@@ -372,7 +372,7 @@ func testCheckJobCancelled(t *testing.T, store kv.Storage, job *model.Job, state
372
372
}
373
373
374
374
func TestRenameTableAutoIDs (t * testing.T ) {
375
- store := testkit .CreateMockStore (t )
375
+ store , dom := testkit .CreateMockStoreAndDomain (t )
376
376
tk1 := testkit .NewTestKit (t , store )
377
377
tk2 := testkit .NewTestKit (t , store )
378
378
tk3 := testkit .NewTestKit (t , store )
@@ -396,6 +396,7 @@ func TestRenameTableAutoIDs(t *testing.T) {
396
396
if len (res ) == 1 && res [0 ][col ] == s {
397
397
break
398
398
}
399
+
399
400
logutil .DDLLogger ().Info ("Could not find match" , zap .String ("tableName" , tableName ), zap .String ("s" , s ), zap .Int ("colNum" , col ))
400
401
401
402
for i := range res {
@@ -412,19 +413,32 @@ func TestRenameTableAutoIDs(t *testing.T) {
412
413
tk2 .MustExec (`set @@session.innodb_lock_wait_timeout = 0` )
413
414
tk2 .MustExec (`BEGIN` )
414
415
tk2 .MustExec (`insert into t values (null, 4)` )
416
+
417
+ v1 := dom .InfoSchema ().SchemaMetaVersion ()
418
+
415
419
go func () {
416
420
alterChan <- tk1 .ExecToErr (`rename table t to ` + dbName + `2.t2` )
417
421
}()
418
422
waitFor (11 , "t" , "running" )
419
423
waitFor (4 , "t" , "public" )
424
+
425
+ // ddl finish does not mean the infoschema loaded.
426
+ // when infoschema v1->v2 switch, it take more time, so we must wait to ensure
427
+ // the new infoschema is used.
428
+ require .Eventually (t , func () bool { return dom .InfoSchema ().SchemaMetaVersion () > v1 }, time .Minute , 2 * time .Millisecond )
429
+
420
430
tk3 .MustExec (`BEGIN` )
421
431
tk3 .MustExec (`insert into ` + dbName + `2.t2 values (50, 5)` )
422
-
432
+ // TODO: still unstable here.
433
+ // This is caused by a known rename table and autoid compatibility issue.
434
+ // In the past we try to fix it by the same auto id allocator before and after table renames.
435
+ // https://github.com/pingcap/tidb/pull/47892
436
+ // But during infoschema v1->v2 switch, infoschema full load happen, then both the old and new
437
+ // autoid instance exists. tk2 here use the old autoid allocator, cause txn conflict on index key
438
+ // b=20, conflicting with the next line insert values (20, 5)
423
439
tk2 .MustExec (`insert into t values (null, 6)` )
424
440
tk3 .MustExec (`insert into ` + dbName + `2.t2 values (20, 5)` )
425
-
426
441
// Done: Fix https://github.com/pingcap/tidb/issues/46904
427
- //tk2.MustContainErrMsg(`insert into t values (null, 6)`, "[tikv:1205]Lock wait timeout exceeded; try restarting transaction")
428
442
tk2 .MustExec (`insert into t values (null, 6)` )
429
443
tk3 .MustExec (`insert into ` + dbName + `2.t2 values (null, 7)` )
430
444
tk2 .MustExec (`COMMIT` )
0 commit comments