github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/dm/tests/shardddl2_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  source $cur/../_utils/shardddl_lib.sh
     9  
    10  function DM_046_CASE() {
    11  	run_sql_source1 "alter table ${shardddl1}.${tb1} drop column b;"
    12  	run_sql_source1 "insert into ${shardddl1}.${tb1} values(1);"
    13  	run_sql_source2 "insert into ${shardddl1}.${tb1} values(2,'aaa');"
    14  	run_sql_source2 "insert into ${shardddl1}.${tb2} values(3,'bbb');"
    15  	run_sql_source2 "alter table ${shardddl1}.${tb1} drop column b;"
    16  	run_sql_source1 "insert into ${shardddl1}.${tb1} values(4);"
    17  	run_sql_source2 "insert into ${shardddl1}.${tb1} values(5);"
    18  	run_sql_source2 "insert into ${shardddl1}.${tb2} values(6,'ccc');"
    19  	run_sql_source2 "alter table ${shardddl1}.${tb2} drop column b;"
    20  	run_sql_source1 "insert into ${shardddl1}.${tb1} values(7);"
    21  	run_sql_source2 "insert into ${shardddl1}.${tb1} values(8);"
    22  	run_sql_source2 "insert into ${shardddl1}.${tb2} values(9);"
    23  	check_sync_diff $WORK_DIR $cur/conf/diff_config.toml
    24  }
    25  
    26  function DM_046() {
    27  	run_case 046 "double-source-pessimistic" \
    28  		"run_sql_source1 \"create table ${shardddl1}.${tb1} (a int primary key, b varchar(10));\"; \
    29       run_sql_source2 \"create table ${shardddl1}.${tb1} (a int primary key, b varchar(10));\"; \
    30       run_sql_source2 \"create table ${shardddl1}.${tb2} (a int primary key, b varchar(10));\"" \
    31  		"clean_table" "pessimistic"
    32  	run_case 046 "double-source-optimistic" \
    33  		"run_sql_source1 \"create table ${shardddl1}.${tb1} (a int primary key, b varchar(10));\"; \
    34       run_sql_source2 \"create table ${shardddl1}.${tb1} (a int primary key, b varchar(10));\"; \
    35       run_sql_source2 \"create table ${shardddl1}.${tb2} (a int primary key, b varchar(10));\"" \
    36  		"clean_table" "optimistic"
    37  }
    38  
    39  function DM_047_CASE() {
    40  	run_sql_source1 "alter table ${shardddl1}.${tb1} drop column c;"
    41  	run_sql_source1 "insert into ${shardddl1}.${tb1} values(1,'aaa');"
    42  	run_sql_source2 "insert into ${shardddl1}.${tb1} (a,b) values(2,'bbb');"
    43  	run_sql_source2 "insert into ${shardddl1}.${tb2} (a,b) values(3,'ccc');"
    44  	run_sql_source2 "alter table ${shardddl1}.${tb1} drop column c;"
    45  	run_sql_source1 "insert into ${shardddl1}.${tb1} values(4,'ddd');"
    46  	run_sql_source2 "insert into ${shardddl1}.${tb1} values(5,'eee');"
    47  	run_sql_source2 "insert into ${shardddl1}.${tb2} (a,b) values(6,'fff');"
    48  	run_sql_source2 "alter table ${shardddl1}.${tb2} drop column c;"
    49  	run_sql_source1 "insert into ${shardddl1}.${tb1} values(7,'ggg');"
    50  	run_sql_source2 "insert into ${shardddl1}.${tb1} values(8,'hhh');"
    51  	run_sql_source2 "insert into ${shardddl1}.${tb2} values(9,'iii');"
    52  	check_sync_diff $WORK_DIR $cur/conf/diff_config.toml
    53  }
    54  
    55  function DM_047() {
    56  	run_case 047 "double-source-pessimistic" \
    57  		"run_sql_source1 \"create table ${shardddl1}.${tb1} (a int primary key, b varchar(10), c int as (a+1) stored);\"; \
    58       run_sql_source2 \"create table ${shardddl1}.${tb1} (a int primary key, b varchar(10), c int as (a+1) stored);\"; \
    59       run_sql_source2 \"create table ${shardddl1}.${tb2} (a int primary key, b varchar(10), c int as (a+1) stored);\"" \
    60  		"clean_table" "pessimistic"
    61  	run_case 047 "double-source-optimistic" \
    62  		"run_sql_source1 \"create table ${shardddl1}.${tb1} (a int primary key, b varchar(10), c int as (a+1) stored);\"; \
    63       run_sql_source2 \"create table ${shardddl1}.${tb1} (a int primary key, b varchar(10), c int as (a+1) stored);\"; \
    64       run_sql_source2 \"create table ${shardddl1}.${tb2} (a int primary key, b varchar(10), c int as (a+1) stored);\"" \
    65  		"clean_table" "optimistic"
    66  }
    67  
    68  function DM_048_CASE() {
    69  	run_sql_source1 "alter table ${shardddl1}.${tb1} drop column c;"
    70  	run_sql_source1 "insert into ${shardddl1}.${tb1} values(1,'aaa');"
    71  	run_sql_source2 "insert into ${shardddl1}.${tb1} (a,b) values(2,'bbb');"
    72  	run_sql_source2 "insert into ${shardddl1}.${tb2} (a,b) values(3,'ccc');"
    73  	run_sql_source2 "alter table ${shardddl1}.${tb1} drop column c;"
    74  	run_sql_source1 "insert into ${shardddl1}.${tb1} values(4,'ddd');"
    75  	run_sql_source2 "insert into ${shardddl1}.${tb1} values(5,'eee');"
    76  	run_sql_source2 "insert into ${shardddl1}.${tb2} (a,b) values(6,'fff');"
    77  	run_sql_source2 "alter table ${shardddl1}.${tb2} drop column c;"
    78  	run_sql_source1 "insert into ${shardddl1}.${tb1} values(7,'ggg');"
    79  	run_sql_source2 "insert into ${shardddl1}.${tb1} values(8,'hhh');"
    80  	run_sql_source2 "insert into ${shardddl1}.${tb2} values(9,'iii');"
    81  	check_sync_diff $WORK_DIR $cur/conf/diff_config.toml
    82  }
    83  
    84  function DM_048() {
    85  	run_case 048 "double-source-pessimistic" \
    86  		"run_sql_source1 \"create table ${shardddl1}.${tb1} (a int primary key, b varchar(10), c int as (a+1) virtual);\"; \
    87       run_sql_source2 \"create table ${shardddl1}.${tb1} (a int primary key, b varchar(10), c int as (a+1) virtual);\"; \
    88       run_sql_source2 \"create table ${shardddl1}.${tb2} (a int primary key, b varchar(10), c int as (a+1) virtual);\"" \
    89  		"clean_table" "pessimistic"
    90  	run_case 048 "double-source-optimistic" \
    91  		"run_sql_source1 \"create table ${shardddl1}.${tb1} (a int primary key, b varchar(10), c int as (a+1) virtual);\"; \
    92       run_sql_source2 \"create table ${shardddl1}.${tb1} (a int primary key, b varchar(10), c int as (a+1) virtual);\"; \
    93       run_sql_source2 \"create table ${shardddl1}.${tb2} (a int primary key, b varchar(10), c int as (a+1) virtual);\"" \
    94  		"clean_table" "optimistic"
    95  }
    96  
    97  function DM_049_CASE() {
    98  	run_sql_source1 "alter table ${shardddl1}.${tb1} change a c int;"
    99  	run_sql_source1 "insert into ${shardddl1}.${tb1} values(1,'aaa');"
   100  	run_sql_source2 "insert into ${shardddl1}.${tb1} values(2,'bbb');"
   101  	run_sql_source2 "insert into ${shardddl1}.${tb2} values(3,'ccc');"
   102  	run_sql_source2 "alter table ${shardddl1}.${tb1} change a c int;"
   103  	run_sql_source1 "insert into ${shardddl1}.${tb1} values(4,'ddd');"
   104  	run_sql_source2 "insert into ${shardddl1}.${tb1} values(5,'eee');"
   105  	run_sql_source2 "insert into ${shardddl1}.${tb2} values(6,'fff');"
   106  	run_sql_source2 "alter table ${shardddl1}.${tb2} change a c int;"
   107  	run_sql_source1 "insert into ${shardddl1}.${tb1} values(7,'ggg');"
   108  	run_sql_source2 "insert into ${shardddl1}.${tb1} values(8,'hhh');"
   109  	run_sql_source2 "insert into ${shardddl1}.${tb2} values(9,'iii');"
   110  
   111  	# insert 3 recorde to make sure optimistic mode sharding resolve can finish fast
   112  	sleep 3
   113  	run_sql_source1 "insert into ${shardddl1}.${tb1} values(10,'jjj');"
   114  	run_sql_source2 "insert into ${shardddl1}.${tb1} values(11,'kkk');"
   115  	run_sql_source2 "insert into ${shardddl1}.${tb2} values(12,'lll');"
   116  	check_sync_diff $WORK_DIR $cur/conf/diff_config.toml
   117  }
   118  
   119  function DM_049() {
   120  	run_case 049 "double-source-pessimistic" \
   121  		"run_sql_source1 \"create table ${shardddl1}.${tb1} (a int primary key, b varchar(10));\"; \
   122       run_sql_source2 \"create table ${shardddl1}.${tb1} (a int primary key, b varchar(10));\"; \
   123       run_sql_source2 \"create table ${shardddl1}.${tb2} (a int primary key, b varchar(10));\"" \
   124  		"clean_table" "pessimistic"
   125  	run_case 049 "double-source-optimistic" \
   126  		"run_sql_source1 \"create table ${shardddl1}.${tb1} (a int primary key, b varchar(10));\"; \
   127       run_sql_source2 \"create table ${shardddl1}.${tb1} (a int primary key, b varchar(10));\"; \
   128       run_sql_source2 \"create table ${shardddl1}.${tb2} (a int primary key, b varchar(10));\"" \
   129  		"clean_table" "optimistic"
   130  }
   131  
   132  function DM_050_CASE() {
   133  	run_sql_source1 "alter table ${shardddl1}.${tb1} change a c int;"
   134  	run_sql_source1 "insert into ${shardddl1}.${tb1} values(1,'aaa');"
   135  	run_sql_source2 "insert into ${shardddl1}.${tb1} values(2,'bbb');"
   136  	run_sql_source2 "insert into ${shardddl1}.${tb2} values(3,'ccc');"
   137  	if [[ "$1" = "optimistic" ]]; then
   138  		relate_worker=$($PWD/bin/dmctl.test DEVEL --master-addr "127.0.0.1:$MASTER_PORT1" operate-source show -s "mysql-replica-01" |
   139  			grep 'worker' | awk -F: '{print $2}' | cut -d'"' -f 2)
   140  		# make sure in skip and wait redirect
   141  		check_log_contain_with_retry 'got a shard DDL lock operation.*CHANGE COLUMN `a` `c` INT' $WORK_DIR/$relate_worker/log/dm-worker.log
   142  	fi
   143  	run_sql_source2 "alter table ${shardddl1}.${tb1} change a d int;"
   144  	run_sql_source1 "insert into ${shardddl1}.${tb1} values(4,'ddd');"
   145  	run_sql_source2 "insert into ${shardddl1}.${tb1} values(5,'eee');"
   146  	run_sql_source2 "insert into ${shardddl1}.${tb2} values(6,'fff');"
   147  	run_sql_source2 "alter table ${shardddl1}.${tb2} change a d int;"
   148  	run_sql_source1 "insert into ${shardddl1}.${tb1} values(7,'ggg');"
   149  	run_sql_source2 "insert into ${shardddl1}.${tb1} values(8,'hhh');"
   150  	run_sql_source2 "insert into ${shardddl1}.${tb2} values(9,'iii');"
   151  
   152  	if [[ "$1" = "pessimistic" ]]; then
   153  		check_log_contain_with_retry "is different with" $WORK_DIR/master/log/dm-master.log
   154  	else
   155  		# can't make sure DDL of which source comes first
   156  		run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
   157  			"query-status test" \
   158  			'ALTER TABLE `shardddl`.`tb` CHANGE COLUMN' 1 \
   159  			"\"${SOURCE_ID2}-\`${shardddl1}\`.\`${tb1}\`\"" 1
   160  	fi
   161  }
   162  
   163  function DM_050() {
   164  	run_case 050 "double-source-pessimistic" \
   165  		"run_sql_source1 \"create table ${shardddl1}.${tb1} (a int primary key, b varchar(10));\"; \
   166       run_sql_source2 \"create table ${shardddl1}.${tb1} (a int primary key, b varchar(10));\"; \
   167       run_sql_source2 \"create table ${shardddl1}.${tb2} (a int primary key, b varchar(10));\"" \
   168  		"clean_table" "pessimistic"
   169  	run_case 050 "double-source-optimistic" \
   170  		"run_sql_source1 \"create table ${shardddl1}.${tb1} (a int primary key, b varchar(10));\"; \
   171       run_sql_source2 \"create table ${shardddl1}.${tb1} (a int primary key, b varchar(10));\"; \
   172       run_sql_source2 \"create table ${shardddl1}.${tb2} (a int primary key, b varchar(10));\"" \
   173  		"clean_table" "optimistic"
   174  }
   175  
   176  function DM_051_CASE() {
   177  	run_sql_source1 "alter table ${shardddl1}.${tb1} change a c int;"
   178  	run_sql_source1 "insert into ${shardddl1}.${tb1} values(1,1);"
   179  	run_sql_source2 "insert into ${shardddl1}.${tb1} values(2,2);"
   180  	run_sql_source2 "insert into ${shardddl1}.${tb2} values(3,3);"
   181  	if [[ "$1" = "optimistic" ]]; then
   182  		relate_worker=$($PWD/bin/dmctl.test DEVEL --master-addr "127.0.0.1:$MASTER_PORT1" operate-source show -s "mysql-replica-01" |
   183  			grep 'worker' | awk -F: '{print $2}' | cut -d'"' -f 2)
   184  		# make sure in skip and wait redirect
   185  		check_log_contain_with_retry 'got a shard DDL lock operation.*CHANGE COLUMN `a` `c` INT' $WORK_DIR/$relate_worker/log/dm-worker.log
   186  	fi
   187  
   188  	run_sql_source2 "alter table ${shardddl1}.${tb1} change b c int;"
   189  	run_sql_source1 "insert into ${shardddl1}.${tb1} values(4,4);"
   190  	run_sql_source2 "insert into ${shardddl1}.${tb1} values(5,5);"
   191  	run_sql_source2 "insert into ${shardddl1}.${tb2} values(6,6);"
   192  	run_sql_source2 "alter table ${shardddl1}.${tb2} change b c int;"
   193  	run_sql_source1 "insert into ${shardddl1}.${tb1} values(7,7);"
   194  	run_sql_source2 "insert into ${shardddl1}.${tb1} values(8,8);"
   195  	run_sql_source2 "insert into ${shardddl1}.${tb2} values(9,9);"
   196  
   197  	if [[ "$1" = "pessimistic" ]]; then
   198  		check_log_contain_with_retry "is different with" $WORK_DIR/master/log/dm-master.log
   199  	else
   200  		run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
   201  			"query-status test" \
   202  			'ALTER TABLE `shardddl`.`tb` CHANGE COLUMN `b` `c` INT' 1 \
   203  			"\"${SOURCE_ID2}-\`${shardddl1}\`.\`${tb1}\`\"" 1
   204  	fi
   205  }
   206  
   207  function DM_051() {
   208  	run_case 051 "double-source-pessimistic" \
   209  		"run_sql_source1 \"create table ${shardddl1}.${tb1} (a int primary key, b int);\"; \
   210       run_sql_source2 \"create table ${shardddl1}.${tb1} (a int primary key, b int);\"; \
   211       run_sql_source2 \"create table ${shardddl1}.${tb2} (a int primary key, b int);\"" \
   212  		"clean_table" "pessimistic"
   213  	run_case 051 "double-source-optimistic" \
   214  		"run_sql_source1 \"create table ${shardddl1}.${tb1} (a int primary key, b int);\"; \
   215       run_sql_source2 \"create table ${shardddl1}.${tb1} (a int primary key, b int);\"; \
   216       run_sql_source2 \"create table ${shardddl1}.${tb2} (a int primary key, b int);\"" \
   217  		"clean_table" "optimistic"
   218  }
   219  
   220  function DM_056_CASE() {
   221  	run_sql_source1 "alter table ${shardddl1}.${tb1} change a c int after b;"
   222  	run_sql_source1 "insert into ${shardddl1}.${tb1} values(1,101);"
   223  	run_sql_source2 "insert into ${shardddl1}.${tb1} values(2,102);"
   224  	run_sql_source2 "insert into ${shardddl1}.${tb2} values(3,103);"
   225  	run_sql_source2 "alter table ${shardddl1}.${tb1} change a c int first;"
   226  	run_sql_source1 "insert into ${shardddl1}.${tb1} values(4,104);"
   227  	run_sql_source2 "insert into ${shardddl1}.${tb1} values(5,105);"
   228  	run_sql_source2 "insert into ${shardddl1}.${tb2} values(6,106);"
   229  	run_sql_source2 "alter table ${shardddl1}.${tb2} change a c int first;"
   230  	run_sql_source1 "insert into ${shardddl1}.${tb1} values(7,107);"
   231  	run_sql_source2 "insert into ${shardddl1}.${tb1} values(8,108);"
   232  	run_sql_source2 "insert into ${shardddl1}.${tb2} values(9,109);"
   233  
   234  	if [[ "$1" = "pessimistic" ]]; then
   235  		check_log_contain_with_retry "is different with" $WORK_DIR/master/log/dm-master.log
   236  	else
   237  		run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
   238  			"query-status test" \
   239  			'Running' 3
   240  		run_sql_source1 "alter table ${shardddl1}.${tb1} change c c int first;"
   241  		run_sql_source1 "insert into ${shardddl1}.${tb1} values(10,110);"
   242  		run_sql_source2 "insert into ${shardddl1}.${tb1} values(11,111);"
   243  		run_sql_source2 "insert into ${shardddl1}.${tb2} values(12,112);"
   244  
   245  		sleep 3
   246  		run_sql_source1 "insert into ${shardddl1}.${tb1} values(13,113);"
   247  		run_sql_source2 "insert into ${shardddl1}.${tb1} values(14,114);"
   248  		run_sql_source2 "insert into ${shardddl1}.${tb2} values(15,115);"
   249  		check_sync_diff $WORK_DIR $cur/conf/diff_config.toml
   250  	fi
   251  }
   252  
   253  function DM_056() {
   254  	run_case 056 "double-source-pessimistic" \
   255  		"run_sql_source1 \"create table ${shardddl1}.${tb1} (a int primary key, b int);\"; \
   256       run_sql_source2 \"create table ${shardddl1}.${tb1} (a int primary key, b int);\"; \
   257       run_sql_source2 \"create table ${shardddl1}.${tb2} (a int primary key, b int);\"" \
   258  		"clean_table" "pessimistic"
   259  	run_case 056 "double-source-optimistic" \
   260  		"run_sql_source1 \"create table ${shardddl1}.${tb1} (a int primary key, b int);\"; \
   261       run_sql_source2 \"create table ${shardddl1}.${tb1} (a int primary key, b int);\"; \
   262       run_sql_source2 \"create table ${shardddl1}.${tb2} (a int primary key, b int);\"" \
   263  		"clean_table" "optimistic"
   264  }
   265  
   266  function DM_057_CASE() {
   267  	run_sql_source1 "alter table ${shardddl1}.${tb1} change id new_col int default 1;"
   268  	run_sql_source1 "insert into ${shardddl1}.${tb1} values(1);"
   269  	run_sql_source2 "insert into ${shardddl1}.${tb1} values(2);"
   270  	run_sql_source2 "insert into ${shardddl1}.${tb2} values(3);"
   271  	run_sql_source2 "alter table ${shardddl1}.${tb1} change id new_col int default 1;"
   272  	run_sql_source1 "insert into ${shardddl1}.${tb1} values(4);"
   273  	run_sql_source2 "insert into ${shardddl1}.${tb1} values(5);"
   274  	run_sql_source2 "insert into ${shardddl1}.${tb2} values(6);"
   275  	run_sql_source2 "alter table ${shardddl1}.${tb2} change id new_col int default 1;"
   276  	run_sql_source1 "insert into ${shardddl1}.${tb1} values(7);"
   277  	run_sql_source2 "insert into ${shardddl1}.${tb1} values(8);"
   278  	run_sql_source2 "insert into ${shardddl1}.${tb2} values(9);"
   279  	check_sync_diff $WORK_DIR $cur/conf/diff_config.toml
   280  }
   281  
   282  function DM_057() {
   283  	run_case 057 "double-source-pessimistic" "init_table 111 211 212" "clean_table" "pessimistic"
   284  	# currently not support optimistic
   285  	# run_case 057 "double-source-optimistic" "init_table 111 211 212" "clean_table" "optimistic"
   286  }
   287  
   288  function DM_058_CASE() {
   289  	run_sql_source1 "alter table ${shardddl1}.${tb1} change id new_col int default 1;"
   290  	run_sql_source1 "insert into ${shardddl1}.${tb1} values(1);"
   291  	run_sql_source2 "insert into ${shardddl1}.${tb1} values(2);"
   292  	run_sql_source2 "insert into ${shardddl1}.${tb2} values(3);"
   293  	if [[ "$1" = "optimistic" ]]; then
   294  		relate_worker=$($PWD/bin/dmctl.test DEVEL --master-addr "127.0.0.1:$MASTER_PORT1" operate-source show -s "mysql-replica-01" |
   295  			grep 'worker' | awk -F: '{print $2}' | cut -d'"' -f 2)
   296  		# make sure in skip and wait redirect
   297  		check_log_contain_with_retry 'got a shard DDL lock operation.*CHANGE COLUMN `id` `new_col`' $WORK_DIR/$relate_worker/log/dm-worker.log
   298  	fi
   299  	run_sql_source2 "alter table ${shardddl1}.${tb1} change id new_col int default 2;"
   300  	run_sql_source1 "insert into ${shardddl1}.${tb1} values(4);"
   301  	run_sql_source2 "insert into ${shardddl1}.${tb1} values(5);"
   302  	run_sql_source2 "insert into ${shardddl1}.${tb2} values(6);"
   303  	run_sql_source2 "alter table ${shardddl1}.${tb2} change id new_col int default 2;"
   304  	run_sql_source1 "insert into ${shardddl1}.${tb1} values(7);"
   305  	run_sql_source2 "insert into ${shardddl1}.${tb1} values(8);"
   306  	run_sql_source2 "insert into ${shardddl1}.${tb2} values(9);"
   307  
   308  	if [[ "$1" = "pessimistic" ]]; then
   309  		check_log_contain_with_retry "is different with" $WORK_DIR/master/log/dm-master.log
   310  	else
   311  		run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
   312  			"query-status test" \
   313  			'ALTER TABLE `shardddl`.`tb` CHANGE COLUMN `id` `new_col` INT DEFAULT 2' 1 \
   314  			"\"${SOURCE_ID2}-\`${shardddl1}\`.\`${tb1}\`\"" 1
   315  	fi
   316  }
   317  
   318  function DM_058() {
   319  	run_case 058 "double-source-pessimistic" "init_table 111 211 212" "clean_table" "pessimistic"
   320  	run_case 058 "double-source-optimistic" "init_table 111 211 212" "clean_table" "optimistic"
   321  }
   322  
   323  function DM_059_CASE {
   324  	run_sql_source1 "insert into ${shardddl1}.${tb1} (id) values(1);"
   325  	run_sql_source2 "insert into ${shardddl1}.${tb1} (id) values(2);"
   326  	run_sql_source2 "insert into ${shardddl1}.${tb2} (id) values(3);"
   327  
   328  	run_sql_source1 "alter table ${shardddl1}.${tb1} change a new_col datetime default now();"
   329  	run_sql_source1 "insert into ${shardddl1}.${tb1} (id) values(4);"
   330  	run_sql_source2 "insert into ${shardddl1}.${tb1} (id) values(5);"
   331  	run_sql_source2 "insert into ${shardddl1}.${tb2} (id) values(6);"
   332  	sleep 1
   333  	run_sql_source2 "alter table ${shardddl1}.${tb1} change a new_col datetime default now();"
   334  	run_sql_source1 "insert into ${shardddl1}.${tb1} (id) values(7);"
   335  	run_sql_source2 "insert into ${shardddl1}.${tb1} (id) values(8);"
   336  	run_sql_source2 "insert into ${shardddl1}.${tb2} (id) values(9);"
   337  	sleep 1
   338  	run_sql_source2 "alter table ${shardddl1}.${tb2} change a new_col datetime default now();"
   339  	run_sql_source1 "insert into ${shardddl1}.${tb1} (id) values(10);"
   340  	run_sql_source2 "insert into ${shardddl1}.${tb1} (id) values(11);"
   341  	run_sql_source2 "insert into ${shardddl1}.${tb2} (id) values(12);"
   342  	check_sync_diff $WORK_DIR $cur/conf/diff_config.toml
   343  }
   344  
   345  function DM_059() {
   346  	run_case 059 "double-source-pessimistic" \
   347  		"run_sql_source1 \"create table ${shardddl1}.${tb1} (id int primary key, a datetime);\"; \
   348       run_sql_source2 \"create table ${shardddl1}.${tb1} (id int primary key, a datetime);\"; \
   349       run_sql_source2 \"create table ${shardddl1}.${tb2} (id int primary key, a datetime);\"" \
   350  		"clean_table" "pessimistic"
   351  	run_case 059 "double-source-pessimistic" \
   352  		"run_sql_source1 \"create table ${shardddl1}.${tb1} (id int primary key, a datetime);\"; \
   353       run_sql_source2 \"create table ${shardddl1}.${tb1} (id int primary key, a datetime);\"; \
   354       run_sql_source2 \"create table ${shardddl1}.${tb2} (id int primary key, a datetime);\"" \
   355  		"clean_table" "optimistic"
   356  }
   357  
   358  function DM_062_CASE() {
   359  	run_sql_source1 "alter table ${shardddl1}.${tb1} modify id bigint;"
   360  	run_sql_source1 "insert into ${shardddl1}.${tb1} values(1);"
   361  	run_sql_source2 "insert into ${shardddl1}.${tb1} values(2);"
   362  	run_sql_source2 "insert into ${shardddl1}.${tb2} values(3);"
   363  	run_sql_source2 "alter table ${shardddl1}.${tb1} modify id bigint;"
   364  	run_sql_source1 "insert into ${shardddl1}.${tb1} values(4);"
   365  	run_sql_source2 "insert into ${shardddl1}.${tb1} values(5);"
   366  	run_sql_source2 "insert into ${shardddl1}.${tb2} values(6);"
   367  	run_sql_source2 "alter table ${shardddl1}.${tb2} modify id bigint;"
   368  	run_sql_source1 "insert into ${shardddl1}.${tb1} values(7);"
   369  	run_sql_source2 "insert into ${shardddl1}.${tb1} values(8);"
   370  	run_sql_source2 "insert into ${shardddl1}.${tb2} values(9);"
   371  	check_sync_diff $WORK_DIR $cur/conf/diff_config.toml
   372  }
   373  
   374  function DM_062() {
   375  	run_case 062 "double-source-pessimistic" "init_table 111 211 212" "clean_table" "pessimistic"
   376  	run_case 062 "double-source-optimistic" "init_table 111 211 212" "clean_table" "optimistic"
   377  }
   378  
   379  function DM_063_CASE() {
   380  	run_sql_source1 "alter table ${shardddl1}.${tb1} modify id mediumint;"
   381  	run_sql_source1 "insert into ${shardddl1}.${tb1} values(1);"
   382  	run_sql_source2 "insert into ${shardddl1}.${tb1} values(2);"
   383  	run_sql_source2 "insert into ${shardddl1}.${tb2} values(3);"
   384  
   385  	if [[ "$1" = "optimistic" ]]; then
   386  		# make sure alter column mediumint exec before bigint
   387  		# otherwise will report "Unsupported modify column length is less than origin"
   388  		run_sql_tidb_with_retry "select count(1) from ${shardddl}.${tb};" "count(1): 3"
   389  	fi
   390  
   391  	run_sql_source2 "alter table ${shardddl1}.${tb1} modify id bigint;"
   392  	run_sql_source1 "insert into ${shardddl1}.${tb1} values(4);"
   393  	run_sql_source2 "insert into ${shardddl1}.${tb1} values(5);"
   394  	run_sql_source2 "insert into ${shardddl1}.${tb2} values(6);"
   395  	run_sql_source2 "alter table ${shardddl1}.${tb2} modify id bigint;"
   396  	run_sql_source1 "insert into ${shardddl1}.${tb1} values(7);"
   397  	run_sql_source2 "insert into ${shardddl1}.${tb1} values(8);"
   398  	run_sql_source2 "insert into ${shardddl1}.${tb2} values(9);"
   399  
   400  	if [[ "$1" = "pessimistic" ]]; then
   401  		check_log_contain_with_retry "is different with" $WORK_DIR/master/log/dm-master.log
   402  	else
   403  		# TODO: should detect schema conflict in optimistic mode
   404  		run_sql_tidb_with_retry "select count(1) from ${shardddl}.${tb};" "count(1): 9"
   405  	fi
   406  }
   407  
   408  function DM_063() {
   409  	run_case 063 "double-source-pessimistic" \
   410  		"run_sql_source1 \"create table ${shardddl1}.${tb1} (id smallint primary key);\"; \
   411       run_sql_source2 \"create table ${shardddl1}.${tb1} (id smallint primary key);\"; \
   412       run_sql_source2 \"create table ${shardddl1}.${tb2} (id smallint primary key);\"" \
   413  		"clean_table" "pessimistic"
   414  	run_case 063 "double-source-optimistic" \
   415  		"run_sql_source1 \"create table ${shardddl1}.${tb1} (id smallint primary key);\"; \
   416       run_sql_source2 \"create table ${shardddl1}.${tb1} (id smallint primary key);\"; \
   417       run_sql_source2 \"create table ${shardddl1}.${tb2} (id smallint primary key);\"" \
   418  		"clean_table" "optimistic"
   419  }
   420  
   421  function DM_064_CASE() {
   422  	run_sql_source1 "alter table ${shardddl1}.${tb1} modify id int(30);"
   423  	run_sql_source1 "insert into ${shardddl1}.${tb1} values(1);"
   424  	run_sql_source2 "insert into ${shardddl1}.${tb1} values(2);"
   425  	run_sql_source2 "insert into ${shardddl1}.${tb2} values(3);"
   426  	run_sql_source2 "alter table ${shardddl1}.${tb1} modify id int(30);"
   427  	run_sql_source1 "insert into ${shardddl1}.${tb1} values(4);"
   428  	run_sql_source2 "insert into ${shardddl1}.${tb1} values(5);"
   429  	run_sql_source2 "insert into ${shardddl1}.${tb2} values(6);"
   430  	run_sql_source2 "alter table ${shardddl1}.${tb2} modify id int(30);"
   431  	run_sql_source1 "insert into ${shardddl1}.${tb1} values(7);"
   432  	run_sql_source2 "insert into ${shardddl1}.${tb1} values(8);"
   433  	run_sql_source2 "insert into ${shardddl1}.${tb2} values(9);"
   434  	check_sync_diff $WORK_DIR $cur/conf/diff_config.toml
   435  }
   436  
   437  function DM_064() {
   438  	run_case 064 "double-source-pessimistic" "init_table 111 211 212" "clean_table" "pessimistic"
   439  	run_case 064 "double-source-optimistic" "init_table 111 211 212" "clean_table" "optimistic"
   440  }
   441  
   442  function DM_065_CASE() {
   443  	run_sql_source1 "alter table ${shardddl1}.${tb1} modify a bigint after b;"
   444  	run_sql_source1 "insert into ${shardddl1}.${tb1} values(1,1);"
   445  	run_sql_source2 "insert into ${shardddl1}.${tb1} values(2,2);"
   446  	run_sql_source2 "insert into ${shardddl1}.${tb2} values(3,3);"
   447  	run_sql_source2 "alter table ${shardddl1}.${tb1} modify a bigint first;"
   448  	run_sql_source1 "insert into ${shardddl1}.${tb1} values(4,4);"
   449  	run_sql_source2 "insert into ${shardddl1}.${tb1} values(5,5);"
   450  	run_sql_source2 "insert into ${shardddl1}.${tb2} values(6,6);"
   451  	run_sql_source2 "alter table ${shardddl1}.${tb2} modify a bigint first;"
   452  	run_sql_source1 "insert into ${shardddl1}.${tb1} values(7,7);"
   453  	run_sql_source2 "insert into ${shardddl1}.${tb1} values(8,8);"
   454  	run_sql_source2 "insert into ${shardddl1}.${tb2} values(9,9);"
   455  
   456  	if [[ "$1" = "pessimistic" ]]; then
   457  		check_log_contain_with_retry "is different with" $WORK_DIR/master/log/dm-master.log
   458  	else
   459  		run_sql_tidb_with_retry "select count(1) from ${shardddl}.${tb};" "count(1): 9"
   460  	fi
   461  }
   462  
   463  function DM_065() {
   464  	run_case 065 "double-source-pessimistic" \
   465  		"run_sql_source1 \"create table ${shardddl1}.${tb1} (a int primary key, b int);\"; \
   466       run_sql_source2 \"create table ${shardddl1}.${tb1} (a int primary key, b int);\"; \
   467       run_sql_source2 \"create table ${shardddl1}.${tb2} (a int primary key, b int);\"" \
   468  		"clean_table" "pessimistic"
   469  	run_case 065 "double-source-optimistic" \
   470  		"run_sql_source1 \"create table ${shardddl1}.${tb1} (a int primary key, b int);\"; \
   471       run_sql_source2 \"create table ${shardddl1}.${tb1} (a int primary key, b int);\"; \
   472       run_sql_source2 \"create table ${shardddl1}.${tb2} (a int primary key, b int);\"" \
   473  		"clean_table" "optimistic"
   474  }
   475  
   476  function DM_066_CASE() {
   477  	run_sql_source1 "alter table ${shardddl1}.${tb1} modify id int default 1;"
   478  	run_sql_source1 "insert into ${shardddl1}.${tb1} values(1);"
   479  	run_sql_source2 "insert into ${shardddl1}.${tb1} values(2);"
   480  	run_sql_source2 "insert into ${shardddl1}.${tb2} values(3);"
   481  	run_sql_source2 "alter table ${shardddl1}.${tb1} modify id int default 1;"
   482  	run_sql_source1 "insert into ${shardddl1}.${tb1} values(4);"
   483  	run_sql_source2 "insert into ${shardddl1}.${tb1} values(5);"
   484  	run_sql_source2 "insert into ${shardddl1}.${tb2} values(6);"
   485  	run_sql_source2 "alter table ${shardddl1}.${tb2} modify id int default 1;"
   486  	run_sql_source1 "insert into ${shardddl1}.${tb1} values(7);"
   487  	run_sql_source2 "insert into ${shardddl1}.${tb1} values(8);"
   488  	run_sql_source2 "insert into ${shardddl1}.${tb2} values(9);"
   489  	check_sync_diff $WORK_DIR $cur/conf/diff_config.toml
   490  }
   491  
   492  function DM_066() {
   493  	run_case 066 "double-source-pessimistic" "init_table 111 211 212" "clean_table" "pessimistic"
   494  	run_case 066 "double-source-optimistic" "init_table 111 211 212" "clean_table" "optimistic"
   495  }
   496  
   497  function DM_067_CASE() {
   498  	run_sql_source1 "alter table ${shardddl1}.${tb1} modify id int default 1;"
   499  	run_sql_source1 "insert into ${shardddl1}.${tb1} values(1);"
   500  	run_sql_source2 "insert into ${shardddl1}.${tb1} values(2);"
   501  	run_sql_source2 "insert into ${shardddl1}.${tb2} values(3);"
   502  	if [[ "$1" = "optimistic" ]]; then
   503  		relate_worker=$($PWD/bin/dmctl.test DEVEL --master-addr "127.0.0.1:$MASTER_PORT1" operate-source show -s "mysql-replica-01" |
   504  			grep 'worker' | awk -F: '{print $2}' | cut -d'"' -f 2)
   505  		# make sure in skip and wait redirect
   506  		check_log_contain_with_retry 'got a shard DDL lock operation.*MODIFY COLUMN `id` INT' $WORK_DIR/$relate_worker/log/dm-worker.log
   507  	fi
   508  	run_sql_source2 "alter table ${shardddl1}.${tb1} modify id int default 2;"
   509  	run_sql_source1 "insert into ${shardddl1}.${tb1} values(4);"
   510  	run_sql_source2 "insert into ${shardddl1}.${tb1} values(5);"
   511  	run_sql_source2 "insert into ${shardddl1}.${tb2} values(6);"
   512  	run_sql_source2 "alter table ${shardddl1}.${tb2} modify id int default 2;"
   513  	run_sql_source1 "insert into ${shardddl1}.${tb1} values(7);"
   514  	run_sql_source2 "insert into ${shardddl1}.${tb1} values(8);"
   515  	run_sql_source2 "insert into ${shardddl1}.${tb2} values(9);"
   516  
   517  	if [[ "$1" = "pessimistic" ]]; then
   518  		check_log_contain_with_retry "is different with" $WORK_DIR/master/log/dm-master.log
   519  	else
   520  		run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
   521  			"query-status test" \
   522  			'ALTER TABLE `shardddl`.`tb` MODIFY COLUMN `id` INT DEFAULT 2' 1 \
   523  			"\"${SOURCE_ID2}-\`${shardddl1}\`.\`${tb1}\`\"" 1
   524  	fi
   525  }
   526  
   527  function DM_067() {
   528  	run_case 067 "double-source-pessimistic" "init_table 111 211 212" "clean_table" "pessimistic"
   529  	run_case 067 "double-source-optimistic" "init_table 111 211 212" "clean_table" "optimistic"
   530  }
   531  
   532  function DM_068_CASE {
   533  	run_sql_source1 "alter table ${shardddl1}.${tb1} modify id datetime default now();"
   534  	run_sql_source1 "insert into ${shardddl1}.${tb1} values(1,now());"
   535  	run_sql_source2 "insert into ${shardddl1}.${tb1} values(2,now());"
   536  	run_sql_source2 "insert into ${shardddl1}.${tb2} values(3,now());"
   537  	run_sql_source2 "alter table ${shardddl1}.${tb1} modify id datetime default now();"
   538  	run_sql_source1 "insert into ${shardddl1}.${tb1} values(4,now());"
   539  	run_sql_source2 "insert into ${shardddl1}.${tb1} values(5,now());"
   540  	run_sql_source2 "insert into ${shardddl1}.${tb2} values(6,now());"
   541  	run_sql_source2 "alter table ${shardddl1}.${tb2} modify id datetime default now();"
   542  	run_sql_source1 "insert into ${shardddl1}.${tb1} values(7,now());"
   543  	run_sql_source2 "insert into ${shardddl1}.${tb1} values(8,now());"
   544  	run_sql_source2 "insert into ${shardddl1}.${tb2} values(9,now());"
   545  	check_sync_diff $WORK_DIR $cur/conf/diff_config.toml
   546  }
   547  
   548  function DM_068() {
   549  	run_case 068 "double-source-pessimistic" \
   550  		"run_sql_source1 \"create table ${shardddl1}.${tb1} (a int primary key, id datetime);\"; \
   551       run_sql_source2 \"create table ${shardddl1}.${tb1} (a int primary key, id datetime);\"; \
   552       run_sql_source2 \"create table ${shardddl1}.${tb2} (a int primary key, id datetime);\"" \
   553  		"clean_table" "pessimistic"
   554  	run_case 068 "double-source-optimistic" \
   555  		"run_sql_source1 \"create table ${shardddl1}.${tb1} (a int primary key, id datetime);\"; \
   556       run_sql_source2 \"create table ${shardddl1}.${tb1} (a int primary key, id datetime);\"; \
   557       run_sql_source2 \"create table ${shardddl1}.${tb2} (a int primary key, id datetime);\"" \
   558  		"clean_table" "optimistic"
   559  }
   560  
   561  function restart_worker() {
   562  	echo "restart dm-worker" $1
   563  	if [[ "$1" = "1" ]]; then
   564  		kill_process dm-worker1
   565  		check_port_offline $WORKER1_PORT 20
   566  	else
   567  		kill_process dm-worker2
   568  		check_port_offline $WORKER2_PORT 20
   569  	fi
   570  	export GO_FAILPOINTS=$2
   571  
   572  	if [[ "$1" = "1" ]]; then
   573  		run_dm_worker $WORK_DIR/worker1 $WORKER1_PORT $cur/conf/dm-worker1.toml
   574  		check_rpc_alive $cur/../bin/check_worker_online 127.0.0.1:$WORKER1_PORT
   575  	else
   576  		run_dm_worker $WORK_DIR/worker2 $WORKER2_PORT $cur/conf/dm-worker2.toml
   577  		check_rpc_alive $cur/../bin/check_worker_online 127.0.0.1:$WORKER2_PORT
   578  	fi
   579  }
   580  
   581  function run() {
   582  	init_cluster
   583  	init_database
   584  	start=46
   585  	end=70
   586  	except=(052 053 054 055 060 061 069 070)
   587  	for i in $(seq -f "%03g" ${start} ${end}); do
   588  		if [[ ${except[@]} =~ $i ]]; then
   589  			continue
   590  		fi
   591  		DM_${i}
   592  		sleep 1
   593  	done
   594  }
   595  
   596  cleanup_data $shardddl
   597  cleanup_data $shardddl1
   598  cleanup_data $shardddl2
   599  # also cleanup dm processes in case of last run failed
   600  cleanup_process $*
   601  run $*
   602  cleanup_process $*
   603  
   604  echo "[$(date)] <<<<<< test case $TEST_NAME success! >>>>>>"