github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/dm/tests/online_ddl/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 run() {
    10  	run_dm_master $WORK_DIR/master $MASTER_PORT $cur/conf/dm-master.toml
    11  	check_rpc_alive $cur/../bin/check_master_online 127.0.0.1:$MASTER_PORT
    12  	check_metric $MASTER_PORT 'start_leader_counter' 3 0 2
    13  
    14  	run_dm_worker $WORK_DIR/worker1 $WORKER1_PORT $cur/conf/dm-worker1.toml
    15  	check_rpc_alive $cur/../bin/check_worker_online 127.0.0.1:$WORKER1_PORT
    16  	# operate mysql config to worker
    17  	cp $cur/conf/source1.yaml $WORK_DIR/source1.yaml
    18  	cp $cur/conf/source2.yaml $WORK_DIR/source2.yaml
    19  	sed -i "/relay-binlog-name/i\relay-dir: $WORK_DIR/worker1/relay_log" $WORK_DIR/source1.yaml
    20  	sed -i "/relay-binlog-name/i\relay-dir: $WORK_DIR/worker2/relay_log" $WORK_DIR/source2.yaml
    21  	dmctl_operate_source create $WORK_DIR/source1.yaml $SOURCE_ID1
    22  
    23  	cp $cur/conf/check-task.yaml $WORK_DIR/check-task.yaml
    24  	# prevent start task in process of online-ddl
    25  	run_sql_file $cur/data/check.gho.db1.sql $MYSQL_HOST1 $MYSQL_PORT1 $MYSQL_PASSWORD1
    26  	run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
    27  		"check-task $WORK_DIR/check-task.yaml" \
    28  		"your ddl is in pt\/ghost online-ddl" 1
    29  
    30  	run_sql_file $cur/data/check.pt.db1.sql $MYSQL_HOST1 $MYSQL_PORT1 $MYSQL_PASSWORD1
    31  	run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
    32  		"check-task $WORK_DIR/check-task.yaml" \
    33  		"your ddl is in pt\/ghost online-ddl" 1
    34  
    35  	run_sql_file $cur/data/gho.db1.prepare.sql $MYSQL_HOST1 $MYSQL_PORT1 $MYSQL_PASSWORD1
    36  	check_contains 'Query OK, 2 rows affected'
    37  	run_sql_file $cur/data/gho.db2.prepare.sql $MYSQL_HOST2 $MYSQL_PORT2 $MYSQL_PASSWORD2
    38  	check_contains 'Query OK, 3 rows affected'
    39  	run_sql_file $cur/data/pt.db1.prepare.sql $MYSQL_HOST1 $MYSQL_PORT1 $MYSQL_PASSWORD1
    40  	check_contains 'Query OK, 2 rows affected'
    41  	run_sql_file $cur/data/pt.db2.prepare.sql $MYSQL_HOST2 $MYSQL_PORT2 $MYSQL_PASSWORD2
    42  	check_contains 'Query OK, 3 rows affected'
    43  
    44  	inject_points=(
    45  		"github.com/pingcap/tiflow/dm/syncer/online-ddl-tools/ExitAfterSaveOnlineDDL=return()"
    46  		"github.com/pingcap/tiflow/dm/syncer/ExitAfterSaveOnlineDDL=return()"
    47  	)
    48  	export GO_FAILPOINTS="$(join_string \; ${inject_points[@]})"
    49  	run_dm_worker $WORK_DIR/worker2 $WORKER2_PORT $cur/conf/dm-worker2.toml
    50  	check_rpc_alive $cur/../bin/check_worker_online 127.0.0.1:$WORKER2_PORT
    51  	export GO_FAILPOINTS=""
    52  
    53  	dmctl_operate_source create $WORK_DIR/source2.yaml $SOURCE_ID2
    54  
    55  	# imitate a DM task is started during the running of online DDL tool
    56  	# *_ignore will be skipped by block-allow-list
    57  	run_sql_source1 "create table online_ddl.gho_ignore (c int); create table online_ddl._gho_ignore_gho (c int);"
    58  	run_sql_source1 "create table online_ddl.pt_ignore (c int); create table online_ddl._pt_ignore_new (c int);"
    59  
    60  	# start DM task only
    61  	cp $cur/conf/dm-task.yaml $WORK_DIR/dm-task.yaml
    62  	dmctl_start_task "$WORK_DIR/dm-task.yaml" "--remove-meta"
    63  
    64  	echo "use sync_diff_inspector to check full dump data"
    65  	check_sync_diff $WORK_DIR $cur/conf/diff_config.toml
    66  
    67  	run_sql_online_ddl "alter table gho_t1 add column c int comment '1  2
    68  3😊4';" $MYSQL_HOST1 $MYSQL_PORT1 $MYSQL_PASSWORD1 online_ddl gh-ost
    69  	run_sql_online_ddl "alter table gho_t2 add column c int comment '1  2
    70  3😊4';" $MYSQL_HOST1 $MYSQL_PORT1 $MYSQL_PASSWORD1 online_ddl gh-ost
    71  	run_sql_online_ddl "alter table gho_t2 add column c int comment '1  2
    72  3😊4';" $MYSQL_HOST2 $MYSQL_PORT2 $MYSQL_PASSWORD2 online_ddl gh-ost
    73  	run_sql_online_ddl "alter table gho_t3 add column c int comment '1  2
    74  3😊4';" $MYSQL_HOST2 $MYSQL_PORT2 $MYSQL_PASSWORD2 online_ddl gh-ost
    75  
    76  	run_sql_online_ddl "alter table pt_t1 add column c int comment '1  2
    77  3😊4';" $MYSQL_HOST1 $MYSQL_PORT1 $MYSQL_PASSWORD1 online_ddl pt
    78  	run_sql_online_ddl "alter table pt_t2 add column c int comment '1  2
    79  3😊4';" $MYSQL_HOST1 $MYSQL_PORT1 $MYSQL_PASSWORD1 online_ddl pt
    80  	run_sql_online_ddl "alter table pt_t2 add column c int comment '1  2
    81  3😊4';" $MYSQL_HOST2 $MYSQL_PORT2 $MYSQL_PASSWORD2 online_ddl pt
    82  	run_sql_online_ddl "alter table pt_t3 add column c int comment '1  2
    83  3😊4';" $MYSQL_HOST2 $MYSQL_PORT2 $MYSQL_PASSWORD2 online_ddl pt
    84  
    85  	check_port_offline $WORKER2_PORT 10
    86  	run_dm_worker $WORK_DIR/worker2 $WORKER2_PORT $cur/conf/dm-worker2.toml
    87  	check_rpc_alive $cur/../bin/check_worker_online 127.0.0.1:$WORKER2_PORT
    88  
    89  	echo "use sync_diff_inspector to check full data"
    90  	check_sync_diff $WORK_DIR $cur/conf/diff_config.toml
    91  
    92  	# imitate a DM task is started during the processing of online DDL tool
    93  	# *_ignore will be skipped by block-allow-list
    94  	run_sql_source1 "rename /* gh-ost */ table online_ddl.gho_ignore to online_ddl._gho_ignore_del, online_ddl._gho_ignore_gho to online_ddl.gho_ignore;"
    95  	run_sql_source1 "rename table online_ddl.pt_ignore to online_ddl._pt_ignore_old, online_ddl._pt_ignore_new to online_ddl.pt_ignore;"
    96  
    97  	run_sql_file_online_ddl $cur/data/gho.db1.increment.sql $MYSQL_HOST1 $MYSQL_PORT1 $MYSQL_PASSWORD1 online_ddl gh-ost
    98  	run_sql_file_online_ddl $cur/data/gho.db2.increment.sql $MYSQL_HOST2 $MYSQL_PORT2 $MYSQL_PASSWORD2 online_ddl gh-ost
    99  	run_sql_file_online_ddl $cur/data/pt.db1.increment.sql $MYSQL_HOST1 $MYSQL_PORT1 $MYSQL_PASSWORD1 online_ddl pt
   100  	run_sql_file_online_ddl $cur/data/pt.db2.increment.sql $MYSQL_HOST2 $MYSQL_PORT2 $MYSQL_PASSWORD2 online_ddl pt
   101  
   102  	for ((k = 0; k < 10; k++)); do
   103  		run_sql_tidb "show create table online_ddl.pt_t_target"
   104  		check_contains "info_json" && break || true
   105  		sleep 1
   106  	done
   107  	check_contains "info_json"
   108  
   109  	run_sql_tidb "show create table online_ddl.gho_t_target"
   110  	run_sql_tidb "show create table online_ddl.pt_t_target"
   111  	check_not_contains "KEY \`name\`"
   112  
   113  	# manually create index to pass check_sync_diff
   114  	run_sql_tidb "alter table online_ddl.gho_t_target add key name (name)"
   115  	run_sql_tidb "alter table online_ddl.pt_t_target add key name (name)"
   116  
   117  	echo "use sync_diff_inspector to check increment data"
   118  	check_sync_diff $WORK_DIR $cur/conf/diff_config.toml
   119  
   120  	echo "start dm-worker3 and kill dm-worker2"
   121  	kill_process dm-worker2
   122  	check_port_offline $WORKER2_PORT 20
   123  
   124  	run_dm_worker $WORK_DIR/worker3 $WORKER3_PORT $cur/conf/dm-worker3.toml
   125  	check_rpc_alive $cur/../bin/check_worker_online 127.0.0.1:$WORKER3_PORT
   126  
   127  	echo "wait and check task running"
   128  	run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
   129  		"query-status test" \
   130  		"\"stage\": \"Running\"" 3
   131  
   132  	# worker1 and worker3 in running stage.
   133  	check_metric $WORKER1_PORT "dm_worker_task_state{source_id=\"mysql-replica-01\",task=\"test\",worker=\"worker1\"}" 3 1 3
   134  	check_metric $WORKER3_PORT "dm_worker_task_state{source_id=\"mysql-replica-02\",task=\"test\",worker=\"worker3\"}" 3 1 3
   135  
   136  	run_sql_file $cur/data/gho.db1.increment2.sql $MYSQL_HOST1 $MYSQL_PORT1 $MYSQL_PASSWORD1
   137  	run_sql_file $cur/data/gho.db2.increment2.sql $MYSQL_HOST2 $MYSQL_PORT2 $MYSQL_PASSWORD2
   138  	run_sql_file $cur/data/pt.db1.increment2.sql $MYSQL_HOST1 $MYSQL_PORT1 $MYSQL_PASSWORD1
   139  	run_sql_file $cur/data/pt.db2.increment2.sql $MYSQL_HOST2 $MYSQL_PORT2 $MYSQL_PASSWORD2
   140  	sleep 2
   141  
   142  	echo "use sync_diff_inspector to check increment2 data now!"
   143  	check_sync_diff $WORK_DIR $cur/conf/diff_config.toml
   144  }
   145  
   146  cleanup_data online_ddl
   147  # also cleanup dm processes in case of last run failed
   148  cleanup_process $*
   149  run
   150  cleanup_process $*
   151  
   152  echo "[$(date)] <<<<<< test case $TEST_NAME success! >>>>>>"