github.com/pingcap/ticdc@v0.0.0-20220526033649-485a10ef2652/tests/changefeed_auto_stop/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  function check_changefeed_state() {
    12      endpoints=$1
    13      changefeedid=$2
    14      expected=$3
    15      output=$(cdc cli changefeed query --simple --changefeed-id $changefeedid --pd=http://$endpoints 2>&1)
    16      state=$(echo $output | grep -oE "\"state\": \"[a-z]+\""|tr -d '" '|awk -F':' '{print $(NF)}')
    17      if [ "$state" != "$expected" ]; then
    18          echo "unexpected state $output, expected $expected"
    19          exit 1
    20      fi
    21  }
    22  
    23  export -f check_changefeed_state
    24  
    25  function run() {
    26      DB_COUNT=4
    27  
    28      rm -rf $WORK_DIR && mkdir -p $WORK_DIR
    29      start_tidb_cluster --workdir $WORK_DIR
    30      cd $WORK_DIR
    31      start_ts=$(cdc cli tso query --pd=http://$UP_PD_HOST_1:$UP_PD_PORT_1)
    32  
    33      for i in $(seq $DB_COUNT); do
    34          db="changefeed_auto_stop_$i"
    35          run_sql "CREATE DATABASE $db;" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
    36          go-ycsb load mysql -P $CUR/conf/workload -p mysql.host=${UP_TIDB_HOST} -p mysql.port=${UP_TIDB_PORT} -p mysql.user=root -p mysql.db=$db
    37      done
    38  
    39      run_cdc_server --workdir $WORK_DIR --binary $CDC_BINARY --logsuffix "1" --addr "127.0.0.1:8301" --pd "http://${UP_PD_HOST_1}:${UP_PD_PORT_1}"
    40      export GO_FAILPOINTS='github.com/pingcap/ticdc/cdc/ProcessorSyncResolvedError=1*return(true);github.com/pingcap/ticdc/cdc/ProcessorUpdatePositionDelaying=sleep(1000)' # old processor
    41      # export GO_FAILPOINTS='github.com/pingcap/ticdc/cdc/processor/pipeline/ProcessorSyncResolvedError=1*return(true);github.com/pingcap/ticdc/cdc/processor/ProcessorUpdatePositionDelaying=sleep(1000)' # new processor
    42      run_cdc_server --workdir $WORK_DIR --binary $CDC_BINARY --logsuffix "2" --addr "127.0.0.1:8302" --pd "http://${UP_PD_HOST_1}:${UP_PD_PORT_1}"
    43      export GO_FAILPOINTS=''
    44  
    45      TOPIC_NAME="ticdc-changefeed-auto-stop-test-$RANDOM"
    46      case $SINK_TYPE in
    47          kafka) SINK_URI="kafka://127.0.0.1:9092/$TOPIC_NAME?partition-num=4&kafka-version=${KAFKA_VERSION}";;
    48          *) SINK_URI="mysql://normal:123456@127.0.0.1:3306/";;
    49      esac
    50      changefeedid=$(cdc cli changefeed create --pd="http://${UP_PD_HOST_1}:${UP_PD_PORT_1}" --start-ts=$start_ts --sink-uri="$SINK_URI" 2>&1|tail -n2|head -n1|awk '{print $2}')
    51      if [ "$SINK_TYPE" == "kafka" ]; then
    52        run_kafka_consumer $WORK_DIR "kafka://127.0.0.1:9092/$TOPIC_NAME?partition-num=4&version=${KAFKA_VERSION}"
    53      fi
    54  
    55      ensure 20 check_changefeed_state  ${UP_PD_HOST_1}:${UP_PD_PORT_1} ${changefeedid} "stopped"
    56  
    57      cdc cli changefeed resume --changefeed-id=${changefeedid} --pd="http://${UP_PD_HOST_1}:${UP_PD_PORT_1}"
    58      for i in $(seq $DB_COUNT); do
    59          check_table_exists "changefeed_auto_stop_$i.USERTABLE" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}
    60      done
    61      check_sync_diff $WORK_DIR $CUR/conf/diff_config.toml
    62  
    63      export GO_FAILPOINTS=''
    64      cleanup_process $CDC_BINARY
    65  }
    66  
    67  trap stop_tidb_cluster EXIT
    68  run $*
    69  check_logs $WORK_DIR
    70  echo "[$(date)] <<<<<< run test case $TEST_NAME success! >>>>>>"