Skip to content

Commit 83b96f9

Browse files
authored
Incremental restore: fix the issue that backfill data is not covered by newTS (#54430) (#54505)
close #54426
1 parent ca1259c commit 83b96f9

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
@@ -844,10 +844,6 @@ func runRestore(c context.Context, g glue.Glue, cmdName string, cfg *RestoreConf
844844
return errors.Trace(err)
845845
}
846846

847-
var newTS uint64
848-
if client.IsIncremental() {
849-
newTS = restoreTS
850-
}
851847
ddlJobs := restore.FilterDDLJobs(client.GetDDLJobs(), tables)
852848
ddlJobs = restore.FilterDDLJobByRules(ddlJobs, restore.DDLJobBlockListRule)
853849

@@ -906,6 +902,17 @@ func runRestore(c context.Context, g glue.Glue, cmdName string, cfg *RestoreConf
906902
return errors.Trace(err)
907903
}
908904

905+
var newTS uint64
906+
if client.IsIncremental() {
907+
// we need to get the new ts after execDDL
908+
// or backfilled data in upstream may not be covered by
909+
// the new ts.
910+
// see https://github.com/pingcap/tidb/issues/54426
911+
newTS, err = client.GetTSWithRetry(ctx)
912+
if err != nil {
913+
return errors.Trace(err)
914+
}
915+
}
909916
// We make bigger errCh so we won't block on multi-part failed.
910917
errCh := make(chan error, 32)
911918

br/tests/br_incremental/run.sh

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

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

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

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

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

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

0 commit comments

Comments
 (0)