@@ -303,8 +303,9 @@ 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 && job .Type != model .ActionCreateTable && job .Type != model .ActionCreateSchema {
307- // If the schema state is none, we only test the job is finished.
306+ if job .SchemaState == model .StateNone && job .State != model .JobStateDone && job .Type != model .ActionCreateTable && job .Type != model .ActionCreateSchema && job .Type != model .ActionRebaseAutoID {
307+ // If the schema state is none and is not equal to model.JobStateDone, we only test the job is finished.
308+ // Unless the job is model.ActionCreateTable, model.ActionCreateSchema, model.ActionRebaseAutoID, we do the cancel anyway.
308309 } else {
309310 errs , err := admin .CancelJobs (txn , test .jobIDs )
310311 if err != nil {
@@ -353,6 +354,8 @@ func buildCancelJobTests(firstID int64) []testCancelJob {
353354 {act : model .ActionDropColumn , jobIDs : []int64 {firstID + 13 }, cancelRetErrs : []error {admin .ErrCannotCancelDDLJob .GenWithStackByArgs (firstID + 13 )}, cancelState : model .StateDeleteOnly , ddlRetErr : err },
354355 {act : model .ActionDropColumn , jobIDs : []int64 {firstID + 14 }, cancelRetErrs : []error {admin .ErrCannotCancelDDLJob .GenWithStackByArgs (firstID + 14 )}, cancelState : model .StateWriteOnly , ddlRetErr : err },
355356 {act : model .ActionDropColumn , jobIDs : []int64 {firstID + 15 }, cancelRetErrs : []error {admin .ErrCannotCancelDDLJob .GenWithStackByArgs (firstID + 15 )}, cancelState : model .StateWriteReorganization , ddlRetErr : err },
357+ {act : model .ActionRebaseAutoID , jobIDs : []int64 {firstID + 16 }, cancelRetErrs : noErrs , cancelState : model .StateNone , ddlRetErr : err },
358+ {act : model .ActionShardRowID , jobIDs : []int64 {firstID + 17 }, cancelRetErrs : noErrs , cancelState : model .StateNone , ddlRetErr : err },
356359 }
357360
358361 return tests
@@ -407,6 +410,11 @@ func (s *testDDLSuite) TestCancelJob(c *C) {
407410 ctx := testNewContext (d )
408411 err := ctx .NewTxn ()
409412 c .Assert (err , IsNil )
413+ tableAutoID := int64 (100 )
414+ shardRowIDBits := uint64 (5 )
415+ tblInfo .AutoIncID = tableAutoID
416+ tblInfo .ShardRowIDBits = shardRowIDBits
417+
410418 job := testCreateTable (c , ctx , d , dbInfo , tblInfo )
411419 // insert t values (1, 2, 3, 4, 5);
412420 originTable := testGetTable (c , d , dbInfo .ID , tblInfo .ID )
@@ -424,7 +432,7 @@ func (s *testDDLSuite) TestCancelJob(c *C) {
424432 tests := buildCancelJobTests (firstJobID )
425433 var checkErr error
426434 var test * testCancelJob
427- tc . onJobUpdated = func (job * model.Job ) {
435+ hookCancelFunc : = func (job * model.Job ) {
428436 if job .State == model .JobStateSynced || job .State == model .JobStateCancelled || job .State == model .JobStateCancelling {
429437 return
430438 }
@@ -455,6 +463,8 @@ func (s *testDDLSuite) TestCancelJob(c *C) {
455463 return
456464 }
457465 }
466+ tc .onJobUpdated = hookCancelFunc
467+ tc .onJobRunBefore = hookCancelFunc
458468 d .SetHook (tc )
459469
460470 // for adding index
@@ -553,6 +563,22 @@ func (s *testDDLSuite) TestCancelJob(c *C) {
553563 testDropColumn (c , ctx , d , dbInfo , tblInfo , dropColName , false )
554564 c .Check (errors .ErrorStack (checkErr ), Equals , "" )
555565 s .checkCancelDropColumn (c , d , dbInfo .ID , tblInfo .ID , dropColName , true )
566+
567+ // cancel rebase auto id
568+ test = & tests [13 ]
569+ rebaseIDArgs := []interface {}{int64 (200 )}
570+ doDDLJobErrWithSchemaState (ctx , d , c , dbInfo .ID , tblInfo .ID , model .ActionRebaseAutoID , rebaseIDArgs , & cancelState )
571+ c .Check (errors .ErrorStack (checkErr ), Equals , "" )
572+ changedTable := testGetTable (c , d , dbInfo .ID , tblInfo .ID )
573+ c .Assert (changedTable .Meta ().AutoIncID , Equals , tableAutoID )
574+
575+ // cancel shard bits
576+ test = & tests [14 ]
577+ shardRowIDArgs := []interface {}{uint64 (7 )}
578+ doDDLJobErrWithSchemaState (ctx , d , c , dbInfo .ID , tblInfo .ID , model .ActionRebaseAutoID , shardRowIDArgs , & cancelState )
579+ c .Check (errors .ErrorStack (checkErr ), Equals , "" )
580+ changedTable = testGetTable (c , d , dbInfo .ID , tblInfo .ID )
581+ c .Assert (changedTable .Meta ().ShardRowIDBits , Equals , shardRowIDBits )
556582}
557583
558584func (s * testDDLSuite ) TestIgnorableSpec (c * C ) {
0 commit comments