github.com/pingcap/ticdc@v0.0.0-20220526033649-485a10ef2652/tests/kill_owner_with_ddl/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  SINK_TYPE=$1
    10  
    11  MAX_RETRIES=10
    12  
    13  function check_capture_count() {
    14      pd=$1
    15      expected=$2
    16      count=$(cdc cli capture list --pd=$pd 2>&1|jq '.|length')
    17      if [[ ! "$count" -eq "$expected" ]]; then
    18          echo "count: $count expected: $expected"
    19          exit 1
    20      fi
    21  }
    22  
    23  function kill_cdc_and_restart() {
    24      pd_addr=$1
    25      work_dir=$2
    26      cdc_binary=$3
    27      MAX_RETRIES=10
    28      cdc_pid=$(curl -s http://127.0.0.1:8300/status|jq '.pid')
    29      kill $cdc_pid
    30      ensure $MAX_RETRIES check_capture_count $pd_addr 0
    31      run_cdc_server --workdir $work_dir --binary $cdc_binary --addr "127.0.0.1:8300" --pd $pd_addr
    32      ensure $MAX_RETRIES check_capture_count $pd_addr 1
    33  }
    34  
    35  export -f check_capture_count
    36  export -f kill_cdc_and_restart
    37  
    38  function run() {
    39      # kafka is not supported yet.
    40      if [ "$SINK_TYPE" == "kafka" ]; then
    41        return
    42      fi
    43  
    44      rm -rf $WORK_DIR && mkdir -p $WORK_DIR
    45      start_tidb_cluster --workdir $WORK_DIR
    46      cd $WORK_DIR
    47  
    48      pd_addr="http://$UP_PD_HOST_1:$UP_PD_PORT_1"
    49      SINK_URI="mysql://normal:123456@127.0.0.1:3306/?max-txn-row=1"
    50  
    51      run_cdc_server --workdir $WORK_DIR --binary $CDC_BINARY --addr "127.0.0.1:8300" --pd $pd_addr
    52      cdc cli changefeed create --pd=$pd_addr --sink-uri="$SINK_URI"
    53      run_sql "CREATE DATABASE kill_owner_with_ddl;" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
    54      run_sql "CREATE table kill_owner_with_ddl.t1 (id int primary key auto_increment, val int);" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
    55      check_table_exists "kill_owner_with_ddl.t1" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}
    56  
    57      export GO_FAILPOINTS='github.com/pingcap/ticdc/cdc/sink/MySQLSinkExecDDLDelay=return(true);github.com/pingcap/ticdc/cdc/ownerFlushIntervalInject=return(0)'
    58      kill_cdc_and_restart $pd_addr $WORK_DIR $CDC_BINARY
    59  
    60      for i in $(seq 2 3); do
    61          run_sql "CREATE table kill_owner_with_ddl.t$i (id int primary key auto_increment, val int);" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
    62      done
    63      for i in $(seq 1 3); do
    64          run_sql "INSERT INTO kill_owner_with_ddl.t$i VALUES (),(),();" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
    65      done
    66  
    67      # sleep to ensure processor has consumed the DDL and flushed checkpoint
    68      sleep 5
    69  
    70      for i in $(seq 1 3); do
    71          kill_cdc_and_restart $pd_addr $WORK_DIR $CDC_BINARY
    72          sleep 8
    73      done
    74  
    75      export GO_FAILPOINTS=''
    76      kill_cdc_and_restart $pd_addr $WORK_DIR $CDC_BINARY
    77  
    78      for i in $(seq 1 3); do
    79          check_table_exists "kill_owner_with_ddl.t$i" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}
    80      done
    81      check_sync_diff $WORK_DIR $CUR/conf/diff_config.toml
    82  
    83      cleanup_process $CDC_BINARY
    84  }
    85  
    86  trap stop_tidb_cluster EXIT
    87  run $*
    88  check_logs $WORK_DIR
    89  echo "[$(date)] <<<<<< run test case $TEST_NAME success! >>>>>>"