github.com/pingcap/ticdc@v0.0.0-20220526033649-485a10ef2652/tests/processor_stop_delay_2/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  TABLE_COUNT=3
    11  
    12  function check_position_removed() {
    13      pd=$1
    14      position=$(cdc cli unsafe show-metadata --pd=$pd | grep "position")
    15      cdc cli unsafe show-metadata --pd=$pd
    16      echo "AAposition: $position"
    17      echo "AAposition: ${#position}"
    18      if [[ ! "${#position}" -eq "0" ]]; then
    19          echo "position: $position"
    20          exit 1
    21      fi
    22  }
    23  
    24  function check_changefeed_state() {
    25      pd_addr=$1
    26      changefeed_id=$2
    27      expected=$3
    28      state=$(cdc cli --pd=$pd_addr changefeed query -s -c $changefeed_id|jq -r ".state")
    29      if [[ "$state" != "$expected" ]];then
    30          echo "unexpected state $state, expected $expected"
    31          exit 1
    32      fi
    33  }
    34  
    35  export -f check_position_removed
    36  export -f check_changefeed_state
    37  
    38  function run() {
    39      rm -rf $WORK_DIR && mkdir -p $WORK_DIR
    40      start_tidb_cluster --workdir $WORK_DIR
    41      cd $WORK_DIR
    42  
    43      pd_addr="http://$UP_PD_HOST_1:$UP_PD_PORT_1"
    44      TOPIC_NAME="ticdc-processor-stop-delay-$RANDOM"
    45      case $SINK_TYPE in
    46          kafka) SINK_URI="kafka://127.0.0.1:9092/$TOPIC_NAME?partition-num=4&kafka-version=${KAFKA_VERSION}";;
    47          *) SINK_URI="mysql://root@127.0.0.1:3306/?max-txn-row=1";;
    48      esac
    49      if [ "$SINK_TYPE" == "kafka" ]; then
    50        run_kafka_consumer $WORK_DIR "kafka://127.0.0.1:9092/$TOPIC_NAME?partition-num=4&version=${KAFKA_VERSION}"
    51      fi
    52      export GO_FAILPOINTS='github.com/pingcap/ticdc/cdc/ProcessorDDLPullerExitDelaying=sleep(2000);github.com/pingcap/ticdc/cdc/ProcessorUpdatePositionDelaying=sleep(2000)' # old processor
    53      # this case should be skipped when new processor enabled
    54  
    55      run_cdc_server --workdir $WORK_DIR --binary $CDC_BINARY --addr "127.0.0.1:8300" --pd $pd_addr
    56      changefeed_id=$(cdc cli changefeed create --pd=$pd_addr --sink-uri="$SINK_URI" 2>&1|tail -n2|head -n1|awk '{print $2}')
    57      run_sql "CREATE DATABASE processor_stop_delay_2;" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
    58      run_sql "CREATE table processor_stop_delay_2.t (id int primary key auto_increment, t datetime DEFAULT CURRENT_TIMESTAMP)" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
    59      run_sql "INSERT INTO processor_stop_delay_2.t values (),(),(),(),(),(),()" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
    60  
    61      # pause changefeed first, and then resume the changefeed. The processor stop
    62      # logic will be delayed by 10s, which is controlled by failpoint injection.
    63      # The changefeed should be resumed and no data loss.
    64      cdc cli changefeed pause --changefeed-id=$changefeed_id --pd=$pd_addr
    65      ensure 10 check_position_removed $pd_addr
    66      ensure 10 check_changefeed_state $pd_addr $changefeed_id "stopped"
    67      run_sql "INSERT INTO processor_stop_delay_2.t values (),(),(),(),(),(),()" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
    68      cdc cli changefeed resume --changefeed-id=$changefeed_id --pd=$pd_addr
    69      run_sql "INSERT INTO processor_stop_delay_2.t values (),(),(),(),(),(),()" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
    70  
    71      check_sync_diff $WORK_DIR $CUR/conf/diff_config.toml
    72  
    73      export GO_FAILPOINTS=''
    74      cleanup_process $CDC_BINARY
    75  }
    76  
    77  trap stop_tidb_cluster EXIT
    78  run $*
    79  check_logs $WORK_DIR
    80  echo "[$(date)] <<<<<< run test case $TEST_NAME success! >>>>>>"