Skip to content

Commit

Permalink
lightning: fix incorrect handling of duplicated key error message (#5…
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot authored May 28, 2024
1 parent afe2aae commit 653752b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion br/pkg/lightning/common/dupdetect.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (d *DupDetector) Next(iter KVIter) (key []byte, value []byte, ok bool, err
}
if d.option.ReportErrOnDup {
dupKey := make([]byte, len(d.curKey))
dupVal := make([]byte, len(val))
dupVal := make([]byte, len(d.curVal))
copy(dupKey, d.curKey)
copy(dupVal, d.curVal)
return nil, nil, false, ErrFoundDuplicateKeys.FastGenByArgs(dupKey, dupVal)
Expand Down
10 changes: 10 additions & 0 deletions tests/realtikvtest/addindextest4/ingest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,3 +528,13 @@ func TestAddEmptyMultiValueIndex(t *testing.T) {
tk.MustExec("alter table t add index ((cast(j->'$.string' as char(10) array)));")
tk.MustExec("admin check table t;")
}

func TestAddUniqueIndexDuplicatedError(t *testing.T) {
store := realtikvtest.CreateMockStoreAndSetup(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("DROP TABLE IF EXISTS `b1cce552` ")
tk.MustExec("CREATE TABLE `b1cce552` (\n `f5d9aecb` timestamp DEFAULT '2031-12-22 06:44:52',\n `d9337060` varchar(186) DEFAULT 'duplicatevalue',\n `4c74082f` year(4) DEFAULT '1977',\n `9215adc3` tinytext DEFAULT NULL,\n `85ad5a07` decimal(5,0) NOT NULL DEFAULT '68649',\n `8c60260f` varchar(130) NOT NULL DEFAULT 'drfwe301tuehhkmk0jl79mzekuq0byg',\n `8069da7b` varchar(90) DEFAULT 'ra5rhqzgjal4o47ppr33xqjmumpiiillh7o5ajx7gohmuroan0u',\n `91e218e1` tinytext DEFAULT NULL,\n PRIMARY KEY (`8c60260f`,`85ad5a07`) /*T![clustered_index] CLUSTERED */,\n KEY `d88975e1` (`8069da7b`)\n);")
tk.MustExec("INSERT INTO `b1cce552` (`f5d9aecb`, `d9337060`, `4c74082f`, `9215adc3`, `85ad5a07`, `8c60260f`, `8069da7b`, `91e218e1`) VALUES ('2031-12-22 06:44:52', 'duplicatevalue', 2028, NULL, 846, 'N6QD1=@ped@owVoJx', '9soPM2d6H', 'Tv%'), ('2031-12-22 06:44:52', 'duplicatevalue', 2028, NULL, 9052, '_HWaf#gD!bw', '9soPM2d6H', 'Tv%');")
tk.MustGetErrCode("ALTER TABLE `b1cce552` ADD unique INDEX `65290727` (`4c74082f`, `d9337060`, `8069da7b`);", errno.ErrDupEntry)
}

0 comments on commit 653752b

Please sign in to comment.