github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/dm/tests/full_mode/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 fail_acquire_global_lock() { 10 export GO_FAILPOINTS="github.com/pingcap/tiflow/dm/worker/TaskCheckInterval=return(\"500ms\")" 11 12 run_sql_file $cur/data/db1.prepare.sql $MYSQL_HOST1 $MYSQL_PORT1 $MYSQL_PASSWORD1 13 check_contains 'Query OK, 2 rows affected' 14 run_sql_file $cur/data/db2.prepare.sql $MYSQL_HOST2 $MYSQL_PORT2 $MYSQL_PASSWORD2 15 check_contains 'Query OK, 3 rows affected' 16 17 cp $cur/data/db1.prepare.user.sql $WORK_DIR/db1.prepare.user.sql 18 sed -i "/revoke create temporary/i\revoke reload on *.* from 'dm_full'@'%';" $WORK_DIR/db1.prepare.user.sql 19 run_sql_file $WORK_DIR/db1.prepare.user.sql $MYSQL_HOST1 $MYSQL_PORT1 $MYSQL_PASSWORD1 20 check_count 'Query OK, 0 rows affected' 8 21 cp $cur/data/db2.prepare.user.sql $WORK_DIR/db2.prepare.user.sql 22 sed -i "/revoke create temporary/i\revoke reload on *.* from 'dm_full'@'%';" $WORK_DIR/db2.prepare.user.sql 23 run_sql_file $WORK_DIR/db2.prepare.user.sql $MYSQL_HOST2 $MYSQL_PORT2 $MYSQL_PASSWORD2 24 check_count 'Query OK, 0 rows affected' 11 25 26 run_dm_master $WORK_DIR/master $MASTER_PORT $cur/conf/dm-master.toml 27 check_rpc_alive $cur/../bin/check_master_online 127.0.0.1:$MASTER_PORT 28 run_dm_worker $WORK_DIR/worker1 $WORKER1_PORT $cur/conf/dm-worker1.toml 29 check_rpc_alive $cur/../bin/check_worker_online 127.0.0.1:$WORKER1_PORT 30 cp $cur/conf/source1.yaml $WORK_DIR/source1.yaml 31 cp $cur/conf/source2.yaml $WORK_DIR/source2.yaml 32 sed -i "/relay-binlog-name/i\relay-dir: $WORK_DIR/worker1/relay_log" $WORK_DIR/source1.yaml 33 sed -i "/relay-binlog-name/i\relay-dir: $WORK_DIR/worker2/relay_log" $WORK_DIR/source2.yaml 34 dmctl_operate_source create $WORK_DIR/source1.yaml $SOURCE_ID1 35 36 run_dm_worker $WORK_DIR/worker2 $WORKER2_PORT $cur/conf/dm-worker2.toml 37 check_rpc_alive $cur/../bin/check_worker_online 127.0.0.1:$WORKER2_PORT 38 dmctl_operate_source create $WORK_DIR/source2.yaml $SOURCE_ID2 39 40 cp $cur/conf/dm-task.yaml $WORK_DIR/dm-task.yaml 41 sed -i '/heartbeat-report-interval/i\ignore-checking-items: ["dump_privilege"]' $WORK_DIR/dm-task.yaml 42 run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \ 43 "start-task $WORK_DIR/dm-task.yaml --remove-meta" 44 45 # TaskCheckInterval set to 500ms 46 sleep 1 47 48 check_log_contains $WORK_DIR/worker1/log/dm-worker.log "you need (at least one of) the RELOAD privilege(s) for this operation" 49 check_log_contains $WORK_DIR/worker1/log/dm-worker.log "error is not resumable" 50 check_log_contains $WORK_DIR/worker2/log/dm-worker.log "you need (at least one of) the RELOAD privilege(s) for this operation" 51 check_log_contains $WORK_DIR/worker2/log/dm-worker.log "error is not resumable" 52 53 run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \ 54 "query-status test" \ 55 "\"stage\": \"Paused\"" 2 \ 56 "LOCK TABLES \`full_mode\`.\`t1\` READ: Error 1044 (42000): Access denied" 1 \ 57 "LOCK TABLES \`full_mode\`.\`t2\` READ: Error 1044 (42000): Access denied" 1 58 59 cleanup_process $* 60 cleanup_data full_mode 61 } 62 63 function escape_schema() { 64 cp $cur/data/db1.prepare.sql $WORK_DIR/db1.prepare.sql 65 cp $cur/data/db2.prepare.sql $WORK_DIR/db2.prepare.sql 66 cp $cur/conf/dm-task.yaml $WORK_DIR/dm-task.yaml 67 cp $cur/conf/diff_config.toml $WORK_DIR/diff_config.toml 68 sed -i "s/full_mode/full\\\\\\\\\/mode/g" $WORK_DIR/diff_config.toml 69 sed -i "s/full_mode/full\/mode/g" $WORK_DIR/db1.prepare.sql $WORK_DIR/db2.prepare.sql $WORK_DIR/dm-task.yaml 70 71 run_sql_file $WORK_DIR/db1.prepare.sql $MYSQL_HOST1 $MYSQL_PORT1 $MYSQL_PASSWORD1 72 check_contains 'Query OK, 2 rows affected' 73 run_sql_file $WORK_DIR/db2.prepare.sql $MYSQL_HOST2 $MYSQL_PORT2 $MYSQL_PASSWORD2 74 check_contains 'Query OK, 3 rows affected' 75 76 # test load data with `/` in the table name 77 run_sql_source1 "create table \`full/mode\`.\`tb\/1\` (id int, name varchar(10), primary key(\`id\`));" 78 run_sql_source1 "insert into \`full/mode\`.\`tb\/1\` values(1,'haha');" 79 run_sql_source1 "insert into \`full/mode\`.\`tb\/1\` values(2,'hihi');" 80 81 run_sql_file $cur/data/db1.prepare.user.sql $MYSQL_HOST1 $MYSQL_PORT1 $MYSQL_PASSWORD1 82 check_count 'Query OK, 0 rows affected' 7 83 run_sql_file $cur/data/db2.prepare.user.sql $MYSQL_HOST2 $MYSQL_PORT2 $MYSQL_PASSWORD2 84 check_count 'Query OK, 0 rows affected' 10 85 86 export GO_FAILPOINTS='github.com/pingcap/tiflow/dm/dumpling/SleepBeforeDumplingClose=return(3)' 87 88 run_dm_master $WORK_DIR/master $MASTER_PORT $cur/conf/dm-master.toml 89 check_rpc_alive $cur/../bin/check_master_online 127.0.0.1:$MASTER_PORT 90 run_dm_worker $WORK_DIR/worker1 $WORKER1_PORT $cur/conf/dm-worker1.toml 91 check_rpc_alive $cur/../bin/check_worker_online 127.0.0.1:$WORKER1_PORT 92 run_dm_worker $WORK_DIR/worker2 $WORKER2_PORT $cur/conf/dm-worker2.toml 93 check_rpc_alive $cur/../bin/check_worker_online 127.0.0.1:$WORKER2_PORT 94 # operate mysql config to worker 95 cp $cur/conf/source1.yaml $WORK_DIR/source1.yaml 96 cp $cur/conf/source2.yaml $WORK_DIR/source2.yaml 97 sed -i "/relay-binlog-name/i\relay-dir: $WORK_DIR/worker1/relay_log" $WORK_DIR/source1.yaml 98 sed -i "/relay-binlog-name/i\relay-dir: $WORK_DIR/worker2/relay_log" $WORK_DIR/source2.yaml 99 dmctl_operate_source create $WORK_DIR/source1.yaml $SOURCE_ID1 100 dmctl_operate_source create $WORK_DIR/source2.yaml $SOURCE_ID2 101 102 # start DM task only 103 dmctl_start_task "$WORK_DIR/dm-task.yaml" "--remove-meta" 104 check_metric $WORKER1_PORT 'dumpling_dump_finished_tables' 3 0 3 105 check_sync_diff $WORK_DIR $WORK_DIR/diff_config.toml 106 107 check_log_contain_with_retry 'clean dump files' $WORK_DIR/worker1/log/dm-worker.log 108 check_log_contain_with_retry 'clean dump files' $WORK_DIR/worker2/log/dm-worker.log 109 110 echo "check dump files have been cleaned" 111 ls $WORK_DIR/worker1/dumped_data.test && exit 1 || echo "worker1 auto removed dump files" 112 ls $WORK_DIR/worker2/dumped_data.test && exit 1 || echo "worker2 auto removed dump files" 113 export GO_FAILPOINTS='' 114 115 cleanup_process $* 116 cleanup_data full/mode 117 } 118 119 function empty_data() { 120 run_sql_both_source "drop database if exists full_mode;" 121 run_sql_both_source "create database full_mode;" 122 run_sql_source1 "create table full_mode.t1 (id int, name varchar(20), primary key(id));" 123 run_sql_source2 "create table full_mode.t2 (id int, name varchar(20), primary key(id));" 124 125 init_cluster 126 127 dmctl_start_task "$cur/conf/dm-task.yaml" "--remove-meta" 128 check_sync_diff $WORK_DIR $cur/conf/diff_config.toml 129 130 sleep 1 131 run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \ 132 "query-status test" \ 133 "\"stage\": \"Finished\"" 2 \ 134 "\"totalBytes\": \"0\"" 2 \ 135 "\"progress\": \"100.00 %\"" 2 136 137 check_log_contains $WORK_DIR/worker1/log/dm-worker.log "progress=\"100.00 %\"" 138 check_log_contains $WORK_DIR/worker2/log/dm-worker.log "progress=\"100.00 %\"" 139 140 cleanup_process $* 141 cleanup_data full_mode 142 } 143 144 function only_route_schema() { 145 run_sql_source1 "drop database if exists full_mode;" 146 run_sql_source1 "create database full_mode;" 147 init_cluster 148 149 dmctl_start_task_standalone "$cur/conf/dm-task-2.yaml" "--remove-meta" 150 run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \ 151 "query-status test" \ 152 "\"stage\": \"Finished\"" 1 153 154 run_sql_tidb_with_retry "SHOW DATABASES LIKE 'full_mode_test';" ": full_mode_test" 155 cleanup_process $* 156 cleanup_data full_mode 157 } 158 159 function run() { 160 fail_acquire_global_lock 161 escape_schema 162 empty_data 163 only_route_schema 164 165 run_sql_both_source "SET @@GLOBAL.SQL_MODE='NO_BACKSLASH_ESCAPES'" 166 run_sql_source1 "SET @@global.time_zone = '+01:00';" 167 run_sql_source2 "SET @@global.time_zone = '+02:00';" 168 169 run_sql_file $cur/data/db1.prepare.sql $MYSQL_HOST1 $MYSQL_PORT1 $MYSQL_PASSWORD1 170 check_contains 'Query OK, 2 rows affected' 171 run_sql_file $cur/data/db2.prepare.sql $MYSQL_HOST2 $MYSQL_PORT2 $MYSQL_PASSWORD2 172 check_contains 'Query OK, 3 rows affected' 173 174 # test load data with `"` in the table name 175 run_sql_source1 "create table full_mode.\`tb\"1\` (id int,name varchar(10), primary key(\`id\`));" 176 run_sql_source1 "insert into full_mode.\`tb\"1\` values(1,'haha');" 177 run_sql_source1 "insert into full_mode.\`tb\"1\` values(2,'hihi');" 178 # write different data in downstream, to test on-duplicate-logical = ignore 179 run_sql_tidb "create database if not exists full_mode;" 180 run_sql_tidb "create table full_mode.\`tb\"1\` (id int,name varchar(10), primary key(\`id\`));" 181 run_sql_tidb "insert into full_mode.\`tb\"1\` values(1,'hoho');" 182 183 run_sql_file $cur/data/db1.prepare.user.sql $MYSQL_HOST1 $MYSQL_PORT1 $MYSQL_PASSWORD1 184 check_count 'Query OK, 0 rows affected' 7 185 run_sql_file $cur/data/db2.prepare.user.sql $MYSQL_HOST2 $MYSQL_PORT2 $MYSQL_PASSWORD2 186 check_count 'Query OK, 0 rows affected' 10 187 188 run_dm_master $WORK_DIR/master $MASTER_PORT $cur/conf/dm-master.toml 189 check_rpc_alive $cur/../bin/check_master_online 127.0.0.1:$MASTER_PORT 190 # check dm-master metrics 191 check_metric $MASTER_PORT 'start_leader_counter' 3 0 2 192 193 run_dm_worker $WORK_DIR/worker1 $WORKER1_PORT $cur/conf/dm-worker1.toml 194 check_rpc_alive $cur/../bin/check_worker_online 127.0.0.1:$WORKER1_PORT 195 run_dm_worker $WORK_DIR/worker2 $WORKER2_PORT $cur/conf/dm-worker2.toml 196 check_rpc_alive $cur/../bin/check_worker_online 127.0.0.1:$WORKER2_PORT 197 # operate mysql config to worker 198 cp $cur/conf/source1.yaml $WORK_DIR/source1.yaml 199 cp $cur/conf/source2.yaml $WORK_DIR/source2.yaml 200 sed -i "/relay-binlog-name/i\relay-dir: $WORK_DIR/worker1/relay_log" $WORK_DIR/source1.yaml 201 sed -i "/relay-binlog-name/i\relay-dir: $WORK_DIR/worker2/relay_log" $WORK_DIR/source2.yaml 202 dmctl_operate_source create $WORK_DIR/source1.yaml $SOURCE_ID1 203 dmctl_operate_source create $WORK_DIR/source2.yaml $SOURCE_ID2 204 205 # start DM task only 206 dmctl_start_task "$cur/conf/dm-task.yaml" "--remove-meta" 207 208 run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \ 209 "query-status test" \ 210 "\"stage\": \"Finished\"" 2 211 212 run_sql_tidb "SELECT name FROM full_mode.\`tb\"1\` WHERE id = 1;" 213 check_contains "hoho" 214 run_sql_source1 "REPLACE INTO full_mode.\`tb\"1\` values(1,'hoho');" 215 216 # use sync_diff_inspector to check full dump loader 217 check_sync_diff $WORK_DIR $cur/conf/diff_config.toml 218 219 echo "check dump files have been cleaned" 220 ls $WORK_DIR/worker1/dumped_data.test && exit 1 || echo "worker1 auto removed dump files" 221 ls $WORK_DIR/worker2/dumped_data.test && exit 1 || echo "worker2 auto removed dump files" 222 # check task finished and metric cleaned 223 check_metric_not_contains $WORKER1_PORT 'dm_worker_task_state{source_id="mysql-replica-01",task="test",worker=\"worker1\"}' 3 224 check_metric_not_contains $WORKER2_PORT 'dm_worker_task_state{source_id="mysql-replica-02",task="test",worker=\"worker2\"}' 3 225 run_sql_both_source "SET @@GLOBAL.SQL_MODE='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'" 226 run_sql_both_source "SET @@GLOBAL.TIME_ZONE='SYSTEM';" 227 } 228 229 cleanup_data full_mode 230 # also cleanup dm processes in case of last run failed 231 cleanup_process $* 232 run $* 233 cleanup_process $* 234 235 echo "[$(date)] <<<<<< test case $TEST_NAME success! >>>>>>"