github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/dm/tests/_utils/shardddl_lib.sh (about) 1 #!/bin/bash 2 3 set -eu 4 5 shardddl="shardddl" 6 shardddl1="shardddl1" 7 shardddl2="shardddl2" 8 tb1="tb1" 9 tb2="tb2" 10 tb3="tb3" 11 tb4="tb4" 12 tb="tb" 13 t_1="t_1" 14 15 function init_database() { 16 run_sql_both_source "drop database if exists ${shardddl1};" 17 run_sql_both_source "drop database if exists ${shardddl2};" 18 run_sql_both_source "create database if not exists ${shardddl1};" 19 run_sql_both_source "create database if not exists ${shardddl2};" 20 } 21 22 function extract() { 23 str="$1" 24 source=${str:0:1} 25 database=${str:1:1} 26 table=${str:2:1} 27 } 28 29 function init_table() { 30 for i in $@; do 31 extract $i 32 run_sql_source${source} "create table shardddl${database}.tb${table} (id int primary key);" 33 done 34 } 35 36 function clean_table() { 37 run_sql_both_source "drop table if exists ${shardddl1}.${tb1};" 38 run_sql_both_source "drop table if exists ${shardddl1}.${tb2};" 39 run_sql_both_source "drop table if exists ${shardddl1}.${tb3};" 40 run_sql_both_source "drop table if exists ${shardddl1}.${tb4};" 41 run_sql_both_source "drop table if exists ${shardddl2}.${tb1};" 42 run_sql_both_source "drop table if exists ${shardddl2}.${tb2};" 43 run_sql_both_source "drop table if exists ${shardddl2}.${tb3};" 44 run_sql_both_source "drop table if exists ${shardddl2}.${tb4};" 45 run_sql_both_source "drop table if exists ${shardddl1}.${t_1};" 46 run_sql_both_source "drop table if exists ${shardddl2}.${t_1};" 47 run_sql_tidb "drop table if exists ${shardddl}.${tb};" 48 run_sql_tidb "drop database if exists dm_meta;" 49 run_sql_tidb "drop table if exists ${shardddl}.${t_1};" 50 } 51 52 function restart_master() { 53 echo "restart dm-master" 54 kill_process dm-master 55 check_master_port_offline 1 56 sleep 2 57 58 run_dm_master $WORK_DIR/master $MASTER_PORT $cur/conf/dm-master.toml 59 check_rpc_alive $cur/../bin/check_master_online 127.0.0.1:$MASTER_PORT 60 } 61 62 function restart_worker1() { 63 echo "restart dm-worker1" 64 kill_process worker1 65 check_process_exit worker1 20 66 run_dm_worker $WORK_DIR/worker1 $WORKER1_PORT $cur/conf/dm-worker1.toml 67 check_rpc_alive $cur/../bin/check_worker_online 127.0.0.1:$WORKER1_PORT 68 } 69 70 function restart_worker2() { 71 echo "restart dm-worker2" 72 kill_process worker2 73 check_process_exit worker2 20 74 run_dm_worker $WORK_DIR/worker2 $WORKER2_PORT $cur/conf/dm-worker2.toml 75 check_rpc_alive $cur/../bin/check_worker_online 127.0.0.1:$WORKER2_PORT 76 } 77 78 function restart_task() { 79 echo "restart task" 80 81 run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \ 82 "stop-task test" 83 84 run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \ 85 "start-task $1" 86 87 if [[ "$task_conf" == *"single"* ]]; then 88 run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \ 89 "query-status test" \ 90 "\"unit\": \"Sync\"" 1 91 elif [[ "$task_conf" == *"double"* ]]; then 92 run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \ 93 "query-status test" \ 94 "\"unit\": \"Sync\"" 2 95 fi 96 } 97 98 function random_restart() { 99 modN=4 100 if [ $# -ge 1 ]; then 101 modN=$1 102 fi 103 mod=$(($RANDOM % $modN)) 104 if [[ "$mod" == "0" ]]; then 105 echo "restart master" 106 restart_master 107 elif [[ "$mod" == "1" ]]; then 108 echo "restart worker1" 109 restart_worker1 110 elif [[ "$mod" == "2" ]]; then 111 echo "restart worker2" 112 restart_worker2 113 else 114 echo "restart task" 115 restart_task $cur/conf/double-source-optimistic.yaml 116 fi 117 }