github.com/pingcap/br@v5.3.0-alpha.0.20220125034240-ec59c7b6ce30+incompatible/tests/lightning_error_summary/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  # skip unstable test for temporary
    17  exit 0
    18  
    19  set -eux
    20  
    21  # Check that error summary are written at the bottom of import.
    22  run_sql 'DROP DATABASE IF EXISTS tidb_lightning_checkpoint_error_summary;'
    23  
    24  # The easiest way to induce error is to prepopulate the target table with conflicting content.
    25  run_sql 'CREATE DATABASE IF NOT EXISTS error_summary;'
    26  run_sql 'DROP TABLE IF EXISTS error_summary.a;'
    27  run_sql 'DROP TABLE IF EXISTS error_summary.c;'
    28  run_sql 'CREATE TABLE error_summary.a (id INT NOT NULL PRIMARY KEY, k INT NOT NULL);'
    29  run_sql 'CREATE TABLE error_summary.c (id INT NOT NULL PRIMARY KEY, k INT NOT NULL);'
    30  export GO_FAILPOINTS="github.com/pingcap/br/pkg/lightning/restore/InitializeCheckpointExit=return(true)"
    31  run_lightning --enable-checkpoint=1 --log-file "$TEST_DIR/lightning-error-summary.log"
    32  run_sql 'INSERT INTO error_summary.a VALUES (2, 4), (6, 8);'
    33  run_sql 'INSERT INTO error_summary.c VALUES (3, 9), (27, 81);'
    34  
    35  set +e
    36  export GO_FAILPOINTS=""
    37  run_lightning --enable-checkpoint=1 --log-file "$TEST_DIR/lightning-error-summary.log"
    38  ERRORCODE=$?
    39  set -e
    40  
    41  [ "$ERRORCODE" -ne 0 ]
    42  
    43  # Verify that table `b` is indeed imported
    44  run_sql 'SELECT sum(id), sum(k) FROM error_summary.b'
    45  check_contains 'sum(id): 28'
    46  check_contains 'sum(k): 32'
    47  
    48  # Verify the log contains the expected messages at the last few lines
    49  tail -20 "$TEST_DIR/lightning-error-summary.log" > "$TEST_DIR/lightning-error-summary.tail"
    50  grep -Fq '["tables failed to be imported"] [count=2]' "$TEST_DIR/lightning-error-summary.tail"
    51  grep -Fq '[-] [table=`error_summary`.`a`] [status=checksum] [error="checksum mismatched' "$TEST_DIR/lightning-error-summary.tail"
    52  grep -Fq '[-] [table=`error_summary`.`c`] [status=checksum] [error="checksum mismatched' "$TEST_DIR/lightning-error-summary.tail"
    53  ! grep -Fq '[-] [table=`error_summary`.`b`] [status=checksum] [error="checksum mismatched' "$TEST_DIR/lightning-error-summary.tail"
    54  
    55  # Now check the error log when the checkpoint is not cleaned.
    56  
    57  set +e
    58  run_lightning --enable-checkpoint=1 --log-file "$TEST_DIR/lightning-error-summary.log"
    59  ERRORCODE=$?
    60  set -e
    61  
    62  [ "$ERRORCODE" -ne 0 ]
    63  
    64  tail -20 "$TEST_DIR/lightning-error-summary.log" > "$TEST_DIR/lightning-error-summary.tail"
    65  grep -Fq '["TiDB Lightning has failed last time. To prevent data loss, this run will stop now. Please resolve errors first"] [count=2]' "$TEST_DIR/lightning-error-summary.tail"
    66  grep -Fq '[-] [table=`error_summary`.`a`] [status=18] [failedStep=checksum] [recommendedAction="./tidb-lightning-ctl --checkpoint-error-destroy='"'"'`error_summary`.`a`'"'"' --config=..."]' "$TEST_DIR/lightning-error-summary.tail"
    67  grep -Fq '[-] [table=`error_summary`.`c`] [status=18] [failedStep=checksum] [recommendedAction="./tidb-lightning-ctl --checkpoint-error-destroy='"'"'`error_summary`.`c`'"'"' --config=..."]' "$TEST_DIR/lightning-error-summary.tail"
    68  ! grep -Fq '[-] [table=`error_summary`.`b`] [status=18] [failedStep=checksum]' "$TEST_DIR/lightning-error-summary.tail"
    69  grep -Fq '["You may also run `./tidb-lightning-ctl --checkpoint-error-destroy=all --config=...` to start from scratch"]' "$TEST_DIR/lightning-error-summary.tail"
    70  grep -Fq '["For details of this failure, read the log file from the PREVIOUS run"]' "$TEST_DIR/lightning-error-summary.tail"