Skip to content

Commit 7f86cec

Browse files
authored
br: refactor test to use wait checkpoint method (#57612) (#59283)
close #57609
1 parent cc5e4e2 commit 7f86cec

File tree

2 files changed

+55
-34
lines changed

2 files changed

+55
-34
lines changed

br/tests/br_pitr/run.sh

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ CUR=$(cd `dirname $0`; pwd)
2121
# const value
2222
PREFIX="pitr_backup" # NOTICE: don't start with 'br' because `restart services` would remove file/directory br*.
2323
res_file="$TEST_DIR/sql_res.$TEST_NAME.txt"
24+
TASK_NAME="br_pitr"
2425

2526
# start a new cluster
2627
echo "restart a services"
@@ -37,7 +38,7 @@ echo "prepare_delete_range_count: $prepare_delete_range_count"
3738

3839
# start the log backup task
3940
echo "start log task"
40-
run_br --pd $PD_ADDR log start --task-name integration_test -s "local://$TEST_DIR/$PREFIX/log"
41+
run_br --pd $PD_ADDR log start --task-name $TASK_NAME -s "local://$TEST_DIR/$PREFIX/log"
4142

4243
# run snapshot backup
4344
echo "run snapshot backup"
@@ -53,39 +54,8 @@ incremental_delete_range_count=$(run_sql "select count(*) DELETE_RANGE_CNT from
5354
echo "incremental_delete_range_count: $incremental_delete_range_count"
5455

5556
# wait checkpoint advance
56-
echo "wait checkpoint advance"
57-
sleep 10
58-
current_ts=$(echo $(($(date +%s%3N) << 18)))
59-
echo "current ts: $current_ts"
60-
i=0
61-
while true; do
62-
# extract the checkpoint ts of the log backup task. If there is some error, the checkpoint ts should be empty
63-
log_backup_status=$(unset BR_LOG_TO_TERM && run_br --pd $PD_ADDR log status --task-name integration_test --json 2>/dev/null)
64-
echo "log backup status: $log_backup_status"
65-
checkpoint_ts=$(echo "$log_backup_status" | head -n 1 | jq 'if .[0].last_errors | length == 0 then .[0].checkpoint else empty end')
66-
echo "checkpoint ts: $checkpoint_ts"
67-
68-
# check whether the checkpoint ts is a number
69-
if [ $checkpoint_ts -gt 0 ] 2>/dev/null; then
70-
# check whether the checkpoint has advanced
71-
if [ $checkpoint_ts -gt $current_ts ]; then
72-
echo "the checkpoint has advanced"
73-
break
74-
fi
75-
# the checkpoint hasn't advanced
76-
echo "the checkpoint hasn't advanced"
77-
i=$((i+1))
78-
if [ "$i" -gt 50 ]; then
79-
echo 'the checkpoint lag is too large'
80-
exit 1
81-
fi
82-
sleep 10
83-
else
84-
# unknown status, maybe somewhere is wrong
85-
echo "TEST: [$TEST_NAME] failed to wait checkpoint advance!"
86-
exit 1
87-
fi
88-
done
57+
current_ts=$(python3 -c "import time; print(int(time.time() * 1000) << 18)")
58+
. "$CUR/../br_test_utils.sh" && wait_log_checkpoint_advance $TASK_NAME
8959

9060
# dump some info from upstream cluster
9161
# ...

br/tests/br_test_utils.sh

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/bin/sh
2+
#
3+
# Copyright 2024 PingCAP, Inc.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -eux
18+
19+
wait_log_checkpoint_advance() {
20+
local task_name=${1:-$TASK_NAME}
21+
echo "wait for log checkpoint to advance for task: $task_name"
22+
sleep 10
23+
local current_ts=$(python3 -c "import time; print(int(time.time() * 1000) << 18)")
24+
echo "current ts: $current_ts"
25+
i=0
26+
while true; do
27+
# extract the checkpoint ts of the log backup task. If there is some error, the checkpoint ts should be empty
28+
log_backup_status=$(unset BR_LOG_TO_TERM && run_br --skip-goleak --pd $PD_ADDR log status --task-name $task_name --json 2>br.log)
29+
echo "log backup status: $log_backup_status"
30+
local checkpoint_ts=$(echo "$log_backup_status" | head -n 1 | jq 'if .[0].last_errors | length == 0 then .[0].checkpoint else empty end')
31+
echo "checkpoint ts: $checkpoint_ts"
32+
33+
# check whether the checkpoint ts is a number
34+
if [ $checkpoint_ts -gt 0 ] 2>/dev/null; then
35+
if [ $checkpoint_ts -gt $current_ts ]; then
36+
echo "the checkpoint has advanced"
37+
break
38+
fi
39+
echo "the checkpoint hasn't advanced"
40+
i=$((i+1))
41+
if [ "$i" -gt 50 ]; then
42+
echo 'the checkpoint lag is too large'
43+
exit 1
44+
fi
45+
sleep 10
46+
else
47+
echo "TEST: [$TEST_NAME] failed to wait checkpoint advance!"
48+
exit 1
49+
fi
50+
done
51+
}

0 commit comments

Comments
 (0)