@@ -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"
@@ -1473,13 +1474,18 @@ func (local *local) ResolveDuplicateRows(ctx context.Context, tbl table.Table, t
1473
1474
return err
1474
1475
}
1475
1476
1477
+ tableIDs := physicalTableIDs (tbl .Meta ())
1478
+ keyInTable := func (key []byte ) bool {
1479
+ return slices .Contains (tableIDs , tablecodec .DecodeTableID (key ))
1480
+ }
1481
+
1476
1482
errLimiter := rate .NewLimiter (1 , 1 )
1477
1483
pool := utils .NewWorkerPool (uint (local .dupeConcurrency ), "resolve duplicate rows" )
1478
1484
err = local .errorMgr .ResolveAllConflictKeys (
1479
1485
ctx , tableName , pool ,
1480
1486
func (ctx context.Context , handleRows [][2 ][]byte ) error {
1481
1487
for {
1482
- err := local .deleteDuplicateRows (ctx , logger , handleRows , decoder )
1488
+ err := local .deleteDuplicateRows (ctx , logger , handleRows , decoder , keyInTable )
1483
1489
if err == nil {
1484
1490
return nil
1485
1491
}
@@ -1502,7 +1508,13 @@ func (local *local) ResolveDuplicateRows(ctx context.Context, tbl table.Table, t
1502
1508
return errors .Trace (err )
1503
1509
}
1504
1510
1505
- func (local * local ) deleteDuplicateRows (ctx context.Context , logger * log.Task , handleRows [][2 ][]byte , decoder * kv.TableKVDecoder ) (err error ) {
1511
+ func (local * local ) deleteDuplicateRows (
1512
+ ctx context.Context ,
1513
+ logger * log.Task ,
1514
+ handleRows [][2 ][]byte ,
1515
+ decoder * kv.TableKVDecoder ,
1516
+ keyInTable func (key []byte ) bool ,
1517
+ ) (err error ) {
1506
1518
// Starts a Delete transaction.
1507
1519
txn , err := local .tikvCli .Begin ()
1508
1520
if err != nil {
@@ -1527,6 +1539,12 @@ func (local *local) deleteDuplicateRows(ctx context.Context, logger *log.Task, h
1527
1539
// (if the number of duplicates is small this should fit entirely in memory)
1528
1540
// (Txn's MemBuf's bufferSizeLimit is currently infinity)
1529
1541
for _ , handleRow := range handleRows {
1542
+ // Skip the row key if it's not in the table.
1543
+ // This can happen if the table has been recreated or truncated,
1544
+ // and the duplicate key is from the old table.
1545
+ if ! keyInTable (handleRow [0 ]) {
1546
+ continue
1547
+ }
1530
1548
logger .Debug ("[resolve-dupe] found row to resolve" ,
1531
1549
logutil .Key ("handle" , handleRow [0 ]),
1532
1550
logutil .Key ("row" , handleRow [1 ]))
0 commit comments