Skip to content

Commit

Permalink
br: fix br integration test file corruption (#56799)
Browse files Browse the repository at this point in the history
close #53835
  • Loading branch information
Leavrth authored Oct 28, 2024
1 parent 6a85c6b commit c7d09e6
Showing 1 changed file with 30 additions and 13 deletions.
43 changes: 30 additions & 13 deletions br/tests/br_pitr/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -172,32 +172,49 @@ fi
echo "restart a services"
restart_services

echo "corrupt a log file"
filename=$(find $TEST_DIR/$PREFIX/log -regex ".*\.log" | grep -v "schema-meta" | tail -n 1)
filename_temp=$filename"_temp"
filename_bak=$filename"_bak"
echo "corruption" > $filename_temp
cat $filename >> $filename_temp
file_corruption() {
echo "corrupt the whole log files"
for filename in $(find $TEST_DIR/$PREFIX/log -regex ".*\.log" | grep -v "schema-meta"); do
echo "corrupt the log file $filename"
filename_temp=$filename"_temp"
echo "corruption" > $filename_temp
cat $filename >> $filename_temp
mv $filename_temp $filename
truncate -s -11 $filename
done
}

# file lost
mv $filename $filename_bak
# file corruption
file_corruption
export GO_FAILPOINTS="github.com/pingcap/tidb/br/pkg/utils/set-import-attempt-to-one=return(true)"
restore_fail=0
run_br --pd $PD_ADDR restore point -s "local://$TEST_DIR/$PREFIX/log" --full-backup-storage "local://$TEST_DIR/$PREFIX/full" || restore_fail=1
export GO_FAILPOINTS=""
if [ $restore_fail -ne 1 ]; then
echo 'pitr success on file lost'
echo 'pitr success on file corruption'
exit 1
fi

# file corruption
mv $filename_temp $filename
truncate --size=-11 $filename
# start a new cluster for corruption
echo "restart a services"
restart_services

file_lost() {
echo "lost the whole log files"
for filename in $(find $TEST_DIR/$PREFIX/log -regex ".*\.log" | grep -v "schema-meta"); do
echo "lost the log file $filename"
filename_temp=$filename"_temp"
mv $filename $filename_temp
done
}

# file lost
file_lost
export GO_FAILPOINTS="github.com/pingcap/tidb/br/pkg/utils/set-import-attempt-to-one=return(true)"
restore_fail=0
run_br --pd $PD_ADDR restore point -s "local://$TEST_DIR/$PREFIX/log" --full-backup-storage "local://$TEST_DIR/$PREFIX/full" || restore_fail=1
export GO_FAILPOINTS=""
if [ $restore_fail -ne 1 ]; then
echo 'pitr success on file corruption'
echo 'pitr success on file lost'
exit 1
fi

0 comments on commit c7d09e6

Please sign in to comment.