github.com/pingcap/br@v5.3.0-alpha.0.20220125034240-ec59c7b6ce30+incompatible/tests/br_rawkv/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  
    18  # restart service without tiflash
    19  source $( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/../_utils/run_services
    20  start_services --no-tiflash
    21  
    22  BACKUP_DIR=$TEST_DIR/"raw_backup"
    23  
    24  rm -rf $BACKUP_DIR
    25  
    26  checksum() {
    27      bin/rawkv --pd $PD_ADDR \
    28          --ca "$TEST_DIR/certs/ca.pem" \
    29          --cert "$TEST_DIR/certs/br.pem" \
    30          --key "$TEST_DIR/certs/br.key" \
    31          --mode checksum --start-key $1 --end-key $2 | grep result | awk '{print $3}'
    32  }
    33  
    34  fail_and_exit() {
    35      echo "TEST: [$TEST_NAME] failed!"
    36      exit 1
    37  }
    38  
    39  clean() {
    40      bin/rawkv --pd $PD_ADDR \
    41      --ca "$TEST_DIR/certs/ca.pem" \
    42      --cert "$TEST_DIR/certs/br.pem" \
    43      --key "$TEST_DIR/certs/br.key" \
    44      --mode delete --start-key $1 --end-key $2
    45  }
    46  
    47  test_full_rawkv() {
    48      check_range_start=00
    49      check_range_end=ff
    50  
    51      checksum_full=$(checksum $check_range_start $check_range_end)
    52      # backup current state of key-values
    53      run_br --pd $PD_ADDR backup raw -s "local://$TEST_DIR/rawkv-full" 
    54  
    55      clean $check_range_start $check_range_end
    56      # Ensure the data is deleted
    57      checksum_new=$(checksum $check_range_start $check_range_end)
    58      if [ "$checksum_new" == "$checksum_full" ];then
    59          echo "failed to delete data in range"
    60          fail_and_exit
    61      fi
    62  
    63      run_br --pd $PD_ADDR restore raw -s "local://$TEST_DIR/rawkv-full"
    64      checksum_new=$(checksum $check_range_start $check_range_end)
    65      if [ "$checksum_new" != "$checksum_full" ];then
    66          echo "failed to restore"
    67          fail_and_exit
    68      fi
    69  }
    70  
    71  checksum_empty=$(checksum 31 3130303030303030)
    72  
    73  # generate raw kv randomly in range[start-key, end-key) in 10s
    74  bin/rawkv --pd $PD_ADDR \
    75      --ca "$TEST_DIR/certs/ca.pem" \
    76      --cert "$TEST_DIR/certs/br.pem" \
    77      --key "$TEST_DIR/certs/br.key" \
    78      --mode rand-gen --start-key 31 --end-key 3130303030303030 --duration 10
    79  
    80  # put some keys around 311122 to check the correctness of endKey of restoring
    81  bin/rawkv --pd $PD_ADDR \
    82      --ca "$TEST_DIR/certs/ca.pem" \
    83      --cert "$TEST_DIR/certs/br.pem" \
    84      --key "$TEST_DIR/certs/br.key" \
    85      --mode put --put-data "311121:31, 31112100:32, 311122:33, 31112200:34, 3111220000:35, 311123:36"
    86  
    87  checksum_ori=$(checksum 31 3130303030303030)
    88  checksum_partial=$(checksum 311111 311122)
    89  
    90  # backup rawkv
    91  echo "backup start..."
    92  run_br --pd $PD_ADDR backup raw -s "local://$BACKUP_DIR" --start 31 --end 3130303030303030 --format hex --concurrency 4
    93  
    94  # delete data in range[start-key, end-key)
    95  clean 31 3130303030303030
    96  # Ensure the data is deleted
    97  checksum_new=$(checksum 31 3130303030303030)
    98  
    99  if [ "$checksum_new" != "$checksum_empty" ];then
   100      echo "failed to delete data in range"
   101      fail_and_exit
   102  fi
   103  
   104  # restore rawkv
   105  echo "restore start..."
   106  run_br --pd $PD_ADDR restore raw -s "local://$BACKUP_DIR" --start 31 --end 3130303030303030 --format hex
   107  
   108  checksum_new=$(checksum 31 3130303030303030)
   109  
   110  if [ "$checksum_new" != "$checksum_ori" ];then
   111      echo "checksum failed after restore"
   112      fail_and_exit
   113  fi
   114  
   115  test_full_rawkv
   116  
   117  # delete data in range[start-key, end-key)
   118  clean 31 3130303030303030
   119  # Ensure the data is deleted
   120  checksum_new=$(checksum 31 3130303030303030)
   121  
   122  if [ "$checksum_new" != "$checksum_empty" ];then
   123      echo "failed to delete data in range"
   124      fail_and_exit
   125  fi
   126  
   127  echo "partial restore start..."
   128  run_br --pd $PD_ADDR restore raw -s "local://$BACKUP_DIR" --start 311111 --end 311122 --format hex --concurrency 4
   129  bin/rawkv --pd $PD_ADDR \
   130      --ca "$TEST_DIR/certs/ca.pem" \
   131      --cert "$TEST_DIR/certs/br.pem" \
   132      --key "$TEST_DIR/certs/br.key" \
   133      --mode scan --start-key 311121 --end-key 33
   134  
   135  checksum_new=$(checksum 31 3130303030303030)
   136  
   137  if [ "$checksum_new" != "$checksum_partial" ];then
   138      echo "checksum failed after restore"
   139      fail_and_exit
   140  fi