github.com/pingcap/br@v5.3.0-alpha.0.20220125034240-ec59c7b6ce30+incompatible/tests/lightning_disk_quota/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  
    18  check_cluster_version 4 0 0 'local backend' || exit 0
    19  
    20  # the default mode (aes-128-ecb) can be easily compressed, switch to cbc to reduce the compression effect.
    21  run_sql 'DROP DATABASE IF EXISTS disk_quota;'
    22  run_sql "SELECT @@block_encryption_mode"
    23  OLD_ENCRYPTION_MODE=$(read_result)
    24  run_sql "SET GLOBAL block_encryption_mode = 'aes-256-cbc';"
    25  
    26  DISK_QUOTA_DIR="$TEST_DIR/with-disk-quota"
    27  FINISHED_FILE="$TEST_DIR/sorted-with-disk-quota.finished"
    28  
    29  mkdir -p "$DISK_QUOTA_DIR"
    30  rm -f "$FINISHED_FILE"
    31  cleanup() {
    32      touch "$FINISHED_FILE"
    33      run_sql "SET GLOBAL block_encryption_mode = '$OLD_ENCRYPTION_MODE';"
    34  }
    35  trap cleanup EXIT
    36  
    37  # There is normally a 2 second delay between these SET GLOBAL statements returns
    38  # and the changes are actually effective. So we have this check-and-retry loop
    39  # below to ensure Lightning gets our desired global vars.
    40  for i in $(seq 3); do
    41      sleep 1
    42      run_sql "SELECT @@block_encryption_mode"
    43      if [ "$(read_result)" = 'aes-256-cbc' ]; then
    44          break
    45      fi
    46  done
    47  
    48  while [ ! -e "$FINISHED_FILE" ] && [ -e "$DISK_QUOTA_DIR" ]; do
    49      # du may fail because the directory is removed by lightning
    50      DISK_USAGE=$(du -s -B1 "$DISK_QUOTA_DIR" | cut -f 1)
    51      # the disk quota of 75 MiB is a just soft limit.
    52      # the reserved size we have is (512 MiB + 4 files × 1000ms × 1 KiB/ms) = 516 MiB,
    53      # which sums up to 591 MiB as the hard limit.
    54      if [ "0$DISK_USAGE" -gt 619610112 ]; then
    55          echo "hard disk quota exceeded, actual size = $DISK_USAGE" > "$FINISHED_FILE"
    56          break
    57      else
    58          sleep 1
    59      fi
    60  done &
    61  
    62  export GO_FAILPOINTS="github.com/pingcap/br/pkg/lightning/restore/SlowDownWriteRows=sleep(50)"
    63  run_lightning --sorted-kv-dir "$DISK_QUOTA_DIR/sorted" --log-file "$TEST_DIR/lightning-disk-quota.log"
    64  touch "$FINISHED_FILE"
    65  # if $FINISHED_FILE has content, it is only because the hard disk quota is exceeded.
    66  [ -s "$FINISHED_FILE" ] && cat "$FINISHED_FILE" && exit 1
    67  
    68  # check that disk quota is indeed triggered.
    69  grep -q 'disk quota exceeded' "$TEST_DIR/lightning-disk-quota.log"
    70  
    71  # check that the columns are correct.
    72  run_sql "select cast(trim(trailing 'a' from aes_decrypt(sa, 'xxx', 'iviviviviviviviv')) as char) a from disk_quota.t where id = 1357"
    73  check_contains 'a: 1357'
    74  run_sql "select cast(trim(trailing 'e' from aes_decrypt(se, 'xxx', 'iviviviviviviviv')) as char) e from disk_quota.t where id = 246"
    75  check_contains 'e: 246'