github.com/pingcap/br@v5.3.0-alpha.0.20220125034240-ec59c7b6ce30+incompatible/tests/br_full_ddl/run.sh (about) 1 #!/bin/sh 2 # 3 # Copyright 2019 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 set -eu 17 DB="$TEST_NAME" 18 TABLE="usertable" 19 DDL_COUNT=5 20 LOG=/$TEST_DIR/backup.log 21 BACKUP_STAT=/$TEST_DIR/backup_stat 22 RESOTRE_STAT=/$TEST_DIR/restore_stat 23 24 run_sql "CREATE DATABASE $DB;" 25 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 26 27 row_count_ori=$(run_sql "SELECT COUNT(*) FROM $DB.$TABLE;" | awk '/COUNT/{print $2}') 28 29 for i in $(seq $DDL_COUNT); do 30 run_sql "USE $DB; ALTER TABLE $TABLE ADD INDEX (FIELD$i);" 31 done 32 33 for i in $(seq $DDL_COUNT); do 34 if (( RANDOM % 2 )); then 35 run_sql "USE $DB; ALTER TABLE $TABLE DROP INDEX FIELD$i;" 36 fi 37 done 38 39 # run analyze to generate stats 40 run_sql "analyze table $DB.$TABLE;" 41 # record field0's stats and remove last_update_version 42 # it's enough to compare with restore stats 43 # the stats looks like 44 # { 45 # "histogram": { 46 # "ndv": 10000, 47 # "buckets": [ 48 # { 49 # "count": 40, 50 # "lower_bound": "QUFqVW1HZkt3UWhXakdCSlF0a2NHRFp0UWpFZ1lEUFFNWXVtVFFTRUh0U3N4RXhub2VMeUF1emhyT0FjWUZvWUhRZVZBcGJLRlVoWVlWR 0djSmRYbnhxc1NzcG1VTHFoZnJZbg==", 51 # "upper_bound": "QUp5bmVNc29FVUFIZ3ZKS3dCaUdGQ0xoV1BSQ0FWZ2VzZGpGU05na2xsYUhkY1VMVWdEeHZORUJLbW9tWGxSTWZQTmZYZVVWR3h5amVyW EJXQ01GcU5mRWlHeEd1dndZa1BSRg==", 52 # "repeats": 1 53 # }, 54 # ...(nearly 1000 rows) 55 # ], 56 # "cm_sketch": { 57 # "rows": [ 58 # { 59 # "counters": [ 60 # 5, 61 # ...(nearly 10000 rows) 62 # ], 63 # } 64 # ] 65 # } 66 run_curl https://$TIDB_STATUS_ADDR/stats/dump/$DB/$TABLE | jq '.columns.field0 | del(.last_update_version, .fm_sketch, .correlation)' > $BACKUP_STAT 67 68 # backup full 69 echo "backup start with stats..." 70 # Do not log to terminal 71 unset BR_LOG_TO_TERM 72 cluster_index_before_backup=$(run_sql "show variables like '%cluster%';" | awk '{print $2}') 73 74 run_br --pd $PD_ADDR backup full -s "local://$TEST_DIR/$DB" --log-file $LOG --ignore-stats=false || cat $LOG 75 checksum_count=$(cat $LOG | grep "checksum success" | wc -l | xargs) 76 77 if [ "${checksum_count}" -lt "1" ];then 78 echo "TEST: [$TEST_NAME] fail on fast checksum" 79 echo $(cat $LOG | grep checksum) 80 exit 1 81 fi 82 83 echo "backup start without stats..." 84 run_br --pd $PD_ADDR backup full -s "local://$TEST_DIR/${DB}_disable_stats" --concurrency 4 85 86 run_sql "DROP DATABASE $DB;" 87 88 cluster_index_before_restore=$(run_sql "show variables like '%cluster%';" | awk '{print $2}') 89 # keep cluster index enable or disable at same time. 90 if [[ "${cluster_index_before_backup}" != "${cluster_index_before_restore}" ]]; then 91 echo "TEST: [$TEST_NAME] must enable or disable cluster_index at same time" 92 echo "cluster index before backup is $cluster_index_before_backup" 93 echo "cluster index before restore is $cluster_index_before_restore" 94 exit 1 95 fi 96 97 echo "restore full without stats..." 98 run_br restore full -s "local://$TEST_DIR/${DB}_disable_stats" --pd $PD_ADDR 99 curl $TIDB_IP:10080/stats/dump/$DB/$TABLE | jq '.columns.field0 | del(.last_update_version, .fm_sketch, .correlation)' > $RESOTRE_STAT 100 101 # stats should not be equal because we disable stats by default. 102 if diff -q $BACKUP_STAT $RESOTRE_STAT > /dev/null 103 then 104 echo "TEST: [$TEST_NAME] fail due to stats are equal" 105 grep ERROR $LOG 106 exit 1 107 fi 108 109 # clear restore environment 110 run_sql "DROP DATABASE $DB;" 111 112 # restore full 113 echo "restore start..." 114 export GO_FAILPOINTS="github.com/pingcap/br/pkg/pdutil/PDEnabledPauseConfig=return(true)" 115 run_br restore full -s "local://$TEST_DIR/$DB" --pd $PD_ADDR --log-file $LOG || { cat $LOG; exit 1; } 116 export GO_FAILPOINTS="" 117 118 pause_count=$(cat $LOG | grep "pause configs successful"| wc -l | xargs) 119 if [ "${pause_count}" != "1" ];then 120 echo "TEST: [$TEST_NAME] fail on pause config" 121 exit 1 122 fi 123 124 BR_LOG_TO_TERM=1 125 126 skip_count=$(cat $LOG | grep "range is empty" | wc -l | xargs) 127 128 # ensure there are only less than two(write + default) range empty error, 129 # because backup range end key is large than reality. 130 # so the last region may download nothing. 131 # FIXME maybe we can treat endkey specially in the future. 132 if [ "${skip_count}" -gt "2" ];then 133 echo "TEST: [$TEST_NAME] fail on download sst, too many skipped range" 134 echo $(cat $LOG | grep "range is empty") 135 exit 1 136 fi 137 138 run_curl https://$TIDB_STATUS_ADDR/stats/dump/$DB/$TABLE | jq '.columns.field0 | del(.last_update_version, .fm_sketch, .correlation)' > $RESOTRE_STAT 139 140 if diff -q $BACKUP_STAT $RESOTRE_STAT > /dev/null 141 then 142 echo "stats are equal" 143 else 144 echo "TEST: [$TEST_NAME] fail due to stats are not equal" 145 grep ERROR $LOG 146 cat $BACKUP_STAT | head -n 1000 147 cat $RESOTRE_STAT | head -n 1000 148 exit 1 149 fi 150 151 row_count_new=$(run_sql "SELECT COUNT(*) FROM $DB.$TABLE;" | awk '/COUNT/{print $2}') 152 153 fail=false 154 if [ "${row_count_ori}" != "${row_count_new}" ];then 155 fail=true 156 echo "TEST: [$TEST_NAME] fail on database $DB${i}" 157 fi 158 echo "database $DB$ [original] row count: ${row_count_ori}, [after br] row count: ${row_count_new}" 159 160 if $fail; then 161 echo "TEST: [$TEST_NAME] failed!" 162 exit 1 163 fi 164 165 run_sql "DROP DATABASE $DB;"