github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/dm/tests/ha_cases3_1/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 API_VERSION="v1alpha1" 9 # import helper functions 10 source $cur/../_utils/ha_cases_lib.sh 11 12 function test_multi_task_running() { 13 echo "[$(date)] <<<<<< start test_multi_task_running >>>>>>" 14 cleanup 15 prepare_sql_multi_task 16 start_multi_tasks_cluster 17 18 # make sure task to step in "Sync" stage 19 run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT3" \ 20 "query-status test" \ 21 "\"stage\": \"Running\"" 4 \ 22 "\"unit\": \"Sync\"" 2 23 run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT3" \ 24 "query-status test2" \ 25 "\"stage\": \"Running\"" 4 \ 26 "\"unit\": \"Sync\"" 2 27 28 echo "use sync_diff_inspector to check full dump loader" 29 check_sync_diff $WORK_DIR $cur/conf/diff_config.toml 30 check_sync_diff $WORK_DIR $cur/conf/diff_config_multi_task.toml 31 32 echo "flush logs to force rotate binlog file" 33 run_sql "flush logs;" $MYSQL_PORT1 $MYSQL_PASSWORD1 34 run_sql "flush logs;" $MYSQL_PORT2 $MYSQL_PASSWORD2 35 36 echo "apply increment data before restart dm-worker to ensure entering increment phase" 37 run_sql_file_withdb $cur/data/db1.increment.sql $MYSQL_HOST1 $MYSQL_PORT1 $MYSQL_PASSWORD1 $ha_test 38 run_sql_file_withdb $cur/data/db2.increment.sql $MYSQL_HOST2 $MYSQL_PORT2 $MYSQL_PASSWORD2 $ha_test 39 run_sql_file_withdb $cur/data/db1.increment.sql $MYSQL_HOST1 $MYSQL_PORT1 $MYSQL_PASSWORD1 $ha_test2 40 run_sql_file_withdb $cur/data/db2.increment.sql $MYSQL_HOST2 $MYSQL_PORT2 $MYSQL_PASSWORD2 $ha_test2 41 42 sleep 5 # wait for flush checkpoint 43 echo "use sync_diff_inspector to check increment data" 44 check_sync_diff $WORK_DIR $cur/conf/diff_config.toml 50 || print_debug_status 45 check_sync_diff $WORK_DIR $cur/conf/diff_config_multi_task.toml 50 || print_debug_status 46 echo "[$(date)] <<<<<< finish test_multi_task_running >>>>>>" 47 } 48 49 function test_isolate_master_and_worker() { 50 echo "[$(date)] <<<<<< start test_isolate_master_and_worker >>>>>>" 51 52 test_multi_task_running 53 54 # join master4 and master5 55 run_dm_master $WORK_DIR/master-join4 $MASTER_PORT4 $cur/conf/dm-master-join4.toml 56 check_rpc_alive $cur/../bin/check_master_online 127.0.0.1:$MASTER_PORT4 57 sleep 5 58 run_dm_master $WORK_DIR/master-join5 $MASTER_PORT5 $cur/conf/dm-master-join5.toml 59 check_rpc_alive $cur/../bin/check_master_online 127.0.0.1:$MASTER_PORT5 60 sleep 5 61 62 master_ports=($MASTER_PORT1 $MASTER_PORT2 $MASTER_PORT3 $MASTER_PORT4 $MASTER_PORT5) 63 alive=(1 2 3 4 5) 64 65 leader=($(get_leader $WORK_DIR 127.0.0.1:${master_ports[${alive[0]} - 1]})) 66 leader_idx=${leader:6} 67 echo "try to isolate leader dm-master$leader_idx" 68 isolate_master $leader_idx "isolate" 69 for idx in "${!alive[@]}"; do 70 if [[ ${alive[idx]} = $leader_idx ]]; then 71 unset 'alive[idx]' 72 fi 73 done 74 alive=("${alive[@]}") 75 76 new_leader=($(get_leader $WORK_DIR 127.0.0.1:${master_ports[${alive[0]} - 1]})) 77 new_leader_idx=${new_leader:6} 78 new_leader_port=${master_ports[$new_leader_idx - 1]} 79 follower_idx=${alive[0]} 80 if [[ $follower_idx = $new_leader_idx ]]; then 81 follower_idx=${alive[1]} 82 fi 83 84 echo "try to isolate follower dm-master$follower_idx" 85 isolate_master $follower_idx "isolate" 86 for idx in "${!alive[@]}"; do 87 if [[ ${alive[idx]} = $follower_idx ]]; then 88 unset 'alive[idx]' 89 fi 90 done 91 alive=("${alive[@]}") 92 93 # find which worker is in use 94 task_name=(test test2) 95 worker_inuse=("") # such as ("worker1" "worker4") 96 status=$($PWD/bin/dmctl.test DEVEL --master-addr "127.0.0.1:$new_leader_port" query-status test | 97 grep 'worker' | awk -F: '{print $2}') 98 echo $status 99 for w in ${status[@]}; do 100 worker_inuse=(${worker_inuse[*]} ${w:0-9:7}) 101 echo "find workers: ${w:0-9:7} for task: test" 102 done 103 echo "find all workers: ${worker_inuse[@]} (total: ${#worker_inuse[@]})" 104 105 for ((i = 0; i < ${#worker_inuse[@]}; i++)); do 106 wk=${worker_inuse[$i]:0-1:1} # get worker id, such as ("1", "4") 107 echo "try to isolate dm-worker$wk" 108 isolate_worker $wk "isolate" 109 done 110 111 run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$new_leader_port" \ 112 "pause-task test" \ 113 "\"result\": true" 3 114 115 run_sql "DROP TABLE if exists $ha_test.ta;" $TIDB_PORT $TIDB_PASSWORD 116 run_sql "DROP TABLE if exists $ha_test.tb;" $TIDB_PORT $TIDB_PASSWORD 117 load_data $MYSQL_PORT1 $MYSQL_PASSWORD1 "a" & 118 load_data $MYSQL_PORT2 $MYSQL_PASSWORD2 "b" & 119 120 run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$new_leader_port" \ 121 "resume-task test" \ 122 "\"result\": true" 3 # wait for load data wait 123 wait 124 sleep 3 125 126 echo "use sync_diff_inspector to check increment data" 127 check_sync_diff $WORK_DIR $cur/conf/diff_config.toml 128 129 echo "[$(date)] <<<<<< finish test_isolate_master_and_worker >>>>>>" 130 } 131 132 function run() { 133 test_isolate_master_and_worker # TICASE-934, 935, 936, 987, 992, 998, 999 134 } 135 136 cleanup_data $ha_test 137 cleanup_data $ha_test2 138 # also cleanup dm processes in case of last run failed 139 cleanup_process $* 140 run $* 141 cleanup_process $* 142 143 echo "[$(date)] <<<<<< test case $TEST_NAME success! >>>>>>"