@@ -68,6 +68,7 @@ import (
68
68
"go.uber.org/atomic"
69
69
"go.uber.org/multierr"
70
70
"go.uber.org/zap"
71
+ "golang.org/x/exp/slices"
71
72
"golang.org/x/sync/errgroup"
72
73
"golang.org/x/time/rate"
73
74
"google.golang.org/grpc"
@@ -1476,13 +1477,18 @@ func (local *local) ResolveDuplicateRows(ctx context.Context, tbl table.Table, t
1476
1477
return err
1477
1478
}
1478
1479
1480
+ tableIDs := physicalTableIDs (tbl .Meta ())
1481
+ keyInTable := func (key []byte ) bool {
1482
+ return slices .Contains (tableIDs , tablecodec .DecodeTableID (key ))
1483
+ }
1484
+
1479
1485
errLimiter := rate .NewLimiter (1 , 1 )
1480
1486
pool := utils .NewWorkerPool (uint (local .dupeConcurrency ), "resolve duplicate rows" )
1481
1487
err = local .errorMgr .ResolveAllConflictKeys (
1482
1488
ctx , tableName , pool ,
1483
1489
func (ctx context.Context , handleRows [][2 ][]byte ) error {
1484
1490
for {
1485
- err := local .deleteDuplicateRows (ctx , logger , handleRows , decoder )
1491
+ err := local .deleteDuplicateRows (ctx , logger , handleRows , decoder , keyInTable )
1486
1492
if err == nil {
1487
1493
return nil
1488
1494
}
@@ -1505,7 +1511,13 @@ func (local *local) ResolveDuplicateRows(ctx context.Context, tbl table.Table, t
1505
1511
return errors .Trace (err )
1506
1512
}
1507
1513
1508
- func (local * local ) deleteDuplicateRows (ctx context.Context , logger * log.Task , handleRows [][2 ][]byte , decoder * kv.TableKVDecoder ) (err error ) {
1514
+ func (local * local ) deleteDuplicateRows (
1515
+ ctx context.Context ,
1516
+ logger * log.Task ,
1517
+ handleRows [][2 ][]byte ,
1518
+ decoder * kv.TableKVDecoder ,
1519
+ keyInTable func (key []byte ) bool ,
1520
+ ) (err error ) {
1509
1521
// Starts a Delete transaction.
1510
1522
txn , err := local .tikvCli .Begin ()
1511
1523
if err != nil {
@@ -1530,6 +1542,12 @@ func (local *local) deleteDuplicateRows(ctx context.Context, logger *log.Task, h
1530
1542
// (if the number of duplicates is small this should fit entirely in memory)
1531
1543
// (Txn's MemBuf's bufferSizeLimit is currently infinity)
1532
1544
for _ , handleRow := range handleRows {
1545
+ // Skip the row key if it's not in the table.
1546
+ // This can happen if the table has been recreated or truncated,
1547
+ // and the duplicate key is from the old table.
1548
+ if ! keyInTable (handleRow [0 ]) {
1549
+ continue
1550
+ }
1533
1551
logger .Debug ("[resolve-dupe] found row to resolve" ,
1534
1552
logutil .Key ("handle" , handleRow [0 ]),
1535
1553
logutil .Key ("row" , handleRow [1 ]))
0 commit comments