forked from pingcap/tidb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is an automated cherry-pick of pingcap#53836
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
- Loading branch information
1 parent
af6aa91
commit c62e126
Showing
7 changed files
with
374 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/bin/sh | ||
# | ||
# Copyright 2024 PingCAP, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
set -eux | ||
|
||
DB="$TEST_NAME" | ||
TABLE="usertable" | ||
CUR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) | ||
|
||
run_sql "CREATE DATABASE $DB;" | ||
go-ycsb load mysql -P $CUR/workload -p mysql.host=$TIDB_IP -p mysql.port=$TIDB_PORT -p mysql.user=root -p mysql.db=$DB | ||
run_br --pd $PD_ADDR backup full -s "local://$TEST_DIR/$DB" | ||
|
||
filename=$(find $TEST_DIR/$DB -regex ".*.sst" | head -n 1) | ||
filename_temp=$filename"_temp" | ||
filename_bak=$filename"_bak" | ||
echo "corruption" > $filename_temp | ||
cat $filename >> $filename_temp | ||
|
||
# file lost | ||
mv $filename $filename_bak | ||
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 full -s "local://$TEST_DIR/$DB" || restore_fail=1 | ||
export GO_FAILPOINTS="" | ||
if [ $restore_fail -ne 1 ]; then | ||
echo 'restore success' | ||
exit 1 | ||
fi | ||
|
||
# file corruption | ||
mv $filename_temp $filename | ||
truncate --size=-11 $filename | ||
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 full -s "local://$TEST_DIR/$DB" || restore_fail=1 | ||
export GO_FAILPOINTS="" | ||
if [ $restore_fail -ne 1 ]; then | ||
echo 'restore success' | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
recordcount=10000 | ||
operationcount=0 | ||
workload=core | ||
|
||
readallfields=true | ||
|
||
readproportion=0 | ||
updateproportion=0 | ||
scanproportion=0 | ||
insertproportion=0 | ||
|
||
requestdistribution=uniform |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
#!/bin/sh | ||
# | ||
# Copyright 2023 PingCAP, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
set -eux | ||
|
||
# restart service without tiflash | ||
source $UTILS_DIR/run_services | ||
start_services --no-tiflash | ||
|
||
BACKUP_DIR=$TEST_DIR/"txn_backup" | ||
BACKUP_FULL=$TEST_DIR/"txnkv-full" | ||
|
||
checksum() { | ||
bin/txnkv --pd $PD_ADDR \ | ||
--ca "$TEST_DIR/certs/ca.pem" \ | ||
--cert "$TEST_DIR/certs/br.pem" \ | ||
--key "$TEST_DIR/certs/br.key" \ | ||
--mode checksum --start-key $1 --end-key $2 | grep result | tail -n 1 | awk '{print $3}' | ||
} | ||
|
||
fail_and_exit() { | ||
echo "TEST: [$TEST_NAME] failed!" | ||
exit 1 | ||
} | ||
|
||
clean() { | ||
bin/txnkv --pd $PD_ADDR \ | ||
--ca "$TEST_DIR/certs/ca.pem" \ | ||
--cert "$TEST_DIR/certs/br.pem" \ | ||
--key "$TEST_DIR/certs/br.key" \ | ||
--mode delete --start-key $1 --end-key $2 | ||
} | ||
|
||
test_full_txnkv_encryption() { | ||
check_range_start="hello" | ||
check_range_end="world" | ||
|
||
rm -rf $BACKUP_FULL | ||
|
||
checksum_full=$(checksum $check_range_start $check_range_end) | ||
# backup current state of key-values | ||
run_br --pd $PD_ADDR backup txn -s "local://$BACKUP_FULL" --crypter.method "aes128-ctr" --crypter.key "0123456789abcdef0123456789abcdef" | ||
|
||
clean $check_range_start $check_range_end | ||
# Ensure the data is deleted | ||
checksum_new=$(checksum $check_range_start $check_range_end) | ||
if [ "$checksum_new" == "$checksum_full" ];then | ||
echo "failed to delete data in range in encryption" | ||
fail_and_exit | ||
fi | ||
|
||
run_br --pd $PD_ADDR restore txn -s "local://$BACKUP_FULL" --crypter.method "aes128-ctr" --crypter.key "0123456789abcdef0123456789abcdef" | ||
checksum_new=$(checksum $check_range_start $check_range_end) | ||
if [ "$checksum_new" != "$checksum_full" ];then | ||
echo "failed to restore" | ||
fail_and_exit | ||
fi | ||
} | ||
|
||
run_test() { | ||
if [ -z "$1" ];then | ||
echo "run test" | ||
else | ||
export GO_FAILPOINTS="$1" | ||
echo "run test with failpoints: $GO_FAILPOINTS" | ||
fi | ||
|
||
rm -rf $BACKUP_DIR | ||
clean "hello" "world" | ||
|
||
# generate txn kv randomly in range[start-key, end-key) in 10s | ||
bin/txnkv --pd $PD_ADDR \ | ||
--ca "$TEST_DIR/certs/ca.pem" \ | ||
--cert "$TEST_DIR/certs/br.pem" \ | ||
--key "$TEST_DIR/certs/br.key" \ | ||
--mode rand-gen --start-key "hello" --end-key "world" --duration 10 | ||
|
||
checksum_ori=$(checksum "hello" "world") | ||
|
||
# backup txnkv | ||
echo "backup start..." | ||
run_br --pd $PD_ADDR backup txn -s "local://$BACKUP_DIR" | ||
|
||
# delete data in range[start-key, end-key) | ||
clean "hello" "world" | ||
# Ensure the data is deleted | ||
retry_cnt=0 | ||
while true; do | ||
checksum_new=$(checksum "hello" "world") | ||
|
||
if [ "$checksum_new" != "$checksum_empty" ]; then | ||
echo "failed to delete data in range after backup; retry_cnt = $retry_cnt" | ||
retry_cnt=$((retry_cnt+1)) | ||
if [ "$retry_cnt" -gt 50 ]; then | ||
fail_and_exit | ||
fi | ||
sleep 1 | ||
continue | ||
fi | ||
|
||
break | ||
done | ||
|
||
# restore rawkv | ||
echo "restore start..." | ||
run_br --pd $PD_ADDR restore txn -s "local://$BACKUP_DIR" | ||
|
||
checksum_new=$(checksum "hello" "world") | ||
|
||
if [ "$checksum_new" != "$checksum_ori" ];then | ||
echo "checksum failed after restore" | ||
fail_and_exit | ||
fi | ||
|
||
test_full_txnkv_encryption | ||
|
||
# delete data in range[start-key, end-key) | ||
clean "hello" "world" | ||
# Ensure the data is deleted | ||
checksum_new=$(checksum "hello" "world") | ||
|
||
if [ "$checksum_new" != "$checksum_empty" ];then | ||
echo "failed to delete data in range" | ||
fail_and_exit | ||
fi | ||
|
||
export GO_FAILPOINTS="" | ||
} | ||
|
||
# delete data in range[start-key, end-key) | ||
clean "hello" "world" | ||
checksum_empty=$(checksum "hello" "world") | ||
run_test "" |
Oops, something went wrong.