Skip to content

Commit

Permalink
lightning/backend/local: fix buildIndexDupTasks (#44442) (#47894)
Browse files Browse the repository at this point in the history
close #44439
  • Loading branch information
ti-chi-bot authored Oct 21, 2023
1 parent 9da9d4d commit aa6ed99
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
5 changes: 3 additions & 2 deletions br/pkg/lightning/backend/local/duplicate.go
Original file line number Diff line number Diff line change
Expand Up @@ -635,8 +635,9 @@ func (m *DupeDetector) buildIndexDupTasks() ([]dupTask, error) {
tid := tablecodec.DecodeTableID(ranges[0].StartKey)
for _, r := range ranges {
tasks = append(tasks, dupTask{
KeyRange: r,
tableID: tid,
KeyRange: r,
tableID: tid,
indexInfo: indexInfo,
})
}
})
Expand Down
5 changes: 4 additions & 1 deletion ddl/ingest/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,11 @@ func (bc *litBackendCtx) Flush(indexID int64, mode FlushMode) (flushed, imported
return true, true, nil
}

// ForceSyncFlagForTest is a flag to force sync only for test.
var ForceSyncFlagForTest = false

func (bc *litBackendCtx) ShouldSync(mode FlushMode) (shouldFlush bool, shouldImport bool) {
if mode == FlushModeForceGlobal {
if mode == FlushModeForceGlobal || ForceSyncFlagForTest {
return true, true
}
if mode == FlushModeForceLocal {
Expand Down
19 changes: 19 additions & 0 deletions tests/realtikvtest/addindextest/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,3 +536,22 @@ func TestAddIndexPreCheckFailed(t *testing.T) {
tk.MustGetErrMsg("alter table t add index idx(b);", "[ddl:8256]Check ingest environment failed: mock error")
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/ddl/ingest/mockIngestCheckEnvFailed"))
}

func TestAddIndexRemoteDuplicateCheck(t *testing.T) {
store := realtikvtest.CreateMockStoreAndSetup(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("drop database if exists addindexlit;")
tk.MustExec("create database addindexlit;")
tk.MustExec("use addindexlit;")
tk.MustExec(`set global tidb_ddl_enable_fast_reorg=on;`)
tk.MustExec("set global tidb_ddl_reorg_worker_cnt=1;")

tk.MustExec("create table t(id int primary key, b int, k int);")
tk.MustQuery("split table t by (30000);").Check(testkit.Rows("1 1"))
tk.MustExec("insert into t values(1, 1, 1);")
tk.MustExec("insert into t values(100000, 1, 1);")

ingest.ForceSyncFlagForTest = true
tk.MustGetErrCode("alter table t add unique index idx(b);", errno.ErrDupEntry)
ingest.ForceSyncFlagForTest = false
}

0 comments on commit aa6ed99

Please sign in to comment.