github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/tests/integration_tests/mq_sink_dispatcher/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  MAX_RETRIES=10
    11  
    12  # use kafka-consumer with canal-json decoder to sync data from kafka to mysql
    13  function run() {
    14  	if [ "$SINK_TYPE" != "kafka" ]; then
    15  		return
    16  	fi
    17  
    18  	rm -rf $WORK_DIR && mkdir -p $WORK_DIR
    19  
    20  	start_tidb_cluster --workdir $WORK_DIR
    21  
    22  	cd $WORK_DIR
    23  
    24  	TOPIC_NAME="dispatcher-test"
    25  
    26  	run_cdc_server --workdir $WORK_DIR --binary $CDC_BINARY --loglevel "info"
    27  
    28  	changefeed_id="test"
    29  
    30  	# create a table before get pd tso to reproduce https://github.com/pingcap/tiflow/issues/10707
    31  	run_sql "DROP DATABASE if exists verify;" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
    32  	run_sql "CREATE DATABASE verify;" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
    33  	run_sql "CREATE TABLE verify.t (a int primary key, b int);" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
    34  
    35  	# record tso before we create tables to skip the system table DDLs
    36  	start_ts=$(run_cdc_cli_tso_query ${UP_PD_HOST_1} ${UP_PD_PORT_1})
    37  	SINK_URI="kafka://127.0.0.1:9092/$TOPIC_NAME?protocol=canal-json&enable-tidb-extension=true"
    38  	run_cdc_cli changefeed create --start-ts=$start_ts --sink-uri="$SINK_URI" -c ${changefeed_id} --config="$CUR/conf/changefeed.toml"
    39  
    40  	ensure $MAX_RETRIES check_changefeed_state http://${UP_PD_HOST_1}:${UP_PD_PORT_1} $changefeed_id "normal" "null" ""
    41  
    42  	run_sql "DROP DATABASE if exists dispatcher;" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
    43  	run_sql "CREATE DATABASE dispatcher;" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
    44  	run_sql "CREATE TABLE dispatcher.index (a int primary key, b int);" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
    45  
    46  	run_sql "INSERT INTO dispatcher.index values (1, 2);" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
    47  
    48  	ensure $MAX_RETRIES check_changefeed_state http://${UP_PD_HOST_1}:${UP_PD_PORT_1} $changefeed_id "failed" "ErrDispatcherFailed"
    49  
    50  	run_cdc_cli changefeed update -c ${changefeed_id} --sink-uri="$SINK_URI" --config="$CUR/conf/new_changefeed.toml" --no-confirm
    51  
    52  	run_cdc_cli changefeed resume -c ${changefeed_id}
    53  
    54  	ensure $MAX_RETRIES check_changefeed_state http://${UP_PD_HOST_1}:${UP_PD_PORT_1} $changefeed_id "normal" "null" ""
    55  
    56  	cdc_kafka_consumer --upstream-uri $SINK_URI --downstream-uri="mysql://root@127.0.0.1:3306/?safe-mode=true&batch-dml-enable=false" --upstream-tidb-dsn="root@tcp(${UP_TIDB_HOST}:${UP_TIDB_PORT})/?" --config="$CUR/conf/new_changefeed.toml" 2>&1 &
    57  
    58  	run_sql "INSERT INTO dispatcher.index values (2, 3);" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
    59  	run_sql "INSERT INTO dispatcher.index values (3, 4);" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
    60  	run_sql "INSERT INTO dispatcher.index values (4, 5);" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
    61  	run_sql "UPDATE dispatcher.index set b = 5 where a = 1;" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
    62  	run_sql "UPDATE dispatcher.index set b = 6 where a = 2;" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
    63  	run_sql "DELETE FROM dispatcher.index where a = 3;" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
    64  
    65  	run_sql "CREATE TABLE test.finish_mark (a int primary key);" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
    66  
    67  	# sync_diff can't check non-exist table, so we check expected tables are created in downstream first
    68  	check_table_exists test.finish_mark ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT} 200
    69  	check_sync_diff $WORK_DIR $CUR/conf/diff_config.toml
    70  
    71  	cleanup_process $CDC_BINARY
    72  }
    73  
    74  trap stop_tidb_cluster EXIT
    75  run $*
    76  check_logs $WORK_DIR
    77  echo "[$(date)] <<<<<< run test case $TEST_NAME success! >>>>>>"