@@ -303,7 +303,7 @@ func checkCancelState(txn kv.Transaction, job *model.Job, test *testCancelJob) e
303303 // If the action is adding index and the state is writing reorganization, it wants to test the case of cancelling the job when backfilling indexes.
304304 // When the job satisfies this case of addIndexFirstReorg, the worker hasn't started to backfill indexes.
305305 if test .cancelState == job .SchemaState && ! addIndexFirstReorg {
306- if job .SchemaState == model .StateNone && job .State != model .JobStateDone {
306+ if job .SchemaState == model .StateNone && job .State != model .JobStateDone && job . Type != model . ActionCreateTable && job . Type != model . ActionCreateSchema {
307307 // If the schema state is none, we only test the job is finished.
308308 } else {
309309 errs , err := admin .CancelJobs (txn , test .jobIDs )
@@ -340,17 +340,19 @@ func buildCancelJobTests(firstID int64) []testCancelJob {
340340
341341 // Test cancel drop index job , see TestCancelDropIndex.
342342
343- // TODO: add create table back after we fix the cancel bug.
344- //{act: model.ActionCreateTable, jobIDs: []int64{firstID + 9}, cancelRetErrs: noErrs, cancelState: model.StatePublic, ddlRetErr: err},
345-
346343 {act : model .ActionAddColumn , jobIDs : []int64 {firstID + 5 }, cancelRetErrs : noErrs , cancelState : model .StateDeleteOnly , ddlRetErr : err },
347344 {act : model .ActionAddColumn , jobIDs : []int64 {firstID + 6 }, cancelRetErrs : noErrs , cancelState : model .StateWriteOnly , ddlRetErr : err },
348345 {act : model .ActionAddColumn , jobIDs : []int64 {firstID + 7 }, cancelRetErrs : noErrs , cancelState : model .StateWriteReorganization , ddlRetErr : err },
349346 {act : model .ActionAddColumn , jobIDs : []int64 {firstID + 8 }, cancelRetErrs : []error {admin .ErrCancelFinishedDDLJob .GenWithStackByArgs (firstID + 8 )}, cancelState : model .StatePublic , ddlRetErr : err },
350347
351- {act : model .ActionDropColumn , jobIDs : []int64 {firstID + 9 }, cancelRetErrs : []error {admin .ErrCannotCancelDDLJob .GenWithStackByArgs (firstID + 9 )}, cancelState : model .StateDeleteOnly , ddlRetErr : err },
352- {act : model .ActionDropColumn , jobIDs : []int64 {firstID + 10 }, cancelRetErrs : []error {admin .ErrCannotCancelDDLJob .GenWithStackByArgs (firstID + 10 )}, cancelState : model .StateWriteOnly , ddlRetErr : err },
353- {act : model .ActionDropColumn , jobIDs : []int64 {firstID + 11 }, cancelRetErrs : []error {admin .ErrCannotCancelDDLJob .GenWithStackByArgs (firstID + 11 )}, cancelState : model .StateWriteReorganization , ddlRetErr : err },
348+ // Test create table, watch out, table id will alloc a globalID.
349+ {act : model .ActionCreateTable , jobIDs : []int64 {firstID + 10 }, cancelRetErrs : noErrs , cancelState : model .StateNone , ddlRetErr : err },
350+ // Test create database, watch out, database id will alloc a globalID.
351+ {act : model .ActionCreateSchema , jobIDs : []int64 {firstID + 12 }, cancelRetErrs : noErrs , cancelState : model .StateNone , ddlRetErr : err },
352+
353+ {act : model .ActionDropColumn , jobIDs : []int64 {firstID + 13 }, cancelRetErrs : []error {admin .ErrCannotCancelDDLJob .GenWithStackByArgs (firstID + 13 )}, cancelState : model .StateDeleteOnly , ddlRetErr : err },
354+ {act : model .ActionDropColumn , jobIDs : []int64 {firstID + 14 }, cancelRetErrs : []error {admin .ErrCannotCancelDDLJob .GenWithStackByArgs (firstID + 14 )}, cancelState : model .StateWriteOnly , ddlRetErr : err },
355+ {act : model .ActionDropColumn , jobIDs : []int64 {firstID + 15 }, cancelRetErrs : []error {admin .ErrCannotCancelDDLJob .GenWithStackByArgs (firstID + 15 )}, cancelState : model .StateWriteReorganization , ddlRetErr : err },
354356 }
355357
356358 return tests
@@ -516,22 +518,36 @@ func (s *testDDLSuite) TestCancelJob(c *C) {
516518 c .Check (errors .ErrorStack (checkErr ), Equals , "" )
517519 s .checkAddColumn (c , d , dbInfo .ID , tblInfo .ID , addingColName , true )
518520
519- // for drop column.
521+ // for create table
522+ tblInfo1 := testTableInfo (c , d , "t1" , 2 )
520523 test = & tests [8 ]
524+ doDDLJobErrWithSchemaState (ctx , d , c , dbInfo .ID , tblInfo1 .ID , model .ActionCreateTable , []interface {}{tblInfo1 }, & cancelState )
525+ c .Check (checkErr , IsNil )
526+ testCheckTableState (c , d , dbInfo , tblInfo1 , model .StateNone )
527+
528+ // for create database
529+ dbInfo1 := testSchemaInfo (c , d , "test_cancel_job1" )
530+ test = & tests [9 ]
531+ doDDLJobErrWithSchemaState (ctx , d , c , dbInfo1 .ID , 0 , model .ActionCreateSchema , []interface {}{dbInfo1 }, & cancelState )
532+ c .Check (checkErr , IsNil )
533+ testCheckSchemaState (c , d , dbInfo1 , model .StateNone )
534+
535+ // for drop column.
536+ test = & tests [10 ]
521537 dropColName := "c3"
522538 s .checkCancelDropColumn (c , d , dbInfo .ID , tblInfo .ID , dropColName , false )
523539 testDropColumn (c , ctx , d , dbInfo , tblInfo , dropColName , false )
524540 c .Check (errors .ErrorStack (checkErr ), Equals , "" )
525541 s .checkCancelDropColumn (c , d , dbInfo .ID , tblInfo .ID , dropColName , true )
526542
527- test = & tests [9 ]
543+ test = & tests [11 ]
528544 dropColName = "c4"
529545 s .checkCancelDropColumn (c , d , dbInfo .ID , tblInfo .ID , dropColName , false )
530546 testDropColumn (c , ctx , d , dbInfo , tblInfo , dropColName , false )
531547 c .Check (errors .ErrorStack (checkErr ), Equals , "" )
532548 s .checkCancelDropColumn (c , d , dbInfo .ID , tblInfo .ID , dropColName , true )
533549
534- test = & tests [10 ]
550+ test = & tests [12 ]
535551 dropColName = "c5"
536552 s .checkCancelDropColumn (c , d , dbInfo .ID , tblInfo .ID , dropColName , false )
537553 testDropColumn (c , ctx , d , dbInfo , tblInfo , dropColName , false )
0 commit comments