github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/dm/tests/duplicate_event/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=$TEST_DIR/$TEST_NAME 8 9 function run_with_prepared_source_config() { 10 # 1. test sync fetch binlog met error and reset binlog streamer with remote binlog 11 12 # with a 5 rows insert txn: 1 * FormatDesc + 1 * PreviousGTID + 1 * GTID + 1 * BEGIN + 5 * (Table_map + Write_rows) + 1 * XID 13 # here we fail at the third write rows event, sync should retry and auto recover without any duplicate event 14 export GO_FAILPOINTS="github.com/pingcap/tiflow/dm/syncer/GetEventErrorInTxn=return(3)" 15 16 run_sql_file $cur/data/db1.prepare.sql $MYSQL_HOST1 $MYSQL_PORT1 $MYSQL_PASSWORD1 17 check_contains 'Query OK, 2 rows affected' 18 19 run_dm_master $WORK_DIR/master $MASTER_PORT $cur/conf/dm-master.toml 20 check_rpc_alive $cur/../bin/check_master_online 127.0.0.1:$MASTER_PORT 21 check_metric $MASTER_PORT 'start_leader_counter' 3 0 2 22 run_dm_worker $WORK_DIR/worker1 $WORKER1_PORT $cur/conf/dm-worker1.toml 23 check_rpc_alive $cur/../bin/check_worker_online 127.0.0.1:$WORKER1_PORT 24 25 dmctl_operate_source create $WORK_DIR/source1.yaml $SOURCE_ID1 26 27 run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \ 28 "start-task $cur/conf/dm-task.yaml --remove-meta" 29 check_metric $WORKER1_PORT "dm_worker_task_state{source_id=\"mysql-replica-01\",task=\"test\",worker=\"worker1\"}" 10 1 3 30 31 # wait safe-mode pass 32 check_log_contain_with_retry "disable safe-mode after task initialization finished" $WORK_DIR/worker1/log/dm-worker.log 33 34 run_sql_file $cur/data/db1.increment.sql $MYSQL_HOST1 $MYSQL_PORT1 $MYSQL_PASSWORD1 35 36 check_log_contain_with_retry "reset replication binlog puller" $WORK_DIR/worker1/log/dm-worker.log 37 check_log_contain_with_retry "discard event already consumed" $WORK_DIR/worker1/log/dm-worker.log 38 check_sync_diff $WORK_DIR $cur/conf/diff_config.toml 39 40 # 2. test relay log retry relay with GTID 41 42 # with a 5 rows insert txn: 1 * FormatDesc + 1 * PreviousGTID + 1 * GTID + 1 * BEGIN + 5 * (Table_map + Write_rows) + 1 * XID 43 # here we fail at the third write rows event, sync should retry and auto recover without any duplicate event 44 export GO_FAILPOINTS="github.com/pingcap/tiflow/dm/relay/RelayGetEventFailedAt=return(3);github.com/pingcap/tiflow/dm/relay/RelayAllowRetry=return" 45 46 run_dm_worker $WORK_DIR/worker2 $WORKER2_PORT $cur/conf/dm-worker2.toml 47 check_rpc_alive $cur/../bin/check_worker_online 127.0.0.1:$WORKER2_PORT 48 49 dmctl_operate_source create $WORK_DIR/source2.yaml $SOURCE_ID2 50 51 run_sql_file $cur/data/db1.prepare.sql $MYSQL_HOST2 $MYSQL_PORT2 $MYSQL_PASSWORD2 52 check_contains 'Query OK, 2 rows affected' 53 54 run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \ 55 "start-task $cur/conf/dm-task-relay.yaml --remove-meta" 56 check_metric $WORKER2_PORT "dm_worker_task_state{source_id=\"mysql-replica-02\",task=\"test_relay\",worker=\"worker2\"}" 10 1 3 57 58 check_sync_diff $WORK_DIR $cur/conf/diff_relay_config.toml 59 60 run_sql_source2 "flush logs;" 61 run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \ 62 "start-relay -s $SOURCE_ID2 worker2" \ 63 "\"result\": true" 2 64 run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \ 65 "query-status -s $SOURCE_ID2" \ 66 "\"relayCatchUpMaster\": true" 1 67 68 run_sql_file $cur/data/db1.increment.sql $MYSQL_HOST2 $MYSQL_PORT2 $MYSQL_PASSWORD2 69 70 check_sync_diff $WORK_DIR $cur/conf/diff_relay_config.toml 71 72 # check relay log binlog file size is the same as master size 73 run_sql_source2 "show master status;" 74 binlog_file=$(grep "File" $TEST_DIR/sql_res.$TEST_NAME.txt | awk -F: '{print $2}' | xargs) 75 binlog_pos=$(grep "Position" $TEST_DIR/sql_res.$TEST_NAME.txt | awk -F: '{print $2}' | xargs) 76 server_uuid=$(tail -n 1 $WORK_DIR/worker2/relay-dir/server-uuid.index) 77 78 succ=0 79 for ((k = 1; k < 6; k++)); do 80 relay_log_size=$(ls -al $WORK_DIR/worker2/relay-dir/$server_uuid/$binlog_file | awk '{print $5}') 81 echo "binlog_pos: $binlog_pos relay_log_size: $relay_log_size" 82 if [[ "$binlog_pos" -eq "$relay_log_size" ]]; then 83 succ=1 84 break 85 fi 86 sleep 1 87 done 88 if [[ $succ -eq 0 ]]; then 89 echo "binlog_pos is not equal to relay_log_size" 90 exit 1 91 fi 92 93 echo "============== run_with_prepared_source_config success ===================" 94 } 95 96 function run() { 97 # test source enable gtid 98 cp $cur/conf/source1.yaml $WORK_DIR/source1.yaml 99 cp $cur/conf/source2.yaml $WORK_DIR/source2.yaml 100 101 run_with_prepared_source_config 102 103 cleanup_process $* 104 cleanup_data dup_event1 dup_event_relay 105 106 # test source disable gtid 107 cp $cur/conf/source1.yaml $WORK_DIR/source1.yaml 108 cp $cur/conf/source2.yaml $WORK_DIR/source2.yaml 109 sed -i "s/enable-gtid: true/enable-gtid: false/g" $WORK_DIR/source1.yaml 110 sed -i "s/enable-gtid: true/enable-gtid: false/g" $WORK_DIR/source2.yaml 111 112 run_with_prepared_source_config 113 } 114 115 # also cleanup dm processes in case of last run failed 116 cleanup_process $* 117 cleanup_data dup_event1 dup_event_relay 118 run 119 cleanup_process $* 120 121 echo "[$(date)] <<<<<< test case $TEST_NAME success! >>>>>>"