Skip to content

Commit d46ddb0

Browse files
tangentati-chi-bot
authored andcommitted
This is an automated cherry-pick of pingcap#61544
Signed-off-by: ti-chi-bot <[email protected]>
1 parent 17bb929 commit d46ddb0

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

pkg/ddl/backfilling_operators.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,7 @@ func (w *tableScanWorker) scanRecords(task TableScanTask, sender func(IndexRecor
450450
}
451451
var done bool
452452
for !done {
453+
failpoint.InjectCall("beforeGetChunk")
453454
srcChk := w.getChunk()
454455
done, err = fetchTableScanResult(w.ctx, w.copCtx.GetBase(), rs, srcChk)
455456
if err != nil || util2.IsContextDone(w.ctx) {

pkg/ddl/ingest/BUILD.bazel

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@ go_test(
6767
embed = [":ingest"],
6868
flaky = True,
6969
race = "on",
70+
<<<<<<< HEAD
7071
shard_count = 18,
72+
=======
73+
shard_count = 25,
74+
>>>>>>> a5f888b2cc3 (ddl: fix cancelling stuck issue during adding index (#61544))
7175
deps = [
7276
"//pkg/config",
7377
"//pkg/ddl",

pkg/ddl/ingest/integration_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,36 @@ func (c *testCallback) OnJobRunBefore(job *model.Job) {
229229
}
230230
}
231231

232+
func TestAddIndexGetChunkCancel(t *testing.T) {
233+
store := testkit.CreateMockStore(t)
234+
tk := testkit.NewTestKit(t, store)
235+
tk.MustExec("use test;")
236+
defer ingesttestutil.InjectMockBackendCtx(t, store)()
237+
238+
tk.MustExec("create table t (a int primary key, b int);")
239+
for i := range 100 {
240+
tk.MustExec(fmt.Sprintf("insert into t values (%d, %d);", i*10000, i*10000))
241+
}
242+
tk.MustExec("split table t between (0) and (1000000) regions 10;")
243+
jobID := int64(0)
244+
testfailpoint.EnableCall(t, "github.com/pingcap/tidb/pkg/ddl/beforeRunOneJobStep", func(job *model.Job) {
245+
if jobID == 0 && job.Type == model.ActionAddIndex {
246+
jobID = job.ID
247+
}
248+
})
249+
cancelled := false
250+
testfailpoint.EnableCall(t, "github.com/pingcap/tidb/pkg/ddl/beforeGetChunk", func() {
251+
if !cancelled {
252+
tk2 := testkit.NewTestKit(t, store)
253+
tk2.MustExec(fmt.Sprintf("admin cancel ddl jobs %d", jobID))
254+
cancelled = true
255+
}
256+
})
257+
tk.MustGetErrCode("alter table t add index idx(b);", errno.ErrCancelledDDLJob)
258+
require.True(t, cancelled)
259+
tk.MustExec("admin check table t;")
260+
}
261+
232262
func TestIngestPartitionRowCount(t *testing.T) {
233263
store := testkit.CreateMockStore(t)
234264
tk := testkit.NewTestKit(t, store)

0 commit comments

Comments
 (0)