github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/tests/integration_tests/batch_update_to_no_batch/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  
    11  # This integration test is used to test the following scenario:
    12  # 1. cdc works well in batch mode
    13  # 2. cdc works well in no-batch mode
    14  # 3. cdc can switch from batch mode to no-batch mode and vice versa and works well
    15  function run() {
    16  	# batch mode only supports mysql sink
    17  	if [ "$SINK_TYPE" != "mysql" ]; then
    18  		return
    19  	fi
    20  
    21  	rm -rf $WORK_DIR && mkdir -p $WORK_DIR
    22  
    23  	start_tidb_cluster --workdir $WORK_DIR
    24  
    25  	cd $WORK_DIR
    26  
    27  	run_sql "set global tidb_enable_change_multi_schema = on" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
    28  	# This must be set before cdc server starts
    29  	run_sql "set global tidb_enable_change_multi_schema = on" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}
    30  	# TiDB global variables cache 2 seconds at most
    31  	sleep 2
    32  
    33  	run_cdc_server --workdir $WORK_DIR --binary $CDC_BINARY
    34  
    35  	# this test contains `recover table`, which requires super privilege, so we
    36  	# can't use the normal user
    37  	SINK_URI="mysql://root@127.0.0.1:3306/?batch-dml-enable=true"
    38  
    39  	changefeed_id="test"
    40  	run_cdc_cli changefeed create --sink-uri="$SINK_URI" -c ${changefeed_id}
    41  
    42  	run_sql_file $CUR/data/test.sql ${UP_TIDB_HOST} ${UP_TIDB_PORT}
    43  
    44  	# pause changefeed
    45  	run_cdc_cli changefeed pause -c ${changefeed_id}
    46  	# update changefeed to no batch dml mode
    47  	run_cdc_cli changefeed update -c ${changefeed_id} --sink-uri="mysql://root@127.0.0.1:3306/?batch-dml-enable=false" --no-confirm
    48  	# resume changefeed
    49  	run_cdc_cli changefeed resume -c ${changefeed_id}
    50  
    51  	run_sql_file $CUR/data/test_v5.sql ${UP_TIDB_HOST} ${UP_TIDB_PORT}
    52  
    53  	# pause changefeed
    54  	run_cdc_cli changefeed pause -c ${changefeed_id}
    55  	# update changefeed to no batch dml mode
    56  	run_cdc_cli changefeed update -c ${changefeed_id} --sink-uri="mysql://root@127.0.0.1:3306/?batch-dml-enable=true" --no-confirm
    57  	# resume changefeed
    58  	run_cdc_cli changefeed resume -c ${changefeed_id}
    59  
    60  	run_sql_file $CUR/data/test_finish.sql ${UP_TIDB_HOST} ${UP_TIDB_PORT}
    61  
    62  	# sync_diff can't check non-exist table, so we check expected tables are created in downstream first
    63  	check_table_exists batch_update_to_no_batch.v1 ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}
    64  	check_table_exists batch_update_to_no_batch.recover_and_insert ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}
    65  	check_table_exists batch_update_to_no_batch.finish_mark ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}
    66  	check_sync_diff $WORK_DIR $CUR/conf/diff_config.toml
    67  
    68  	cleanup_process $CDC_BINARY
    69  }
    70  
    71  trap stop_tidb_cluster EXIT
    72  run $*
    73  check_logs $WORK_DIR
    74  echo "[$(date)] <<<<<< run test case $TEST_NAME success! >>>>>>"