github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/tests/integration_tests/processor_stop_delay/run.sh (about)

     1  #!/bin/bash
     2  
     3  set -eu
     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 run() {
    13  	rm -rf $WORK_DIR && mkdir -p $WORK_DIR
    14  	start_tidb_cluster --workdir $WORK_DIR
    15  	cd $WORK_DIR
    16  
    17  	pd_addr="http://$UP_PD_HOST_1:$UP_PD_PORT_1"
    18  	TOPIC_NAME="ticdc-processor-stop-delay-$RANDOM"
    19  	case $SINK_TYPE in
    20  	kafka) SINK_URI="kafka://127.0.0.1:9092/$TOPIC_NAME?protocol=open-protocol&partition-num=4&kafka-version=${KAFKA_VERSION}&max-message-bytes=10485760" ;;
    21  	storage) SINK_URI="file://$WORK_DIR/storage_test/$TOPIC_NAME?protocol=canal-json&enable-tidb-extension=true" ;;
    22  	pulsar)
    23  		run_pulsar_cluster $WORK_DIR normal
    24  		SINK_URI="pulsar://127.0.0.1:6650/$TOPIC_NAME?protocol=canal-json&enable-tidb-extension=true"
    25  		;;
    26  	*) SINK_URI="mysql://normal:123456@127.0.0.1:3306/?max-txn-row=1" ;;
    27  	esac
    28  	export GO_FAILPOINTS='github.com/pingcap/tiflow/cdc/processor/processorStopDelay=1*sleep(10000)'
    29  
    30  	run_cdc_server --workdir $WORK_DIR --binary $CDC_BINARY --addr "127.0.0.1:8300" --pd $pd_addr
    31  	changefeed_id=$(cdc cli changefeed create --pd=$pd_addr --sink-uri="$SINK_URI" 2>&1 | tail -n2 | head -n1 | awk '{print $2}')
    32  	case $SINK_TYPE in
    33  	kafka) run_kafka_consumer $WORK_DIR "kafka://127.0.0.1:9092/$TOPIC_NAME?protocol=open-protocol&partition-num=4&version=${KAFKA_VERSION}&max-message-bytes=10485760" ;;
    34  	storage) run_storage_consumer $WORK_DIR $SINK_URI "" "" ;;
    35  	pulsar) run_pulsar_consumer --upstream-uri $SINK_URI ;;
    36  	esac
    37  
    38  	run_sql "CREATE DATABASE processor_stop_delay;" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
    39  	run_sql "CREATE table processor_stop_delay.t (id int primary key auto_increment, t datetime DEFAULT CURRENT_TIMESTAMP)" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
    40  	run_sql "INSERT INTO processor_stop_delay.t values (),(),(),(),(),(),()" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
    41  	check_table_exists "processor_stop_delay.t" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}
    42  	check_sync_diff $WORK_DIR $CUR/conf/diff_config.toml
    43  
    44  	# pause changefeed first, and then resume the changefeed. The processor stop
    45  	# logic will be delayed by 10s, which is controlled by failpoint injection.
    46  	# The changefeed should be resumed and no data loss.
    47  	cdc cli changefeed pause --changefeed-id=$changefeed_id --pd=$pd_addr
    48  	sleep 1
    49  	run_sql "INSERT INTO processor_stop_delay.t values (),(),(),(),(),(),()" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
    50  	cdc cli changefeed resume --changefeed-id=$changefeed_id --pd=$pd_addr
    51  	run_sql "INSERT INTO processor_stop_delay.t values (),(),(),(),(),(),()" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
    52  
    53  	check_sync_diff $WORK_DIR $CUR/conf/diff_config.toml
    54  
    55  	export GO_FAILPOINTS=''
    56  	cleanup_process $CDC_BINARY
    57  }
    58  
    59  trap stop_tidb_cluster EXIT
    60  run $*
    61  check_logs $WORK_DIR
    62  echo "[$(date)] <<<<<< run test case $TEST_NAME success! >>>>>>"