Skip to content

Commit aa6ed99

Browse files
authored
lightning/backend/local: fix buildIndexDupTasks (#44442) (#47894)
close #44439
1 parent 9da9d4d commit aa6ed99

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-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/integration_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,3 +536,22 @@ func TestAddIndexPreCheckFailed(t *testing.T) {
536536
tk.MustGetErrMsg("alter table t add index idx(b);", "[ddl:8256]Check ingest environment failed: mock error")
537537
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/ddl/ingest/mockIngestCheckEnvFailed"))
538538
}
539+
540+
func TestAddIndexRemoteDuplicateCheck(t *testing.T) {
541+
store := realtikvtest.CreateMockStoreAndSetup(t)
542+
tk := testkit.NewTestKit(t, store)
543+
tk.MustExec("drop database if exists addindexlit;")
544+
tk.MustExec("create database addindexlit;")
545+
tk.MustExec("use addindexlit;")
546+
tk.MustExec(`set global tidb_ddl_enable_fast_reorg=on;`)
547+
tk.MustExec("set global tidb_ddl_reorg_worker_cnt=1;")
548+
549+
tk.MustExec("create table t(id int primary key, b int, k int);")
550+
tk.MustQuery("split table t by (30000);").Check(testkit.Rows("1 1"))
551+
tk.MustExec("insert into t values(1, 1, 1);")
552+
tk.MustExec("insert into t values(100000, 1, 1);")
553+
554+
ingest.ForceSyncFlagForTest = true
555+
tk.MustGetErrCode("alter table t add unique index idx(b);", errno.ErrDupEntry)
556+
ingest.ForceSyncFlagForTest = false
557+
}

0 commit comments

Comments
 (0)