diff --git a/ddl/db_test.go b/ddl/db_test.go index 77d3902c7a916..a6f45efe30793 100644 --- a/ddl/db_test.go +++ b/ddl/db_test.go @@ -327,7 +327,7 @@ func (s *testSerialDBSuite) TestAddExpressionIndexRollback(c *C) { _, checkErr = tk1.Exec("use test_db") d := s.dom.DDL() - hook := &ddl.TestDDLCallback{} + hook := &ddl.TestDDLCallback{Do: s.dom} var currJob *model.Job ctx := mock.NewContext() ctx.Store = s.store @@ -447,7 +447,7 @@ LOOP: func (s *testDBSuite5) TestCancelAddPrimaryKey(c *C) { idxName := "primary" addIdxSQL := "alter table t1 add primary key idx_c2 (c2);" - testCancelAddIndex(c, s.store, s.dom.DDL(), s.lease, idxName, addIdxSQL, "") + testCancelAddIndex(c, s.store, s.dom.DDL(), s.lease, idxName, addIdxSQL, "", s.dom) // Check the column's flag when the "add primary key" failed. tk := testkit.NewTestKit(c, s.store) @@ -463,14 +463,14 @@ func (s *testDBSuite5) TestCancelAddPrimaryKey(c *C) { func (s *testDBSuite3) TestCancelAddIndex(c *C) { idxName := "c3_index " addIdxSQL := "create unique index c3_index on t1 (c3)" - testCancelAddIndex(c, s.store, s.dom.DDL(), s.lease, idxName, addIdxSQL, "") + testCancelAddIndex(c, s.store, s.dom.DDL(), s.lease, idxName, addIdxSQL, "", s.dom) tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test_db") tk.MustExec("drop table t1") } -func testCancelAddIndex(c *C, store kv.Storage, d ddl.DDL, lease time.Duration, idxName, addIdxSQL, sqlModeSQL string) { +func testCancelAddIndex(c *C, store kv.Storage, d ddl.DDL, lease time.Duration, idxName, addIdxSQL, sqlModeSQL string, dom *domain.Domain) { tk := testkit.NewTestKit(c, store) tk.MustExec("use test_db") tk.MustExec("drop table if exists t1") @@ -492,7 +492,7 @@ func testCancelAddIndex(c *C, store kv.Storage, d ddl.DDL, lease time.Duration, } var c3IdxInfo *model.IndexInfo - hook := &ddl.TestDDLCallback{} + hook := &ddl.TestDDLCallback{Do: dom} originBatchSize := tk.MustQuery("select @@global.tidb_ddl_reorg_batch_size") // Set batch size to lower try to slow down add-index reorganization, This if for hook to cancel this ddl job. tk.MustExec("set @@global.tidb_ddl_reorg_batch_size = 32") @@ -558,7 +558,7 @@ func (s *testDBSuite4) TestCancelAddIndex1(c *C) { } var checkErr error - hook := &ddl.TestDDLCallback{} + hook := &ddl.TestDDLCallback{Do: s.dom} hook.OnJobRunBeforeExported = func(job *model.Job) { if job.Type == model.ActionAddIndex && job.State == model.JobStateRunning && job.SchemaState == model.StateWriteReorganization && job.SnapshotVer == 0 { jobIDs := []int64{job.ID} @@ -612,7 +612,7 @@ func (s *testDBSuite4) TestCancelDropPrimaryKey(c *C) { idxName := "primary" addIdxSQL := "alter table t add primary key idx_c2 (c2);" dropIdxSQL := "alter table t drop primary key;" - testCancelDropIndex(c, s.store, s.dom.DDL(), idxName, addIdxSQL, dropIdxSQL) + testCancelDropIndex(c, s.store, s.dom.DDL(), idxName, addIdxSQL, dropIdxSQL, s.dom) } // TestCancelDropIndex tests cancel ddl job which type is drop index. @@ -620,11 +620,11 @@ func (s *testDBSuite5) TestCancelDropIndex(c *C) { idxName := "idx_c2" addIdxSQL := "alter table t add index idx_c2 (c2);" dropIdxSQL := "alter table t drop index idx_c2;" - testCancelDropIndex(c, s.store, s.dom.DDL(), idxName, addIdxSQL, dropIdxSQL) + testCancelDropIndex(c, s.store, s.dom.DDL(), idxName, addIdxSQL, dropIdxSQL, s.dom) } // testCancelDropIndex tests cancel ddl job which type is drop index. -func testCancelDropIndex(c *C, store kv.Storage, d ddl.DDL, idxName, addIdxSQL, dropIdxSQL string) { +func testCancelDropIndex(c *C, store kv.Storage, d ddl.DDL, idxName, addIdxSQL, dropIdxSQL string, dom *domain.Domain) { tk := testkit.NewTestKit(c, store) tk.MustExec("use test_db") tk.MustExec("drop table if exists t") @@ -647,7 +647,7 @@ func testCancelDropIndex(c *C, store kv.Storage, d ddl.DDL, idxName, addIdxSQL, {true, model.JobStateRunning, model.StateDeleteReorganization, false}, } var checkErr error - hook := &ddl.TestDDLCallback{} + hook := &ddl.TestDDLCallback{Do: dom} var jobID int64 testCase := &testCases[0] hook.OnJobRunBeforeExported = func(job *model.Job) { @@ -722,7 +722,7 @@ func (s *testDBSuite5) TestCancelTruncateTable(c *C) { s.mustExec(tk, c, "create table t(c1 int, c2 int)") defer s.mustExec(tk, c, "drop table t;") var checkErr error - hook := &ddl.TestDDLCallback{} + hook := &ddl.TestDDLCallback{Do: s.dom} hook.OnJobRunBeforeExported = func(job *model.Job) { if job.Type == model.ActionTruncateTable && job.State == model.JobStateNone { jobIDs := []int64{job.ID} @@ -765,7 +765,7 @@ func (s *testDBSuite5) TestParallelDropSchemaAndDropTable(c *C) { s.mustExec(tk, c, "use test_drop_schema_table") s.mustExec(tk, c, "create table t(c1 int, c2 int)") var checkErr error - hook := &ddl.TestDDLCallback{} + hook := &ddl.TestDDLCallback{Do: s.dom} dbInfo := testGetSchemaByName(c, tk.Se, "test_drop_schema_table") done := false var wg sync.WaitGroup @@ -827,7 +827,7 @@ func (s *testDBSuite1) TestCancelRenameIndex(c *C) { } s.mustExec(tk, c, "alter table t add index idx_c2(c2)") var checkErr error - hook := &ddl.TestDDLCallback{} + hook := &ddl.TestDDLCallback{Do: s.dom} hook.OnJobRunBeforeExported = func(job *model.Job) { if job.Type == model.ActionRenameIndex && job.State == model.JobStateNone { jobIDs := []int64{job.ID} @@ -894,7 +894,7 @@ func (s *testDBSuite2) TestCancelDropTableAndSchema(c *C) { {true, model.ActionDropSchema, model.JobStateRunning, model.StateDeleteOnly, false}, } var checkErr error - hook := &ddl.TestDDLCallback{} + hook := &ddl.TestDDLCallback{Do: s.dom} var jobID int64 testCase := &testCases[0] s.mustExec(tk, c, "create database if not exists test_drop_db") @@ -1336,7 +1336,7 @@ func (s *testDBSuite1) TestCancelAddTableAndDropTablePartition(c *C) { {model.ActionAddTablePartition, model.JobStateRunning, model.StateReplicaOnly, true}, } var checkErr error - hook := &ddl.TestDDLCallback{} + hook := &ddl.TestDDLCallback{Do: s.dom} testCase := &testCases[0] var jobID int64 hook.OnJobRunBeforeExported = func(job *model.Job) { @@ -1507,7 +1507,7 @@ func (s *testDBSuite3) TestCancelDropColumn(c *C) { {true, model.JobStateRunning, model.StateDeleteReorganization, false}, } var checkErr error - hook := &ddl.TestDDLCallback{} + hook := &ddl.TestDDLCallback{Do: s.dom} var jobID int64 testCase := &testCases[0] hook.OnJobRunBeforeExported = func(job *model.Job) { @@ -1614,7 +1614,7 @@ func (s *testDBSuite3) TestCancelDropColumns(c *C) { {true, model.JobStateRunning, model.StateDeleteReorganization, false}, } var checkErr error - hook := &ddl.TestDDLCallback{} + hook := &ddl.TestDDLCallback{Do: s.dom} var jobID int64 testCase := &testCases[0] hook.OnJobRunBeforeExported = func(job *model.Job) { @@ -2465,7 +2465,7 @@ func (s *testSerialDBSuite) TestCreateTableWithLike2(c *C) { tbl1 := testGetTableByName(c, s.s, "test_db", "t1") doneCh := make(chan error, 2) - hook := &ddl.TestDDLCallback{} + hook := &ddl.TestDDLCallback{Do: s.dom} var onceChecker sync.Map hook.OnJobRunBeforeExported = func(job *model.Job) { if job.Type != model.ActionAddColumn && job.Type != model.ActionDropColumn && @@ -2745,7 +2745,7 @@ func (s *testSerialDBSuite) TestRepairTable(c *C) { // Repaired tableInfo has been filtered by `domain.InfoSchema()`, so get it in repairInfo. originTableInfo, _ := domainutil.RepairInfo.GetRepairedTableInfoByTableName("test", "origin") - hook := &ddl.TestDDLCallback{} + hook := &ddl.TestDDLCallback{Do: s.dom} var repairErr error hook.OnJobRunBeforeExported = func(job *model.Job) { if job.Type != model.ActionRepairTable { @@ -3832,7 +3832,7 @@ func (s *testDBSuite5) TestModifyColumnRollBack(c *C) { var c2 *table.Column var checkErr error - hook := &ddl.TestDDLCallback{} + hook := &ddl.TestDDLCallback{Do: s.dom} hook.OnJobUpdatedExported = func(job *model.Job) { if checkErr != nil { return @@ -3930,7 +3930,7 @@ func (s *testSerialDBSuite) TestModifyColumnnReorgInfo(c *C) { defer s.dom.DDL().(ddl.DDLForTest).SetHook(originalHook) // Check insert null before job first update. - hook := &ddl.TestDDLCallback{} + hook := &ddl.TestDDLCallback{Do: s.dom} var checkErr error var currJob *model.Job var elements []*meta.Element @@ -4155,7 +4155,7 @@ func testModifyColumnNullToNotNull(c *C, s *testDBSuite, enableChangeColumnType // Check insert null before job first update. times := 0 - hook := &ddl.TestDDLCallback{} + hook := &ddl.TestDDLCallback{Do: s.dom} tk.MustExec("delete from t1") var checkErr error hook.OnJobRunBeforeExported = func(job *model.Job) { @@ -4284,7 +4284,7 @@ func (s *testDBSuite3) TestTransactionWithWriteOnlyColumn(c *C) { originHook := s.dom.DDL().GetHook() defer s.dom.DDL().(ddl.DDLForTest).SetHook(originHook) - hook := &ddl.TestDDLCallback{} + hook := &ddl.TestDDLCallback{Do: s.dom} var checkErr error hook.OnJobRunBeforeExported = func(job *model.Job) { if checkErr != nil {