github.com/pingcap/ticdc@v0.0.0-20220526033649-485a10ef2652/tests/ddl_async/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  SINK_URI="mysql://root@127.0.0.1:3306/"
    12  
    13  function check_ts_forward() {
    14      changefeedid=$1
    15      rts1=$(cdc cli changefeed query --changefeed-id=${changefeedid} 2>&1|jq '.status."resolved-ts"')
    16      checkpoint1=$(cdc cli changefeed query --changefeed-id=${changefeedid} 2>&1|jq '.status."checkpoint-ts"')
    17      sleep 1
    18      rts2=$(cdc cli changefeed query --changefeed-id=${changefeedid} 2>&1|jq '.status."resolved-ts"')
    19      checkpoint2=$(cdc cli changefeed query --changefeed-id=${changefeedid} 2>&1|jq '.status."checkpoint-ts"')
    20      if [[ "$rts1" != "null" ]] && [[ "$rts1" != "0" ]]; then
    21          if [[  "$rts1" -ne "$rts2" ]] || [[ "$checkpoint1" -ne "$checkpoint2" ]]; then
    22              echo "changefeed is working normally rts: ${rts1}->${rts2} checkpoint: ${checkpoint1}->${checkpoint2}"
    23              return
    24          fi
    25      fi
    26      exit 1
    27  }
    28  
    29  function check_ts_block() {
    30      changefeedid=$1
    31      rts1=$(cdc cli changefeed query --changefeed-id=${changefeedid} 2>&1|jq '.status."resolved-ts"')
    32      checkpoint1=$(cdc cli changefeed query --changefeed-id=${changefeedid} 2>&1|jq '.status."checkpoint-ts"')
    33      sleep 1
    34      rts2=$(cdc cli changefeed query --changefeed-id=${changefeedid} 2>&1|jq '.status."resolved-ts"')
    35      checkpoint2=$(cdc cli changefeed query --changefeed-id=${changefeedid} 2>&1|jq '.status."checkpoint-ts"')
    36  
    37      echo "changefeed is blocking rts: ${rts1}->${rts2} checkpoint: ${checkpoint1}->${checkpoint2}"
    38  
    39      if [[ "$rts1" != "null" ]] && [[ "$rts1" != "0" ]]; then
    40          if [[  "$rts1" -eq "$rts2" ]] || [[ "$checkpoint1" -eq "$checkpoint2" ]]; then
    41              echo "changefeed is blocking rts: ${rts1}->${rts2} checkpoint: ${checkpoint1}->${checkpoint2}"
    42              return
    43          fi
    44      fi
    45      exit 1
    46  }
    47  
    48  export -f check_ts_forward
    49  export -f check_ts_block
    50  
    51  function run() {
    52        # don't test kafka in this case
    53      if [ "$SINK_TYPE" == "kafka" ]; then
    54        return
    55      fi
    56  
    57      rm -rf $WORK_DIR && mkdir -p $WORK_DIR
    58  
    59      start_tidb_cluster --workdir $WORK_DIR
    60  
    61      cd $WORK_DIR
    62  
    63      # record tso before we create tables to skip the system table DDLs
    64      start_ts=$(run_cdc_cli tso query --pd=http://$UP_PD_HOST_1:$UP_PD_PORT_1)
    65  
    66      run_sql_file $CUR/data/prepare.sql ${UP_TIDB_HOST} ${UP_TIDB_PORT}
    67  
    68      export GO_FAILPOINTS='github.com/pingcap/ticdc/cdc/InjectChangefeedDDLBlock=1*return(true)'
    69      run_cdc_server --workdir $WORK_DIR --binary $CDC_BINARY
    70      # normal changefeed
    71      run_cdc_cli changefeed create -c="changefeed-ddl-normal" --start-ts=$start_ts --sink-uri="$SINK_URI" --config="$CUR/conf/normal_cf_config.toml"
    72      # ddl blocked changefeed
    73      run_cdc_cli changefeed create -c="changefeed-ddl-block" --start-ts=$start_ts --sink-uri="blackhole://" --config="$CUR/conf/block_cf_config.toml"
    74      # write ddl
    75  
    76      ensure 5 check_ts_forward "changefeed-ddl-normal"
    77      ensure 15 check_ts_block "changefeed-ddl-block"
    78  
    79      check_table_exists ddl_async.finish_mark ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}
    80      check_sync_diff $WORK_DIR $CUR/conf/diff_config.toml
    81  
    82      cleanup_process $CDC_BINARY
    83  }
    84  
    85  trap stop_tidb_cluster EXIT
    86  run $*
    87  check_logs $WORK_DIR
    88  echo "[$(date)] <<<<<< run test case $TEST_NAME success! >>>>>>"