Skip to content

Commit ec5398b

Browse files
authored
Incremental restore: fix the issue that backfill data is not covered by newTS (#54430) (#55656)
close #54426
1 parent 1a305b3 commit ec5398b

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

br/pkg/task/restore.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -645,10 +645,6 @@ func runRestore(c context.Context, g glue.Glue, cmdName string, cfg *RestoreConf
645645
return errors.Trace(err)
646646
}
647647

648-
var newTS uint64
649-
if client.IsIncremental() {
650-
newTS = restoreTS
651-
}
652648
ddlJobs := restore.FilterDDLJobs(client.GetDDLJobs(), tables)
653649
ddlJobs = restore.FilterDDLJobByRules(ddlJobs, restore.DDLJobBlockListRule)
654650

@@ -704,6 +700,17 @@ func runRestore(c context.Context, g glue.Glue, cmdName string, cfg *RestoreConf
704700
}
705701
}
706702

703+
var newTS uint64
704+
if client.IsIncremental() {
705+
// we need to get the new ts after execDDL
706+
// or backfilled data in upstream may not be covered by
707+
// the new ts.
708+
// see https://github.com/pingcap/tidb/issues/54426
709+
newTS, err = client.GetTSWithRetry(ctx)
710+
if err != nil {
711+
return errors.Trace(err)
712+
}
713+
}
707714
// We make bigger errCh so we won't block on multi-part failed.
708715
errCh := make(chan error, 32)
709716

br/tests/br_incremental/run.sh

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ go-ycsb load mysql -P tests/$TEST_NAME/workload -p mysql.host=$TIDB_IP -p mysql.
2626
row_count_ori_full=$(run_sql "SELECT COUNT(*) FROM $DB.$TABLE;" | awk '/COUNT/{print $2}')
2727

2828
run_sql "CREATE TABLE IF NOT EXISTS ${DB}.${AUTO_ID_TABLE} (c1 INT);"
29+
run_sql "create table ${DB}.t (pk bigint primary key, val int not null);"
30+
run_sql "insert into ${DB}.t values (1, 11), (2, 22), (3, 33), (4, 44);"
2931

30-
# full backup
3132
echo "full backup start..."
3233
run_br --pd $PD_ADDR backup db -s "local://$TEST_DIR/$DB/full" --db $DB
3334

@@ -37,6 +38,9 @@ for i in $(seq $ROW_COUNT); do
3738
run_sql "INSERT INTO ${DB}.${AUTO_ID_TABLE}(c1) VALUES ($i);"
3839
done
3940

41+
run_sql "create index index_val on ${DB}.t (val);"
42+
run_sql "update ${DB}.t set val = 66 - val;"
43+
4044
# incremental backup
4145
echo "incremental backup start..."
4246
last_backup_ts=$(run_br validate decode --field="end-version" -s "local://$TEST_DIR/$DB/full" | grep -oE "^[0-9]+")
@@ -69,4 +73,15 @@ for i in $(seq $ROW_COUNT); do
6973
run_sql "INSERT INTO ${DB}.${AUTO_ID_TABLE}(c1) VALUES ($i);"
7074
done
7175

76+
if run_sql "admin check table ${DB}.t;" | grep -q 'inconsistency'; then
77+
echo "TEST: [$TEST_NAME] incremental restore fail on database $DB.t"
78+
exit 1
79+
fi
80+
81+
index_count=$(run_sql "select count(*) from $DB.t use index (index_val);" | awk '/count/{print $2}')
82+
if [ "${index_count}" != "4" ];then
83+
echo "TEST: [$TEST_NAME] index check fail on database $DB.t"
84+
exit 1
85+
fi
86+
7287
run_sql "DROP DATABASE $DB;"

0 commit comments

Comments
 (0)