Skip to content

Commit 3033d5d

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 796f6a0 commit 3033d5d

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
@@ -465,6 +465,7 @@ func (w *tableScanWorker) scanRecords(task TableScanTask, sender func(IndexRecor
465465
}
466466
var done bool
467467
for !done {
468+
failpoint.InjectCall("beforeGetChunk")
468469
srcChk := w.getChunk()
469470
done, err = fetchTableScanResult(w.ctx, w.copCtx.GetBase(), rs, srcChk)
470471
if err != nil || w.ctx.Err() != nil {

pkg/ddl/ingest/BUILD.bazel

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,11 @@ go_test(
7272
embed = [":ingest"],
7373
flaky = True,
7474
race = "on",
75+
<<<<<<< HEAD
7576
shard_count = 17,
77+
=======
78+
shard_count = 25,
79+
>>>>>>> a5f888b2cc3 (ddl: fix cancelling stuck issue during adding index (#61544))
7680
deps = [
7781
"//pkg/config",
7882
"//pkg/ddl",

pkg/ddl/ingest/integration_test.go

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

206+
func TestAddIndexGetChunkCancel(t *testing.T) {
207+
store := testkit.CreateMockStore(t)
208+
tk := testkit.NewTestKit(t, store)
209+
tk.MustExec("use test;")
210+
defer ingesttestutil.InjectMockBackendCtx(t, store)()
211+
212+
tk.MustExec("create table t (a int primary key, b int);")
213+
for i := range 100 {
214+
tk.MustExec(fmt.Sprintf("insert into t values (%d, %d);", i*10000, i*10000))
215+
}
216+
tk.MustExec("split table t between (0) and (1000000) regions 10;")
217+
jobID := int64(0)
218+
testfailpoint.EnableCall(t, "github.com/pingcap/tidb/pkg/ddl/beforeRunOneJobStep", func(job *model.Job) {
219+
if jobID == 0 && job.Type == model.ActionAddIndex {
220+
jobID = job.ID
221+
}
222+
})
223+
cancelled := false
224+
testfailpoint.EnableCall(t, "github.com/pingcap/tidb/pkg/ddl/beforeGetChunk", func() {
225+
if !cancelled {
226+
tk2 := testkit.NewTestKit(t, store)
227+
tk2.MustExec(fmt.Sprintf("admin cancel ddl jobs %d", jobID))
228+
cancelled = true
229+
}
230+
})
231+
tk.MustGetErrCode("alter table t add index idx(b);", errno.ErrCancelledDDLJob)
232+
require.True(t, cancelled)
233+
tk.MustExec("admin check table t;")
234+
}
235+
206236
func TestIngestPartitionRowCount(t *testing.T) {
207237
store := testkit.CreateMockStore(t)
208238
tk := testkit.NewTestKit(t, store)

0 commit comments

Comments
 (0)