github.com/pingcap/br@v5.3.0-alpha.0.20220125034240-ec59c7b6ce30+incompatible/tests/br_small_batch_size/run.sh (about) 1 #!/bin/sh 2 # 3 # Copyright 2020 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 # See the License for the specific language governing permissions and 14 # limitations under the License. 15 16 random_values() { 17 length=$1 18 count=$2 19 python -c " 20 import random 21 import string 22 for ignored in range($count): 23 print(''.join(random.choice(string.ascii_letters) for _ in range($length)))" | 24 awk '{print "(1" $1 "1)"}' | 25 tr "\n1" ",'" | 26 sed 's/,$//' 27 } 28 29 create_and_insert() { 30 table_name=$1 31 record_count=$2 32 run_sql "CREATE TABLE $DB.$table_name(k varchar(256) primary key)" 33 stmt="INSERT INTO $DB.$table_name VALUES `random_values 255 $record_count`" 34 echo $stmt | mysql -uroot -h127.0.0.1 -P4000 35 } 36 37 check_size() { 38 table_name=$1 39 record_count=$2 40 41 count=`run_sql 'select count(*) from $DB.$table_name' | awk '/count/{print $2}'` 42 43 if [ $count -ne $record_count ]; then 44 echo "check size failed: $count vs $record_count" 45 fi 46 } 47 48 set -eu 49 DB="$TEST_NAME" 50 TABLE="usertable" 51 52 run_sql "CREATE DATABASE $DB;" 53 54 record_counts=(10000 10010 10086) 55 for i in $record_counts; do 56 create_and_insert "t$i" $i 57 done 58 go-ycsb load mysql -P tests/$TEST_NAME/workload -p mysql.host=$TIDB_IP -p mysql.port=$TIDB_PORT -p mysql.user=root -p mysql.db=$DB 59 60 61 echo "backup start..." 62 backup_dir="$TEST_DIR/${TEST_NAME}_backup" 63 rm -rf $backup_dir 64 run_br backup full -s "local://$backup_dir" --pd $PD_ADDR 65 66 run_sql "drop database $DB" 67 68 69 echo "restore start..." 70 GO_FAILPOINTS="github.com/pingcap/br/pkg/task/small-batch-size=return(2)" \ 71 run_br restore full -s "local://$backup_dir" --pd $PD_ADDR --ratelimit 1024 72 73 for i in $record_counts; do 74 check_size "t$i" $i 75 done 76 check_size $TABLE 10000 77 78 run_sql "DROP DATABASE $DB"