github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/dm/tests/initial_unit/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 8 WORK_DIR=$TEST_DIR/$TEST_NAME 9 10 function prepare_data() { 11 run_sql 'DROP DATABASE if exists initial_unit;' $MYSQL_PORT1 $MYSQL_PASSWORD1 12 run_sql 'CREATE DATABASE initial_unit;' $MYSQL_PORT1 $MYSQL_PASSWORD1 13 run_sql "CREATE TABLE initial_unit.t$1(i TINYINT, j INT UNIQUE KEY);" $MYSQL_PORT1 $MYSQL_PASSWORD1 14 for j in $(seq 100); do 15 run_sql "INSERT INTO initial_unit.t$1 VALUES ($j,${j}000$j),($j,${j}001$j);" $MYSQL_PORT1 $MYSQL_PASSWORD1 16 done 17 } 18 19 function run() { 20 failpoints=( 21 # 1152 is ErrAbortingConnection 22 "github.com/pingcap/tiflow/dm/syncer/LoadCheckpointFailed=return(1152)" 23 "github.com/pingcap/tiflow/dm/syncer/dbconn/GetMasterStatusFailed=return(1152)" 24 ) 25 26 for ((i = 0; i < ${#failpoints[@]}; i++)); do 27 WORK_DIR=$TEST_DIR/$TEST_NAME/$i 28 29 # clear downstream env 30 run_sql 'DROP DATABASE if exists dm_meta;' $TIDB_PORT $TIDB_PASSWORD 31 run_sql 'DROP DATABASE if exists initial_unit;' $TIDB_PORT $TIDB_PASSWORD 32 prepare_data $i 33 34 echo "failpoint=${failpoints[i]}" 35 export GO_FAILPOINTS=${failpoints[i]} 36 37 run_dm_master $WORK_DIR/master $MASTER_PORT $cur/conf/dm-master.toml 38 check_rpc_alive $cur/../bin/check_master_online 127.0.0.1:$MASTER_PORT 39 run_dm_worker $WORK_DIR/worker1 $WORKER1_PORT $cur/conf/dm-worker1.toml 40 check_rpc_alive $cur/../bin/check_worker_online 127.0.0.1:$WORKER1_PORT 41 # operate mysql config to worker 42 cp $cur/conf/source1.yaml $WORK_DIR/source1.yaml 43 sed -i "/relay-binlog-name/i\relay-dir: $WORK_DIR/worker1/relay_log" $WORK_DIR/source1.yaml 44 dmctl_operate_source create $WORK_DIR/source1.yaml $SOURCE_ID1 45 46 echo "start task and query status, the sync unit will initial failed" 47 task_conf="$cur/conf/dm-task.yaml" 48 run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \ 49 "start-task $task_conf" \ 50 "\"result\": true" 1 \ 51 "\"source\": \"$SOURCE_ID1\"" 1 \ 52 "fail to initialize unit Sync of subtask test" 1 53 54 sleep 2 55 run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \ 56 "query-status test" \ 57 "\"stage\": \"Paused\"" 1 \ 58 "\"unit\": \"InvalidUnit\"" 1 \ 59 "fail to initialize unit Sync of subtask test" 1 60 61 echo "resume task will also initial failed" 62 run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \ 63 "resume-task test" \ 64 "\"result\": true" 1 \ 65 "\"source\": \"$SOURCE_ID1\"" 1 \ 66 "fail to initialize unit Sync of subtask test" 1 67 68 sleep 2 69 run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \ 70 "query-status test" \ 71 "\"stage\": \"Paused\"" 1 \ 72 "\"unit\": \"InvalidUnit\"" 1 \ 73 "fail to initialize unit Sync of subtask test" 1 74 75 echo "reset go failpoints, and need restart dm-worker" 76 echo "then resume task, task will recover success" 77 export GO_FAILPOINTS='' 78 79 kill_dm_worker 80 81 run_dm_worker $WORK_DIR/worker1 $WORKER1_PORT $cur/conf/dm-worker1.toml 82 check_rpc_alive $cur/../bin/check_worker_online 127.0.0.1:$WORKER1_PORT 83 sleep 10 84 85 echo "start task after restarted dm-worker, the sync unit will initial success" 86 task_conf="$cur/conf/dm-task.yaml" 87 run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \ 88 "start-task $task_conf" \ 89 "\"result\": false" 1 \ 90 "subtasks with name test for sources \[mysql-replica-01\] already exist" 1 91 check_sync_diff $WORK_DIR $cur/conf/diff_config.toml 92 93 # resume-task takes no effect 94 run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \ 95 "resume-task test" \ 96 "\"result\": true" 2 \ 97 "\"source\": \"$SOURCE_ID1\"" 1 98 99 run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \ 100 "query-status test" \ 101 "\"stage\": \"Running\"" 2 102 103 cleanup_process 104 done 105 } 106 107 cleanup_data initial_unit 108 cleanup_process 109 110 run $* 111 112 cleanup_process 113 114 echo "[$(date)] <<<<<< test case $TEST_NAME success! >>>>>>"