github.com/pingcap/br@v5.3.0-alpha.0.20220125034240-ec59c7b6ce30+incompatible/tests/lightning_checkpoint_columns/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 -euE
    17  
    18  # Populate the mydumper source
    19  DBPATH="$TEST_DIR/cp.mydump"
    20  
    21  mkdir -p $DBPATH
    22  echo 'CREATE DATABASE cp_tsr;' > "$DBPATH/cp_tsr-schema-create.sql"
    23  echo "CREATE TABLE tbl(i TINYINT PRIMARY KEY, j INT);" > "$DBPATH/cp_tsr.tbl-schema.sql"
    24  # the column orders in data file is different from table schema order.
    25  echo "INSERT INTO tbl (j, i) VALUES (3, 1),(4, 2);" > "$DBPATH/cp_tsr.tbl.sql"
    26  
    27  # Set minDeliverBytes to a small enough number to only write only 1 row each time
    28  # Set the failpoint to kill the lightning instance as soon as one row is written
    29  PKG="github.com/pingcap/br/pkg/lightning/restore"
    30  export GO_FAILPOINTS="$PKG/SlowDownWriteRows=sleep(1000);$PKG/FailAfterWriteRows=panic;$PKG/SetMinDeliverBytes=return(1)"
    31  
    32  # Start importing the tables.
    33  run_sql 'DROP DATABASE IF EXISTS cp_tsr'
    34  run_sql 'DROP DATABASE IF EXISTS tidb_lightning_checkpoint_test'
    35  
    36  set +e
    37  run_lightning -d "$DBPATH" --backend tidb --enable-checkpoint=1 2> /dev/null
    38  set -e
    39  run_sql 'SELECT count(*) FROM `cp_tsr`.tbl'
    40  check_contains "count(*): 1"
    41  
    42  # restart lightning from checkpoint, the second line should be written successfully
    43  export GO_FAILPOINTS=
    44  set +e
    45  run_lightning -d "$DBPATH" --backend tidb --enable-checkpoint=1 2> /dev/null
    46  set -e
    47  
    48  run_sql 'SELECT j FROM `cp_tsr`.tbl WHERE i = 2;'
    49  check_contains "j: 4"