Skip to content

Commit cd0f864

Browse files
authored
lightning/backend/local: fix buildIndexDupTasks (#44442)
close #44439
1 parent dd54ff2 commit cd0f864

File tree

4 files changed

+28
-3
lines changed

4 files changed

+28
-3
lines changed

br/pkg/lightning/backend/local/duplicate.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -635,8 +635,9 @@ func (m *DupeDetector) buildIndexDupTasks() ([]dupTask, error) {
635635
tid := tablecodec.DecodeTableID(ranges[0].StartKey)
636636
for _, r := range ranges {
637637
tasks = append(tasks, dupTask{
638-
KeyRange: r,
639-
tableID: tid,
638+
KeyRange: r,
639+
tableID: tid,
640+
indexInfo: indexInfo,
640641
})
641642
}
642643
})

ddl/ingest/backend.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,11 @@ func (bc *litBackendCtx) Flush(indexID int64, mode FlushMode) (flushed, imported
224224
return true, true, nil
225225
}
226226

227+
// ForceSyncFlagForTest is a flag to force sync only for test.
228+
var ForceSyncFlagForTest = false
229+
227230
func (bc *litBackendCtx) ShouldSync(mode FlushMode) (shouldFlush bool, shouldImport bool) {
228-
if mode == FlushModeForceGlobal {
231+
if mode == FlushModeForceGlobal || ForceSyncFlagForTest {
229232
return true, true
230233
}
231234
if mode == FlushModeForceLocal {

tests/realtikvtest/addindextest/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ go_test(
3838
"//ddl",
3939
"//ddl/ingest",
4040
"//ddl/testutil",
41+
"//errno",
4142
"//sessionctx/variable",
4243
"//testkit",
4344
"//tests/realtikvtest",

tests/realtikvtest/addindextest/integration_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"github.com/pingcap/tidb/ddl"
2828
"github.com/pingcap/tidb/ddl/ingest"
2929
"github.com/pingcap/tidb/ddl/testutil"
30+
"github.com/pingcap/tidb/errno"
3031
"github.com/pingcap/tidb/sessionctx/variable"
3132
"github.com/pingcap/tidb/testkit"
3233
"github.com/pingcap/tidb/tests/realtikvtest"
@@ -391,3 +392,22 @@ func TestAddIndexFinishImportError(t *testing.T) {
391392
jobTp := rows[0][3].(string)
392393
require.True(t, strings.Contains(jobTp, "ingest"), jobTp)
393394
}
395+
396+
func TestAddIndexRemoteDuplicateCheck(t *testing.T) {
397+
store := realtikvtest.CreateMockStoreAndSetup(t)
398+
tk := testkit.NewTestKit(t, store)
399+
tk.MustExec("drop database if exists addindexlit;")
400+
tk.MustExec("create database addindexlit;")
401+
tk.MustExec("use addindexlit;")
402+
tk.MustExec(`set global tidb_ddl_enable_fast_reorg=on;`)
403+
tk.MustExec("set global tidb_ddl_reorg_worker_cnt=1;")
404+
405+
tk.MustExec("create table t(id int primary key, b int, k int);")
406+
tk.MustQuery("split table t by (30000);").Check(testkit.Rows("1 1"))
407+
tk.MustExec("insert into t values(1, 1, 1);")
408+
tk.MustExec("insert into t values(100000, 1, 1);")
409+
410+
ingest.ForceSyncFlagForTest = true
411+
tk.MustGetErrCode("alter table t add unique index idx(b);", errno.ErrDupEntry)
412+
ingest.ForceSyncFlagForTest = false
413+
}

0 commit comments

Comments
 (0)