Skip to content

Commit 0155485

Browse files
authored
br: wait tiflash replicas ready && fix unstable test (#46301) (#46341)
close #46302
1 parent 16c342c commit 0155485

File tree

3 files changed

+42
-5
lines changed

3 files changed

+42
-5
lines changed

br/pkg/restore/client.go

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1824,11 +1824,28 @@ func (rc *Client) GoWaitTiFlashReady(ctx context.Context, inCh <-chan *CreatedTa
18241824
zap.Stringer("table", tbl.OldTable.Info.Name),
18251825
zap.Stringer("db", tbl.OldTable.DB.Name))
18261826
for {
1827-
progress, err := infosync.CalculateTiFlashProgress(tbl.Table.ID, tbl.Table.TiFlashReplica.Count, tiFlashStores)
1828-
if err != nil {
1829-
log.Warn("failed to get tiflash replica progress, wait for next retry", zap.Error(err))
1830-
time.Sleep(time.Second)
1831-
continue
1827+
var progress float64
1828+
if pi := tbl.Table.GetPartitionInfo(); pi != nil && len(pi.Definitions) > 0 {
1829+
for _, p := range pi.Definitions {
1830+
progressOfPartition, err := infosync.MustGetTiFlashProgress(p.ID, tbl.Table.TiFlashReplica.Count, &tiFlashStores)
1831+
if err != nil {
1832+
log.Warn("failed to get progress for tiflash partition replica, retry it",
1833+
zap.Int64("tableID", tbl.Table.ID), zap.Int64("partitionID", p.ID), zap.Error(err))
1834+
time.Sleep(time.Second)
1835+
continue
1836+
}
1837+
progress += progressOfPartition
1838+
}
1839+
progress = progress / float64(len(pi.Definitions))
1840+
} else {
1841+
var err error
1842+
progress, err = infosync.MustGetTiFlashProgress(tbl.Table.ID, tbl.Table.TiFlashReplica.Count, &tiFlashStores)
1843+
if err != nil {
1844+
log.Warn("failed to get progress for tiflash replica, retry it",
1845+
zap.Int64("tableID", tbl.Table.ID), zap.Error(err))
1846+
time.Sleep(time.Second)
1847+
continue
1848+
}
18321849
}
18331850
// check until progress is 1
18341851
if progress == 1 {

br/tests/br_tiflash/run.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,29 @@ run_sql "CREATE DATABASE $DB"
2323

2424
run_sql "CREATE TABLE $DB.kv(k varchar(256) primary key, v int)"
2525

26+
run_sql "CREATE TABLE $DB.partition_kv(\
27+
k INT, \
28+
v INT, \
29+
PRIMARY KEY(k) CLUSTERED \
30+
) PARTITION BY RANGE(k) (\
31+
PARTITION p0 VALUES LESS THAN (200), \
32+
PARTITION p1 VALUES LESS THAN (400), \
33+
PARTITION p2 VALUES LESS THAN MAXVALUE)"
34+
2635
stmt="INSERT INTO $DB.kv(k, v) VALUES ('1-record', 1)"
36+
parition_stmt="INSERT INTO $DB.partition_kv(k, v) VALUES (1, 1)"
2737
for i in $(seq 2 $RECORD_COUNT); do
2838
stmt="$stmt,('$i-record', $i)"
39+
parition_stmt="$parition_stmt,($i, $i)"
2940
done
3041
run_sql "$stmt"
42+
run_sql "$parition_stmt"
3143

3244
if ! run_sql "ALTER TABLE $DB.kv SET TIFLASH REPLICA 1"; then
3345
# 10s should be enough for tiflash-proxy get started
3446
sleep 10
3547
run_sql "ALTER TABLE $DB.kv SET TIFLASH REPLICA 1"
48+
run_sql "ALTER TABLE $DB.partition_kv SET TIFLASH REPLICA 1"
3649
fi
3750

3851

@@ -54,6 +67,8 @@ run_sql "DROP DATABASE $DB"
5467
run_br restore full -s "local://$TEST_DIR/$DB" --pd $PD_ADDR --wait-tiflash-ready=true
5568

5669
# check TiFlash sync
70+
echo "wait 3 seconds for tiflash tick puller triggered"
71+
sleep 3
5772
if ! [ $(run_sql "select * from information_schema.tiflash_replica" | grep "PROGRESS" | sed "s/[^0-9]//g") -eq 1 ]; then
5873
echo "restore didn't wait tiflash synced after set --wait-tiflash-ready=true."
5974
exit 1

br/tests/run.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ set -eu
1818
export PATH="tests/_utils:bin:$PATH"
1919
export TEST_DIR=/tmp/backup_restore_test
2020

21+
# Create COV_DIR if not exists
22+
if [ -d "$COV_DIR" ]; then
23+
mkdir -p $COV_DIR
24+
fi
25+
2126
# Reset TEST_DIR
2227
rm -rf $TEST_DIR && mkdir -p $TEST_DIR
2328

0 commit comments

Comments
 (0)