github.com/pingcap/br@v5.3.0-alpha.0.20220125034240-ec59c7b6ce30+incompatible/tests/br_tiflash/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 -eu
    17  DB="${TEST_NAME}_DATABASE"
    18  RECORD_COUNT=1000
    19  
    20  
    21  run_sql "CREATE DATABASE $DB"
    22  
    23  run_sql "CREATE TABLE $DB.kv(k varchar(256) primary key, v int)"
    24  
    25  stmt="INSERT INTO $DB.kv(k, v) VALUES ('1-record', 1)"
    26  for i in $(seq 2 $RECORD_COUNT); do
    27      stmt="$stmt,('$i-record', $i)"
    28  done
    29  run_sql "$stmt"
    30  
    31  if ! run_sql "ALTER TABLE $DB.kv SET TIFLASH REPLICA 1"; then
    32    # 10s should be enough for tiflash-proxy get started
    33    sleep 10
    34    run_sql "ALTER TABLE $DB.kv SET TIFLASH REPLICA 1"
    35  fi
    36  
    37  
    38  
    39  i=0
    40  while ! [ $(run_sql "select * from information_schema.tiflash_replica" | grep "PROGRESS" | sed "s/[^0-9]//g") -eq 1 ]; do
    41      i=$(( i + 1 ))
    42      echo "Waiting for TiFlash synchronizing [$i]."
    43      if [ $i -gt 20 ]; then
    44          echo "Failed to sync data to tiflash."
    45          exit 1
    46      fi
    47      sleep 5
    48  done
    49  
    50  rm -rf "/${TEST_DIR}/$DB"
    51  run_br backup full -s "local://$TEST_DIR/$DB" --pd $PD_ADDR
    52  
    53  run_sql "DROP DATABASE $DB"
    54  run_br restore full -s "local://$TEST_DIR/$DB" --pd $PD_ADDR
    55  
    56  # wating for TiFlash sync
    57  sleep 100
    58  AFTER_BR_COUNT=`run_sql "SELECT count(*) FROM $DB.kv;" | sed -n "s/[^0-9]//g;/^[0-9]*$/p" | tail -n1`
    59  if [ "$AFTER_BR_COUNT" -ne "$RECORD_COUNT" ]; then
    60      echo "failed to restore, before: $RECORD_COUNT; after: $AFTER_BR_COUNT"
    61      exit 1
    62  fi
    63  
    64  run_sql "DROP DATABASE $DB"