github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/tests/integration_tests/kill_owner_with_ddl/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  MAX_RETRIES=10
    12  
    13  function check_capture_count() {
    14  	pd=$1
    15  	expected=$2
    16  	count=$(cdc cli capture list --pd=$pd 2>&1 | jq '.|length')
    17  	if [[ ! "$count" -eq "$expected" ]]; then
    18  		echo "count: $count expected: $expected"
    19  		exit 1
    20  	fi
    21  }
    22  
    23  function kill_cdc_and_restart() {
    24  	pd_addr=$1
    25  	work_dir=$2
    26  	cdc_binary=$3
    27  	MAX_RETRIES=10
    28  	status=$(curl -s http://127.0.0.1:8300/status)
    29  	cdc_pid=$(echo "$status" | jq '.pid')
    30  
    31  	kill_cdc_pid $cdc_pid
    32  	ensure $MAX_RETRIES check_capture_count $pd_addr 0
    33  	run_cdc_server --workdir $work_dir --binary $cdc_binary --addr "127.0.0.1:8300" --pd $pd_addr
    34  	ensure $MAX_RETRIES check_capture_count $pd_addr 1
    35  }
    36  
    37  export -f check_capture_count
    38  export -f kill_cdc_and_restart
    39  
    40  function run() {
    41  	# kafka is not supported yet.
    42  	if [ "$SINK_TYPE" != "mysql" ]; then
    43  		return
    44  	fi
    45  
    46  	rm -rf $WORK_DIR && mkdir -p $WORK_DIR
    47  	start_tidb_cluster --workdir $WORK_DIR
    48  	cd $WORK_DIR
    49  
    50  	pd_addr="http://$UP_PD_HOST_1:$UP_PD_PORT_1"
    51  	SINK_URI="mysql://normal:123456@127.0.0.1:3306/?max-txn-row=1"
    52  
    53  	run_cdc_server --workdir $WORK_DIR --binary $CDC_BINARY --addr "127.0.0.1:8300" --pd $pd_addr
    54  	cdc cli changefeed create --pd=$pd_addr --sink-uri="$SINK_URI"
    55  	run_sql "CREATE DATABASE kill_owner_with_ddl;" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
    56  	run_sql "CREATE table kill_owner_with_ddl.t1 (id int primary key auto_increment, val int);" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
    57  	check_table_exists "kill_owner_with_ddl.t1" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}
    58  
    59  	export GO_FAILPOINTS='github.com/pingcap/tiflow/cdc/sink/ddlsink/mysql/MySQLSinkExecDDLDelay=return(true);github.com/pingcap/tiflow/cdc/capture/ownerFlushIntervalInject=return(10)'
    60  	kill_cdc_and_restart $pd_addr $WORK_DIR $CDC_BINARY
    61  
    62  	for i in $(seq 2 3); do
    63  		run_sql "CREATE table kill_owner_with_ddl.t$i (id int primary key auto_increment, val int);" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
    64  	done
    65  	for i in $(seq 1 3); do
    66  		run_sql "INSERT INTO kill_owner_with_ddl.t$i VALUES (),(),();" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
    67  	done
    68  
    69  	# sleep to ensure processor has consumed the DDL and flushed checkpoint
    70  	sleep 5
    71  
    72  	for i in $(seq 1 3); do
    73  		kill_cdc_and_restart $pd_addr $WORK_DIR $CDC_BINARY
    74  		sleep 8
    75  	done
    76  
    77  	export GO_FAILPOINTS=''
    78  	kill_cdc_and_restart $pd_addr $WORK_DIR $CDC_BINARY
    79  
    80  	for i in $(seq 1 3); do
    81  		check_table_exists "kill_owner_with_ddl.t$i" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}
    82  	done
    83  	check_sync_diff $WORK_DIR $CUR/conf/diff_config.toml
    84  
    85  	cleanup_process $CDC_BINARY
    86  }
    87  
    88  trap stop_tidb_cluster EXIT
    89  run $*
    90  check_logs $WORK_DIR
    91  echo "[$(date)] <<<<<< run test case $TEST_NAME success! >>>>>>"