github.com/pingcap/ticdc@v0.0.0-20220526033649-485a10ef2652/tests/capture_suicide_while_balance_table/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 12 # This test mainly verifies CDC can handle the following scenario 13 # 1. Two captures, capture-1 is the owner, each capture replicates more than one table. 14 # 2. capture-2 replicates some DMLs but has some delay, such as large amount of 15 # incremental scan data, sink block, etc, we name this slow table as table-slow. 16 # 3. Before capture-2 the checkpoint ts of table-slow reaches global resolved ts, 17 # a rebalance operation is triggered, either by manual rebalance or a new capture 18 # joins the cluster. So a delete table operation will be dispatched to capture-2, 19 # and the boundary ts is global resolved ts. capture-2 will continue to replicate 20 # table-slow until the checkpoint ts reaches the boundary ts. 21 # 4. However, before the checkpoint ts of table-slow reaches boundary ts, capture-2 22 # suicides itself because of some network issue or PD jitter. 23 # 5. After the cluster recovers, the data of table-slow in downstream should be 24 # consistent with upstream. 25 # 26 # In this test, step-2 is achieved by failpoint injection, step-3 is triggered 27 # by manual rebalance, step-4 is achieved by revoking the lease of capture key. 28 function run() { 29 # test with mysql sink only 30 if [ "$SINK_TYPE" != "mysql" ]; then 31 return 32 fi 33 34 rm -rf $WORK_DIR && mkdir -p $WORK_DIR 35 start_tidb_cluster --workdir $WORK_DIR 36 cd $WORK_DIR 37 38 pd_addr="http://$UP_PD_HOST_1:$UP_PD_PORT_1" 39 run_cdc_server --workdir $WORK_DIR --binary $CDC_BINARY --pd $pd_addr --logsuffix 1 --addr "127.0.0.1:8300" 40 export GO_FAILPOINTS='github.com/pingcap/ticdc/cdc/sink/MySQLSinkHangLongTime=1*return(true)' 41 run_cdc_server --workdir $WORK_DIR --binary $CDC_BINARY --pd $pd_addr --logsuffix 2 --addr "127.0.0.1:8301" 42 43 SINK_URI="mysql://normal:123456@127.0.0.1:3306/?max-txn-row=1" 44 changefeed_id=$(cdc cli changefeed create --pd=$pd_addr --sink-uri="$SINK_URI" 2>&1|tail -n2|head -n1|awk '{print $2}') 45 46 run_sql "CREATE DATABASE capture_suicide_while_balance_table;" ${UP_TIDB_HOST} ${UP_TIDB_PORT} 47 for i in $(seq 1 4); do 48 run_sql "CREATE table capture_suicide_while_balance_table.t$i (id int primary key auto_increment)" ${UP_TIDB_HOST} ${UP_TIDB_PORT} 49 done 50 51 for i in $(seq 1 4); do 52 check_table_exists "capture_suicide_while_balance_table.t$i" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT} 53 done 54 55 capture1_id=$(cdc cli capture list|jq -r '.[]|select(.address=="127.0.0.1:8300")|.id') 56 capture2_id=$(cdc cli capture list|jq -r '.[]|select(.address=="127.0.0.1:8301")|.id') 57 one_table_id=$(cdc cli processor query -c $changefeed_id -p $capture2_id|jq -r '.status.tables|keys[0]') 58 table_query=$(mysql -h${UP_TIDB_HOST} -P${UP_TIDB_PORT} -uroot -e "select table_name from information_schema.tables where tidb_table_id = ${one_table_id}\G") 59 table_name=$(echo $table_query|tail -n 1|awk '{print $(NF)}') 60 run_sql "insert into capture_suicide_while_balance_table.${table_name} values (),(),(),(),()" 61 62 # sleep some time to wait global resolved ts forwarded 63 sleep 2 64 curl -X POST http://127.0.0.1:8300/capture/owner/move_table -d "cf-id=${changefeed_id}&target-cp-id=${capture1_id}&table-id=${one_table_id}" 65 # sleep some time to wait table balance job is written to etcd 66 sleep 2 67 68 # revoke lease of etcd capture key to simulate etcd session done 69 lease=$(ETCDCTL_API=3 etcdctl get /tidb/cdc/capture/${capture2_id} -w json|grep -o 'lease":[0-9]*'|awk -F: '{print $2}') 70 lease_hex=$(printf '%x\n' $lease) 71 ETCDCTL_API=3 etcdctl lease revoke $lease_hex 72 73 check_sync_diff $WORK_DIR $CUR/conf/diff_config.toml 74 export GO_FAILPOINTS='' 75 cleanup_process $CDC_BINARY 76 } 77 78 trap stop_tidb_cluster EXIT 79 run $* 80 check_logs $WORK_DIR 81 echo "[$(date)] <<<<<< run test case $TEST_NAME success! >>>>>>"