github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/dm/tests/check_task/run.sh (about) 1 #!/bin/bash 2 set -eu 3 cur=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) 4 source $cur/../_utils/test_prepare 5 WORK_DIR=$TEST_DIR/$TEST_NAME 6 7 TABLE_NUM=20 8 9 function prepare_incompatible_tables() { 10 run_sql_both_source "drop database if exists checktask" 11 run_sql_both_source "create database if not exists checktask" 12 for i in $(seq $TABLE_NUM); do 13 run_sql_both_source "create table checktask.test${i}(id int, b varchar(10))" # no primary key 14 done 15 } 16 17 function prepare() { 18 run_dm_master $WORK_DIR/master $MASTER_PORT $cur/conf/dm-master.toml 19 check_rpc_alive $cur/../bin/check_master_online 127.0.0.1:$MASTER_PORT 20 run_dm_worker $WORK_DIR/worker1 $WORKER1_PORT $cur/conf/dm-worker1.toml 21 check_rpc_alive $cur/../bin/check_worker_online 127.0.0.1:$WORKER1_PORT 22 dmctl_operate_source create $cur/conf/source1.yaml $SOURCE_ID1 23 } 24 25 function test_check_task_warn_no_block() { 26 prepare_incompatible_tables 27 run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \ 28 "check-task $cur/conf/task-noshard.yaml" \ 29 "\"state\": \"warn\"" 1 30 } 31 32 function test_check_task_fail_no_block_forsharding() { 33 run_sql_both_source "drop database if exists \`check-task\`" 34 run_sql_both_source "create database if not exists \`check-task\`" 35 run_sql_file $cur/data/db1.prepare.sql $MYSQL_HOST1 $MYSQL_PORT1 $MYSQL_PASSWORD1 36 37 run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \ 38 "check-task $cur/conf/task-sharding.yaml" \ 39 "\"state\": \"fail\"" 1 40 } 41 42 # this test case ensures that the privileges we require fully meet the demands of both syncer and loader, 43 # and dm can still make progress if the downstream user lacks `super` privilege. 44 function test_privileges_can_migrate() { 45 # cleanup data if last test failed 46 echo "--> start test_privileges_can_migrate..." 47 run_sql_source1 "drop database if exists \`checktask1\`" 48 run_sql_source1 "create database if not exists \`checktask1\`" 49 run_sql_tidb "drop user if exists 'test1'@'%';" 50 run_sql_tidb "drop database if exists \`checktask1\`" 51 run_sql_source1 "create table checktask1.test_privilege(id int primary key, b varchar(10))" 52 run_sql_source1 "insert into checktask1.test_privilege values (1, 'a'),(2, 'b');" 53 run_sql_tidb "create user 'test1'@'%' identified by '123456';" 54 run_sql_tidb "grant select, create, insert, update, delete, alter, drop, index, config on *.* to 'test1'@'%';" 55 run_sql_tidb "flush privileges;" 56 run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \ 57 "start-task $cur/conf/task-priv.yaml --remove-meta" \ 58 "\"state\": \"fail\"" 0 59 sleep 1 # wait full migration finish 60 check_sync_diff $WORK_DIR $cur/conf/diff_config.toml 61 run_sql_source1 "insert into checktask1.test_privilege values (3, 'c'),(4, 'd');" # simple dml 62 run_sql_source1 "alter table checktask1.test_privilege add column c int default 0;" # ddl 63 run_sql_source1 "create table checktask1.test_ddl(id int primary key, b varchar(10));" # create table 64 run_sql_source1 "create table checktask1.test_ddl2(id int primary key, b varchar(10));" 65 run_sql_source1 "drop table checktask1.test_ddl2;" # drop table 66 run_sql_source1 "create index idx on checktask1.test_privilege(b);" # create index 67 run_sql_source1 "insert into checktask1.test_privilege values (5, 'e', 5),(6, 'f', 6);" # dml with ddl 68 run_sql_source1 "insert into checktask1.test_ddl values (1, 'a'),(2, 'b');" # simple dml 69 run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \ 70 "query-status test" \ 71 "\"Running\"" 2 72 check_sync_diff $WORK_DIR $cur/conf/diff_config.toml 73 run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \ 74 "stop-task test" \ 75 "\"result\": true" 2 76 # cleanup 77 run_sql_tidb "drop user 'test1'@'%';" 78 run_sql_tidb "drop database if exists \`checktask1\`;" 79 echo "pass test_privileges_can_migrate" 80 } 81 82 function test_privilege_precheck() { 83 echo "--> start test_privilege_precheck..." 84 # fail: missing privilege 85 run_sql_tidb "drop user if exists 'test1'@'%';" 86 run_sql_tidb "create user 'test1'@'%' identified by '123456';" 87 run_sql_tidb "grant select, create, insert, delete, alter, drop, index on *.* to 'test1'@'%';" 88 run_sql_tidb "flush privileges;" 89 run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \ 90 "check-task $cur/conf/task-priv.yaml" \ 91 "\"warning\": 1" 1 \ 92 "lack of Update global (*.*) privilege" 1 93 run_sql_tidb "grant update on *.* to 'test1'@'%';" 94 run_sql_tidb "flush privileges;" 95 # success: fulfill privileges 96 run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \ 97 "check-task $cur/conf/task-priv.yaml" \ 98 "\"msg\": \"pre-check is passed. \"" 1 99 run_sql_tidb "drop user 'test1'@'%';" 100 101 # success: all privileges 102 run_sql_tidb "create user 'test1'@'%' identified by '123456';" 103 run_sql_tidb "grant all privileges on *.* to 'test1'@'%';" 104 run_sql_tidb "flush privileges;" 105 run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \ 106 "check-task $cur/conf/task-priv.yaml" \ 107 "\"msg\": \"pre-check is passed. \"" 1 108 run_sql_tidb "drop user 'test1'@'%';" 109 echo "pass test_privilege_precheck" 110 } 111 112 function run() { 113 prepare 114 test_check_task_warn_no_block 115 test_check_task_fail_no_block_forsharding 116 test_privileges_can_migrate 117 test_privilege_precheck 118 } 119 120 cleanup_data check-task 121 cleanup_data checktask 122 cleanup_process $* 123 run $* 124 cleanup_process $* 125 cleanup_data checktask 126 cleanup_data check-task