github.com/pingcap/ticdc@v0.0.0-20220526033649-485a10ef2652/tests/cdclog_file/run.sh (about)

     1  #!/bin/bash
     2  
     3  set -e
     4  
     5  CUR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
     6  source $CUR/../_utils/test_prepare
     7  WORK_DIR=$OUT_DIR/$TEST_NAME
     8  CDC_BINARY=cdc.test
     9  
    10  
    11  function prepare() {
    12      rm -rf "$WORK_DIR"
    13      mkdir -p "$WORK_DIR"
    14      stop_tidb_cluster
    15      start_tidb_cluster --workdir $WORK_DIR
    16  
    17      cd $WORK_DIR
    18  
    19      # record tso before we create tables to skip the system table DDLs
    20      start_ts=$(run_cdc_cli tso query --pd=http://$UP_PD_HOST_1:$UP_PD_PORT_1)
    21  
    22      run_cdc_server --workdir $WORK_DIR --binary $CDC_BINARY
    23  
    24      SINK_URI="local://$WORK_DIR/test?"
    25  
    26      run_cdc_cli changefeed create --start-ts=$start_ts --sink-uri="$SINK_URI"
    27  }
    28  
    29  success=0
    30  function check_cdclog() {
    31    # TODO test rotate file
    32    DATA_DIR="$WORK_DIR/test"
    33    # retrieve table id by log meta
    34    if [ ! -f $DATA_DIR/log.meta ]; then
    35      return
    36    fi
    37    table_id=$(cat $DATA_DIR/log.meta | jq | grep t1 | awk -F '"' '{print $2}')
    38    if [ ! -d $DATA_DIR/t_$table_id ]; then
    39      return
    40    fi
    41    file_count=$(ls -ahl $DATA_DIR/t_$table_id | grep cdclog | wc -l)
    42    if [[ ! "$file_count" -eq "1" ]]; then
    43        echo "$TEST_NAME failed, expect 1 row changed files, obtain $file_count"
    44        return
    45    fi
    46    if [ ! -d $DATA_DIR/ddls ]; then
    47      return
    48    fi
    49    ddl_file_count=$(ls -ahl $DATA_DIR/ddls | grep ddl | wc -l)
    50    if [[ ! "$ddl_file_count" -eq "1" ]]; then
    51        echo "$TEST_NAME failed, expect 1 ddl file, obtain $ddl_file_count"
    52        return
    53    fi
    54    success=1
    55  }
    56  
    57  function cdclog_test() {
    58    run_sql "drop database if exists $TEST_NAME"
    59    run_sql "create database $TEST_NAME"
    60    run_sql "create table $TEST_NAME.t1 (c0 int primary key, payload varchar(1024));"
    61    run_sql "create table $TEST_NAME.t2 (c0 int primary key, payload varchar(1024));"
    62  
    63    run_sql "insert into $TEST_NAME.t1 values (1, 'a')"
    64    run_sql "insert into $TEST_NAME.t1 values (2, 'b')"
    65  
    66    i=0
    67    while [ $i -lt 30 ]
    68    do
    69      check_cdclog
    70      if [ "$success" == 1 ]; then
    71          echo "check log successfully"
    72          break
    73      fi
    74      i=$(( $i + 1 ))
    75      echo "check log failed $i-th time, retry later"
    76      sleep 2
    77    done
    78    cleanup_process $CDC_BINARY
    79  }
    80  
    81  trap stop_tidb_cluster EXIT
    82  prepare $*
    83  cdclog_test $*
    84  check_logs $WORK_DIR
    85  echo "[$(date)] <<<<<< run test case $TEST_NAME success! >>>>>>"