Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ddl: make test TestRenameTableAutoIDs more stable #54695

Merged
merged 4 commits into from
Jul 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions pkg/ddl/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ func testCheckJobCancelled(t *testing.T, store kv.Storage, job *model.Job, state
}

func TestRenameTableAutoIDs(t *testing.T) {
store := testkit.CreateMockStore(t)
store, dom := testkit.CreateMockStoreAndDomain(t)
tk1 := testkit.NewTestKit(t, store)
tk2 := testkit.NewTestKit(t, store)
tk3 := testkit.NewTestKit(t, store)
Expand All @@ -396,6 +396,7 @@ func TestRenameTableAutoIDs(t *testing.T) {
if len(res) == 1 && res[0][col] == s {
break
}

logutil.DDLLogger().Info("Could not find match", zap.String("tableName", tableName), zap.String("s", s), zap.Int("colNum", col))

for i := range res {
Expand All @@ -412,19 +413,32 @@ func TestRenameTableAutoIDs(t *testing.T) {
tk2.MustExec(`set @@session.innodb_lock_wait_timeout = 0`)
tk2.MustExec(`BEGIN`)
tk2.MustExec(`insert into t values (null, 4)`)

v1 := dom.InfoSchema().SchemaMetaVersion()

go func() {
alterChan <- tk1.ExecToErr(`rename table t to ` + dbName + `2.t2`)
}()
waitFor(11, "t", "running")
waitFor(4, "t", "public")

// ddl finish does not mean the infoschema loaded.
// when infoschema v1->v2 switch, it take more time, so we must wait to ensure
// the new infoschema is used.
require.Eventually(t, func() bool { return dom.InfoSchema().SchemaMetaVersion() > v1 }, time.Minute, 2*time.Millisecond)

tk3.MustExec(`BEGIN`)
tk3.MustExec(`insert into ` + dbName + `2.t2 values (50, 5)`)

// TODO: still unstable here.
// This is caused by a known rename table and autoid compatibility issue.
// In the past we try to fix it by the same auto id allocator before and after table renames.
// https://github.com/pingcap/tidb/pull/47892
// But during infoschema v1->v2 switch, infoschema full load happen, then both the old and new
// autoid instance exists. tk2 here use the old autoid allocator, cause txn conflict on index key
// b=20, conflicting with the next line insert values (20, 5)
tk2.MustExec(`insert into t values (null, 6)`)
tk3.MustExec(`insert into ` + dbName + `2.t2 values (20, 5)`)

// Done: Fix https://github.com/pingcap/tidb/issues/46904
//tk2.MustContainErrMsg(`insert into t values (null, 6)`, "[tikv:1205]Lock wait timeout exceeded; try restarting transaction")
tk2.MustExec(`insert into t values (null, 6)`)
tk3.MustExec(`insert into ` + dbName + `2.t2 values (null, 7)`)
tk2.MustExec(`COMMIT`)
Expand Down