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: stop DDL retry when partition ID is not found in truncate partition (#26232) #26238

Merged
merged 4 commits into from
Sep 2, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
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