Admin alter ddl jobs behavior is not expected
- 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)
Use sysbench prepare table with 10000000 rows, create index and alter the thread.
The global system var value:
```
mysql> select @@global.tidb_ddl_enable_fast_reorg, @@global.tidb_enable_dist_task, @@global.tidb_ddl_reorg_worker_cnt, @@global.tidb_ddl_reorg_batch_size, @@global.tidb_ddl_reorg_max_write_speed\G
*************************** 1. row ***************************
@@global.tidb_ddl_enable_fast_reorg: 1
@@global.tidb_enable_dist_task: 0
@@global.tidb_ddl_reorg_worker_cnt: 1
@@global.tidb_ddl_reorg_batch_size: 32
@@global.tidb_ddl_reorg_max_write_speed: 0
1 row in set (0.00 sec)
```
```
mysql> use test;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> alter table sbtest1 add index(c);
Query OK, 0 rows affected (43.47 sec)
```
In another a session get the job id and alter the thread
```
admin alter ddl jobs 137 thread=4;
```
### 2. What did you expect to see? (Required)
The ddl jobs finished success and alter success.
### 3. What did you see instead (Required)
The ddl jobs finished success and alter success, but the there are error messages, the job took two attempts to succeed.
```
[2024/11/26 00:32:22.332 +08:00] [INFO] [index.go:1110] ["run add index job done"] [category=ddl] [charset=utf8mb4] [collation=utf8mb4_general_ci]
[2024/11/26 00:32:22.334 +08:00] [WARN] [session.go:819] ["can not retry txn"] [label=internal] [error="[kv:9007]Write conflict, txnStartTS=454178193874354182, conflictStartTS=454178194306891786, conflictCommitTS=454178194306891787, key={tableID=281474976710654, tableName=mysql.tidb_ddl_job, handle=119}, originalKey=748000fffffffffffe5f728000000000000077, primary={metaKey=true, key=DB:2, field=Table:110}, originalPrimaryKey=6d44423a3200000000fb00000000000000685461626c653a3131ff3000000000000000f8, reason=Optimistic [try again later]"] [IsBatchInsert=false] [IsPessimistic=false] [InRestrictedSQL=true] [tidb_retry_limit=10] [tidb_disable_txn_auto_retry=true]
[2024/11/26 00:32:22.334 +08:00] [WARN] [session.go:835] ["commit failed"] ["finished txn"="Txn{state=invalid}"] [error="[kv:9007]Write conflict, txnStartTS=454178193874354182, conflictStartTS=454178194306891786, conflictCommitTS=454178194306891787, key={tableID=281474976710654, tableName=mysql.tidb_ddl_job, handle=119}, originalKey=748000fffffffffffe5f728000000000000077, primary={metaKey=true, key=DB:2, field=Table:110}, originalPrimaryKey=6d44423a3200000000fb00000000000000685461626c653a3131ff3000000000000000f8, reason=Optimistic [try again later]"]
[2024/11/26 00:32:22.334 +08:00] [INFO] [job_scheduler.go:587] ["handle ddl job failed"] [category=ddl] [jobID=119] [conn=3271557130] [error="[kv:9007]Write conflict, txnStartTS=454178193874354182, conflictStartTS=454178194306891786, conflictCommitTS=454178194306891787, key={tableID=281474976710654, tableName=mysql.tidb_ddl_job, handle=119}, originalKey=748000fffffffffffe5f728000000000000077, primary={metaKey=true, key=DB:2, field=Table:110}, originalPrimaryKey=6d44423a3200000000fb00000000000000685461626c653a3131ff3000000000000000f8, reason=Optimistic [try again later]"] [job="ID:119, Type:add index, State:done, SchemaState:public, SchemaID:2, TableID:110, RowCount:1000000, ArgLen:1, start time: 2024-11-26 00:31:54.129 +0800 CST, Err:, ErrCount:0, SnapshotVersion:454178193861246994, Version: v2, UniqueWarnings:0"]
[2024/11/26 00:32:22.335 +08:00] [INFO] [job_scheduler.go:497] ["run job failed"] [category=ddl] [error="[kv:9007]Write conflict, txnStartTS=454178193874354182, conflictStartTS=454178194306891786, conflictCommitTS=454178194306891787, key={tableID=281474976710654, tableName=mysql.tidb_ddl_job, handle=119}, originalKey=748000fffffffffffe5f728000000000000077, primary={metaKey=true, key=DB:2, field=Table:110}, originalPrimaryKey=6d44423a3200000000fb00000000000000685461626c653a3131ff3000000000000000f8, reason=Optimistic [try again later]"] [job="ID:119, Type:add index, State:done, SchemaState:public, SchemaID:2, TableID:110, RowCount:1000000, ArgLen:1, start time: 2024-11-26 00:31:54.129 +0800 CST, Err:, ErrCount:0, SnapshotVersion:454178193861246994, Version: v2, UniqueWarnings:0"]
[2024/11/26 00:32:22.335 +08:00] [INFO] [job_worker.go:784] ["run DDL job"] [category=ddl] [jobID=119] [conn=3271557130] [job="ID:119, Type:add index, State:running, SchemaState:write reorganization, SchemaID:2, TableID:110, RowCount:0, ArgLen:0, start time: 2024-11-26 00:31:54.129 +0800 CST, Err:, ErrCount:0, SnapshotVersion:454178193861246994, Version: v2, UniqueWarnings:0"]
```
### 4. What is your TiDB version? (Required)
master
Contributor guide
Assessment
This issue has not been assessed yet.