github.com/pingcap/br@v5.3.0-alpha.0.20220125034240-ec59c7b6ce30+incompatible/tests/lightning_local_backend/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  ENGINE_COUNT=6
    21  
    22  # First, verify that inject with not leader error is fine.
    23  rm -f "$TEST_DIR/lightning-local.log"
    24  rm -f "/tmp/tidb_lightning_checkpoint_local_backend_test.pb"
    25  run_sql 'DROP DATABASE IF EXISTS cpeng;'
    26  export GO_FAILPOINTS='github.com/pingcap/br/pkg/lightning/backend/local/FailIngestMeta=1*return("notleader")'
    27  
    28  run_lightning --backend local --enable-checkpoint=1 --log-file "$TEST_DIR/lightning-local.log" --config "tests/$TEST_NAME/config.toml"
    29  
    30  # Check that everything is correctly imported
    31  run_sql 'SELECT count(*), sum(c) FROM cpeng.a'
    32  check_contains 'count(*): 4'
    33  check_contains 'sum(c): 10'
    34  
    35  run_sql 'SELECT count(*), sum(c) FROM cpeng.b'
    36  check_contains 'count(*): 4'
    37  check_contains 'sum(c): 46'
    38  
    39  # Now, verify it works with epoch not match as well.
    40  run_sql 'DROP DATABASE cpeng;'
    41  rm -f "/tmp/tidb_lightning_checkpoint_local_backend_test.pb"
    42  
    43  export GO_FAILPOINTS='github.com/pingcap/br/pkg/lightning/backend/local/FailIngestMeta=2*return("epochnotmatch")'
    44  
    45  run_lightning --backend local --enable-checkpoint=1 --log-file "$TEST_DIR/lightning-local.log" --config "tests/$TEST_NAME/config.toml"
    46  
    47  run_sql 'SELECT count(*), sum(c) FROM cpeng.a'
    48  check_contains 'count(*): 4'
    49  check_contains 'sum(c): 10'
    50  
    51  run_sql 'SELECT count(*), sum(c) FROM cpeng.b'
    52  check_contains 'count(*): 4'
    53  check_contains 'sum(c): 46'
    54  
    55  
    56  # Now, verify it works with checkpoints as well.
    57  run_sql 'DROP DATABASE cpeng;'
    58  rm -f "/tmp/tidb_lightning_checkpoint_local_backend_test.pb"
    59  
    60  set +e
    61  export GO_FAILPOINTS='github.com/pingcap/br/pkg/lightning/restore/FailIfStatusBecomes=return(90);'
    62  for i in $(seq "$ENGINE_COUNT"); do
    63      echo "******** Importing Table Now (step $i/$ENGINE_COUNT) ********"
    64      run_lightning --backend local --enable-checkpoint=1 --log-file "$TEST_DIR/lightning-local.log" --config "tests/$TEST_NAME/config.toml"
    65      [ $? -ne 0 ] || exit 1
    66  done
    67  set -e
    68  
    69  export GO_FAILPOINTS=''
    70  echo "******** Verify checkpoint no-op ********"
    71  run_lightning --backend local --enable-checkpoint=1 --log-file "$TEST_DIR/lightning-local.log" --config "tests/$TEST_NAME/config.toml"
    72  
    73  run_sql 'SELECT count(*), sum(c) FROM cpeng.a'
    74  check_contains 'count(*): 4'
    75  check_contains 'sum(c): 10'
    76  
    77  run_sql 'SELECT count(*), sum(c) FROM cpeng.b'
    78  check_contains 'count(*): 4'
    79  check_contains 'sum(c): 46'
    80  
    81  # Verify GetLocalStoringTables works
    82  # failpoint works for per table not task, so we limit this test to task that allow one table
    83  for ckpt in mysql file; do
    84    run_sql 'DROP DATABASE IF EXISTS cpeng;'
    85    run_sql 'DROP DATABASE IF EXISTS tidb_lightning_checkpoint_local_backend_test'
    86    rm -f "/tmp/tidb_lightning_checkpoint_local_backend_test.pb"
    87  
    88    # before chunk pos is updated, local files could handle lost
    89    set +e
    90    export GO_FAILPOINTS="github.com/pingcap/br/pkg/lightning/restore/FailAfterWriteRows=return"
    91    run_lightning --backend local --enable-checkpoint=1 --log-file "$TEST_DIR/lightning-local.log" --config "tests/$TEST_NAME/$ckpt.toml"
    92    set -e
    93    run_lightning_ctl --check-local-storage \
    94      --backend local \
    95      --enable-checkpoint=1 \
    96      --config=tests/$TEST_NAME/$ckpt.toml >$TEST_DIR/lightning_ctl.output 2>&1
    97    grep -Fq "No table has lost intermediate files according to given config" $TEST_DIR/lightning_ctl.output
    98  
    99    # when position of chunk file doesn't equal to offset, intermediate file should exist
   100    run_sql 'DROP DATABASE IF EXISTS cpeng;'
   101    run_sql 'DROP DATABASE IF EXISTS tidb_lightning_checkpoint_local_backend_test'
   102    rm -f "/tmp/tidb_lightning_checkpoint_local_backend_test.pb"
   103    set +e
   104    export GO_FAILPOINTS="github.com/pingcap/br/pkg/lightning/restore/LocalBackendSaveCheckpoint=return;github.com/pingcap/br/pkg/lightning/restore/FailIfImportedChunk=return(1)"
   105    run_lightning --backend local --enable-checkpoint=1 --log-file "$TEST_DIR/lightning-local.log" --config "tests/$TEST_NAME/$ckpt.toml"
   106    set -e
   107    run_lightning_ctl --check-local-storage \
   108      --backend local \
   109      --enable-checkpoint=1 \
   110      --config=tests/$TEST_NAME/$ckpt.toml >$TEST_DIR/lightning_ctl.output 2>&1
   111    grep -Eq "These tables are missing intermediate files: \[.+\]" $TEST_DIR/lightning_ctl.output
   112    # don't distinguish whole sort-kv directory missing and table's directory missing for now
   113    ls -lA $TEST_DIR/$TEST_NAME.sorted
   114  
   115    # after index engine is imported, local file could handle lost
   116    set +e
   117    export GO_FAILPOINTS="github.com/pingcap/br/pkg/lightning/restore/FailIfIndexEngineImported=return(1)"
   118    run_lightning --backend local --enable-checkpoint=1 --log-file "$TEST_DIR/lightning-local.log" --config "tests/$TEST_NAME/$ckpt.toml"
   119    set -e
   120    run_lightning_ctl --check-local-storage \
   121      --backend local \
   122      --enable-checkpoint=1 \
   123      --config=tests/$TEST_NAME/$ckpt.toml >$TEST_DIR/lightning_ctl.output 2>&1
   124    grep -Fq "No table has lost intermediate files according to given config" $TEST_DIR/lightning_ctl.output
   125  done
   126  rm -r $TEST_DIR/$TEST_NAME.sorted