github.com/pingcap/br@v5.3.0-alpha.0.20220125034240-ec59c7b6ce30+incompatible/tests/lightning_checkpoint_engines/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 -eux 17 18 do_run_lightning() { 19 run_lightning --backend $1 --enable-checkpoint=1 --log-file "$TEST_DIR/lightning-checkpoint-engines.log" --config "tests/$TEST_NAME/$2.toml" 20 } 21 22 for BACKEND in importer local; do 23 if [ "$BACKEND" = 'local' ]; then 24 check_cluster_version 4 0 0 'local backend' || continue 25 fi 26 27 # First, verify that a normal operation is fine. 28 rm -f "$TEST_DIR/lightning-checkpoint-engines.log" 29 rm -f "/tmp/tidb_lightning_checkpoint.pb" 30 run_sql 'DROP DATABASE IF EXISTS cpeng;' 31 rm -rf $TEST_DIR/importer/* 32 33 export GO_FAILPOINTS="" 34 35 do_run_lightning $BACKEND config 36 37 # Check that we have indeed opened 6 engines (index + data engine) 38 DATA_ENGINE_COUNT=4 39 INDEX_ENGINE_COUNT=2 40 ENGINE_COUNT=6 41 OPEN_ENGINES_COUNT=$(grep 'open engine' "$TEST_DIR/lightning-checkpoint-engines.log" | wc -l) 42 echo "Number of open engines: $OPEN_ENGINES_COUNT" 43 [ "$OPEN_ENGINES_COUNT" -eq $ENGINE_COUNT ] 44 45 # Check that everything is correctly imported 46 run_sql 'SELECT count(*), sum(c) FROM cpeng.a' 47 check_contains 'count(*): 4' 48 check_contains 'sum(c): 10' 49 50 run_sql 'SELECT count(*), sum(c) FROM cpeng.b' 51 check_contains 'count(*): 4' 52 check_contains 'sum(c): 46' 53 54 # Now, verify it works with checkpoints as well. 55 56 run_sql 'DROP DATABASE cpeng;' 57 rm -f "/tmp/tidb_lightning_checkpoint.pb" 58 59 # Data engine part 60 export GO_FAILPOINTS='github.com/pingcap/br/pkg/lightning/restore/SlowDownImport=sleep(500);github.com/pingcap/br/pkg/lightning/restore/FailIfStatusBecomes=return(120);github.com/pingcap/br/pkg/lightning/restore/FailIfIndexEngineImported=return(140)' 61 for i in $(seq "$ENGINE_COUNT"); do 62 echo "******** Importing Table Now (step $i/$ENGINE_COUNT) ********" 63 ! do_run_lightning $BACKEND config 2> /dev/null 64 done 65 66 echo "******** Verify checkpoint no-op ********" 67 # all engines should have been imported here. 68 do_run_lightning $BACKEND config 69 70 run_sql 'SELECT count(*), sum(c) FROM cpeng.a' 71 check_contains 'count(*): 4' 72 check_contains 'sum(c): 10' 73 74 run_sql 'SELECT count(*), sum(c) FROM cpeng.b' 75 check_contains 'count(*): 4' 76 check_contains 'sum(c): 46' 77 78 # Now, try again with MySQL checkpoints 79 80 run_sql 'DROP DATABASE cpeng;' 81 run_sql 'DROP DATABASE IF EXISTS tidb_lightning_checkpoint;' 82 rm -rf $TEST_DIR/lightning_checkpoint_engines.sorted 83 rm -rf $TEST_DIR/importer/* 84 85 set +e 86 for i in $(seq "$ENGINE_COUNT"); do 87 echo "******** Importing Table Now (step $i/$ENGINE_COUNT) ********" 88 do_run_lightning $BACKEND mysql 2> /dev/null 89 [ $? -ne 0 ] || exit 1 90 done 91 set -e 92 93 echo "******** Verify checkpoint no-op ********" 94 do_run_lightning $BACKEND mysql 95 96 run_sql 'SELECT count(*), sum(c) FROM cpeng.a' 97 check_contains 'count(*): 4' 98 check_contains 'sum(c): 10' 99 100 run_sql 'SELECT count(*), sum(c) FROM cpeng.b' 101 check_contains 'count(*): 4' 102 check_contains 'sum(c): 46' 103 done