github.com/pingcap/br@v5.3.0-alpha.0.20220125034240-ec59c7b6ce30+incompatible/tests/br_split_region_fail/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  set -eux
    17  DB="$TEST_NAME"
    18  TABLE="usertable"
    19  LOG="not-leader.log"
    20  DB_COUNT=3
    21  
    22  for i in $(seq $DB_COUNT); do
    23      run_sql "CREATE DATABASE $DB${i};"
    24      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${i}
    25  done
    26  
    27  for i in $(seq $DB_COUNT); do
    28      row_count_ori[${i}]=$(run_sql "SELECT COUNT(*) FROM $DB${i}.$TABLE;" | awk '/COUNT/{print $2}')
    29  done
    30  
    31  
    32  # backup full
    33  echo "backup start..."
    34  run_br --pd $PD_ADDR backup full -s "local://$TEST_DIR/$DB"
    35  
    36  rm -f $LOG
    37  
    38  for i in $(seq $DB_COUNT); do
    39      run_sql "DROP DATABASE $DB${i};"
    40  done
    41  
    42  
    43  # restore full
    44  echo "restore start..."
    45  
    46  unset BR_LOG_TO_TERM
    47  GO_FAILPOINTS="github.com/pingcap/br/pkg/restore/not-leader-error=1*return(true)->1*return(false);\
    48  github.com/pingcap/br/pkg/restore/somewhat-retryable-error=3*return(true)" \
    49  run_br restore full -s "local://$TEST_DIR/$DB" --pd $PD_ADDR --ratelimit 1024 --log-file $LOG || true
    50  BR_LOG_TO_TERM=1
    51  
    52  grep "a error occurs on split region" $LOG && \
    53  grep "split region meet not leader error" $LOG && \
    54  grep "Full restore success" $LOG && \
    55  grep "find new leader" $LOG
    56  
    57  if [ $? -ne 0 ]; then
    58      echo "failed to retry on failpoint."
    59      echo "full log:"
    60      cat $LOG
    61      exit 1
    62  fi
    63  
    64  for i in $(seq $DB_COUNT); do
    65      row_count_new[${i}]=$(run_sql "SELECT COUNT(*) FROM $DB${i}.$TABLE;" | awk '/COUNT/{print $2}')
    66  done
    67  
    68  fail=false
    69  for i in $(seq $DB_COUNT); do
    70      if [ "${row_count_ori[i]}" != "${row_count_new[i]}" ];then
    71          fail=true
    72          echo "TEST: [$TEST_NAME] fail on database $DB${i}"
    73      fi
    74      echo "database $DB${i} [original] row count: ${row_count_ori[i]}, [after br] row count: ${row_count_new[i]}"
    75  done
    76  
    77  if $fail; then
    78      echo "TEST: [$TEST_NAME] failed!"
    79      exit 1
    80  fi
    81  
    82  for i in $(seq $DB_COUNT); do
    83      run_sql "DROP DATABASE $DB${i}"
    84  done