pingcap / pingcap/tidb

[mview] one FAST AS OF TIMESTAMP refresh hit lock wait timeout while later refreshes on the same MV succeeded

Open
#67,617 1 comment 0 reactions 0 assignees View on GitHub
component/mview feature/developing severity/moderate type/bug
Dominant language
Go
Stars
40.5k
Forks
6.2k
PR merge metrics
PR metrics pending

Description

## Bug Report

Please answer these questions before submitting your issue. Thanks!

### 1. Minimal reproduce step (Required)

Observed on 2026-04-08 on TiDB v8.5.4 Enterprise.

1. Create and initialize a materialized view successfully.
2. Run the following refresh on the same MV:

```sql
USE prod_betcenter;
REFRESH MATERIALIZED VIEW bet_mview_296_02 FAST AS OF TIMESTAMP '2026-04-08 07:04:42';
```

3. Check `mysql.tidb_mview_refresh_hist` and TiDB logs.

Relevant rows from `mysql.tidb_mview_refresh_hist` for the observed runs, excluding `MV_SCHEMA` and `MV_NAME`:

```text
REFRESH_JOB_ID | MVIEW_ID | REFRESH_METHOD | REFRESH_TIME | REFRESH_ENDTIME | REFRESH_DURATION_SEC | REFRESH_STATUS | REFRESH_ROWS | REFRESH_READ_TSO | REFRESH_FAILED_REASON | CANCEL_REQUESTED_AT | CANCEL_REQUESTED_BY
465473479069663236 | 59472 | bounded fast manual | 2026-04-08 09:26:47.848310 | 2026-04-08 09:27:09.788963 | 21.940653 | failed | NULL | 465473476060512256 | context canceled | NULL | NULL
465473577360818186 | 59472 | bounded fast manual | 2026-04-08 09:33:02.812928 | 2026-04-08 09:35:00.661003 | 117.848075 | failed | NULL | 465473575217790976 | context canceled | NULL | NULL
465473769866264585 | 59472 | bounded fast manual | 2026-04-08 09:45:17.164208 | 2026-04-08 09:48:59.038169 | 221.873961 | failed | NULL | 465471244075008000 | lock wait timeout | NULL | NULL
465474393100517381 | 59472 | fast manual | 2026-04-08 10:24:54.612023 | 2026-04-08 10:32:45.608737 | 470.996714 | success | 7073620 | 465474393100517385 | NULL | NULL | NULL
465475223022206981 | 59468 | bounded fast manual | 2026-04-08 11:17:40.506580 | 2026-04-08 11:18:05.910289 | 25.403709 | failed | NULL | 465473520009216000 | cancelled manually by 'root'@'%' | 2026-04-08 11:18:01.136850 | 'root'@'%'
465475256353816584 | 59468 | bounded fast manual | 2026-04-08 11:19:47.639360 | 2026-04-08 11:21:23.165833 | 95.526473 | failed | NULL | 465473520009216000 | cancelled manually by 'root'@'%' | 2026-04-08 11:21:17.978649 | 'root'@'%'
```

The two `KILL QUERY` runs above recorded `NULL` in `CANCEL_REQUESTED_AT` and `CANCEL_REQUESTED_BY`. The two `CANCEL MATERIALIZED VIEW REFRESH JOB` runs above recorded values in both columns.

### 2. What did you expect to see? (Required)

Expected the `FAST AS OF TIMESTAMP` refresh to finish successfully, because a later refresh on the same MV completed successfully on the same date.

### 3. What did you see instead (Required)

The `FAST AS OF TIMESTAMP` refresh with `REFRESH_JOB_ID = 465473769866264585` failed with `lock wait timeout`.

Relevant TiDB log lines from the failed run:

```text
[2026/04/08 09:48:58.539 +00:00] [WARN] [session.go:2203] ["run statement failed"] [conn=348228462] [error="lock wait timeout"] [session="... txn: \"465473769866264585\" ..."]
[2026/04/08 09:48:59.041 +00:00] [INFO] [materialized_view.go:2447] ["refresh materialized view is slow"] [mview=bet_mview_296_02] [refreshType=fast] [success=false] [error="lock wait timeout"]
[2026/04/08 09:48:59.043 +00:00] [INFO] [region_request.go:1011] ["send request failed, err: context canceled"] [conn=348228462] [req-ts=465473769866264585] [req-type=PessimisticRollback]
[2026/04/08 09:48:59.093 +00:00] [WARN] [txn.go:1722] ["[kv] pessimisticRollback failed."] [conn=348228462] [error="context canceled"]
```

A later refresh on the same MV completed successfully with `REFRESH_JOB_ID = 465474393100517381`.

### 4. What is your TiDB version? (Required)

```text
Release Version: v8.5.4
Edition: Enterprise
Git Commit Hash: 8907b97ad28ec3d14412a0a8d48de1d08e46baad
Git Branch: heads/refs/tags/v8.5.4
UTC Build Time: 2026-04-05 08:48:00
GoVersion: go1.23.6
Race Enabled: false
Check Table Before Drop: false
Store: tikv
Enterprise Extension Commit Hash: 7d43ff65ebc145bd63fa84cb368f8775be906998
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.