Skip to content

Commit

Permalink
ddl: stop DDL retry when partition ID is not found in `truncate parti…
Browse files Browse the repository at this point in the history
…tion` (#26232) (#26238)
  • Loading branch information
ti-srebot authored Sep 2, 2021
1 parent e33ecd8 commit 0a18ae2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
33 changes: 33 additions & 0 deletions ddl/db_partition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3378,3 +3378,36 @@ func (s *testIntegrationSuite7) TestPartitionListWithNewCollation(c *C) {
str := tk.MustQuery(`desc select * from t11 where a = 'b';`).Rows()[0][3].(string)
c.Assert(strings.Contains(str, "partition:p0"), IsTrue)
}

func (s *testIntegrationSuite7) TestTruncatePartitionMultipleTimes(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)
tk.MustExec("drop table if exists test.t;")
tk.MustExec(`create table test.t (a int primary key) partition by range (a) (
partition p0 values less than (10),
partition p1 values less than (maxvalue));`)
d := domain.GetDomain(tk.Se).DDL()
originHook := d.GetHook()
defer d.(ddl.DDLForTest).SetHook(originHook)
hook := &ddl.TestDDLCallback{}
d.(ddl.DDLForTest).SetHook(hook)
injected := false
hook.OnJobRunBeforeExported = func(job *model.Job) {
if job.Type == model.ActionTruncateTablePartition && job.SnapshotVer == 0 && !injected {
injected = true
time.Sleep(30 * time.Millisecond)
}
}
var errCount int32
hook.OnJobUpdatedExported = func(job *model.Job) {
if job.Type == model.ActionTruncateTablePartition && job.Error != nil {
atomic.AddInt32(&errCount, 1)
}
}
done1 := make(chan error, 1)
go backgroundExec(s.store, "alter table test.t truncate partition p0;", done1)
done2 := make(chan error, 1)
go backgroundExec(s.store, "alter table test.t truncate partition p0;", done2)
<-done1
<-done2
c.Assert(errCount, LessEqual, int32(1))
}
3 changes: 2 additions & 1 deletion ddl/partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -1075,7 +1075,8 @@ func onTruncateTablePartition(d *ddlCtx, t *meta.Meta, job *model.Job) (int64, e
}
}
if len(newPartitions) == 0 {
return ver, table.ErrUnknownPartition.GenWithStackByArgs("drop?", tblInfo.Name.O)
job.State = model.JobStateCancelled
return ver, table.ErrUnknownPartition.GenWithStackByArgs(fmt.Sprintf("pid:%v", oldIDs), tblInfo.Name.O)
}

// Clear the tiflash replica available status.
Expand Down

0 comments on commit 0a18ae2

Please sign in to comment.