github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/dm/tests/handle_error_2/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  source $cur/../_utils/handle_error_lib.sh
     8  WORK_DIR=$TEST_DIR/$TEST_NAME
     9  
    10  # 4215, 4217
    11  function DM_4215_CASE() {
    12  	run_sql_source1 "insert into ${db}.${tb1} values(1);"
    13  	run_sql_source2 "insert into ${db}.${tb1} values(2);"
    14  	run_sql_source1 "alter table ${db}.${tb1} add column c int unique;"
    15  	check_log_contain_with_retry 'add column c int unique' $WORK_DIR/worker1/log/dm-worker.log
    16  	run_sql_source2 "alter table ${db}.${tb1} add column c int unique;"
    17  	run_sql_source1 "alter table ${db}.${tb1} add column d int unique;"
    18  	run_sql_source2 "alter table ${db}.${tb1} add column d int unique;"
    19  
    20  	if [[ "$1" = "pessimistic" ]]; then
    21  		run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
    22  			"query-status test" \
    23  			'"ErrScope": "downstream"' 1 \
    24  			"unsupported add column 'c' constraint UNIQUE KEY" 1
    25  	else
    26  		run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
    27  			"query-status test" \
    28  			'"ErrScope": "downstream"' 2 \
    29  			"unsupported add column 'c' constraint UNIQUE KEY" 2
    30  	fi
    31  
    32  	run_sql_tidb "alter table ${db}.${tb} add column c int; alter table ${db}.${tb} add unique (c);"
    33  
    34  	if [[ "$1" = "pessimistic" ]]; then
    35  		# unlock for non DDL lock owner
    36  		run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
    37  			"unlock-ddl-lock test-\`handle_error\`.\`tb\` --force-remove"
    38  		# skip for DDL lock owner
    39  		run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
    40  			"binlog skip test -s $source1" \
    41  			"\"result\": true" 2
    42  	else
    43  		run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
    44  			"binlog skip test" \
    45  			"\"result\": true" 3
    46  	fi
    47  
    48  	run_sql_source1 "insert into ${db}.${tb1} values(3,3,3);"
    49  
    50  	if [[ "$1" = "pessimistic" ]]; then
    51  		run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
    52  			"query-status test" \
    53  			'"ErrScope": "downstream"' 1 \
    54  			"unsupported add column 'd' constraint UNIQUE KEY" 1
    55  	else
    56  		run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
    57  			"query-status test" \
    58  			'"ErrScope": "downstream"' 2 \
    59  			"unsupported add column 'd' constraint UNIQUE KEY" 2
    60  	fi
    61  
    62  	run_sql_tidb "alter table ${db}.${tb} add column d int; alter table ${db}.${tb} add unique (d);"
    63  	if [[ "$1" = "pessimistic" ]]; then
    64  		# unlock for non DDL lock owner
    65  		run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
    66  			"unlock-ddl-lock test-\`handle_error\`.\`tb\` --force-remove"
    67  		# skip for DDL lock owner
    68  		run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
    69  			"binlog skip test" \
    70  			"\"result\": true" 2
    71  	else
    72  		run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
    73  			"binlog skip test" \
    74  			"\"result\": true" 3
    75  	fi
    76  
    77  	run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
    78  		"query-status test" \
    79  		"\"result\": true" 3
    80  
    81  	run_sql_source2 "insert into ${db}.${tb1} values(4,4,4);"
    82  
    83  	run_sql_tidb_with_retry "select count(1) from ${db}.${tb};" "count(1): 4"
    84  }
    85  
    86  function DM_4215() {
    87  	run_case 4215 "double-source-pessimistic" "init_table 11 21" "clean_table" "pessimistic"
    88  	run_case 4215 "double-source-optimistic" "init_table 11 21" "clean_table" "optimistic"
    89  }
    90  
    91  function DM_4216_CASE() {
    92  	run_sql_source1 "insert into ${db}.${tb1} values(1);"
    93  	run_sql_source2 "insert into ${db}.${tb1} values(2);"
    94  	run_sql_source1 "alter table ${db}.${tb1} add column c varchar(20) character set utf32;"
    95  	run_sql_source2 "alter table ${db}.${tb1} add column c varchar(20) character set utf32;"
    96  
    97  	run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
    98  		"query-status test" \
    99  		"Unknown character set" 2
   100  
   101  	start_location1=$(get_start_location 127.0.0.1:$MASTER_PORT $source1)
   102  	start_location2=$(get_start_location 127.0.0.1:$MASTER_PORT $source2)
   103  
   104  	if [ "$start_location1" = "$start_location2" ]; then
   105  		run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
   106  			"binlog replace test -b $start_location1 alter table ${db}.${tb1} add column c varchar(20);" \
   107  			"\"result\": true" 3
   108  	else
   109  		# WARN: may replace unknown event like later insert, test will fail
   110  		# It hasn't happened yet.
   111  		run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
   112  			"binlog replace test -b $start_location1 alter table ${db}.${tb1} add column c varchar(20);" \
   113  			"\"result\": true" 3
   114  
   115  		run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
   116  			"query-status test" \
   117  			"Unknown character set" 1
   118  
   119  		run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
   120  			"binlog replace test -b $start_location2 alter table ${db}.${tb1} add column c varchar(20);" \
   121  			"\"result\": true" 3
   122  	fi
   123  
   124  	run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
   125  		"query-status test" \
   126  		"\"result\": true" 3
   127  
   128  	run_sql_source1 "insert into ${db}.${tb1} values(3,3);"
   129  	run_sql_source2 "insert into ${db}.${tb1} values(4,4);"
   130  
   131  	run_sql_tidb_with_retry "select count(1) from ${db}.${tb} where id<100;" "count(1): 4"
   132  }
   133  
   134  function DM_4216() {
   135  	run_case 4216 "double-source-pessimistic" "init_table 11 21" "clean_table" "pessimistic"
   136  	run_case 4216 "double-source-optimistic" "init_table 11 21" "clean_table" "optimistic"
   137  
   138  	# test different error locations
   139  	run_case 4216 "double-source-pessimistic" "init_table 11 21;run_sql_source1 \"insert into ${db}.${tb1} values(100);\"" "clean_table" "pessimistic"
   140  	run_case 4216 "double-source-optimistic" "init_table 11 21;run_sql_source1 \"insert into ${db}.${tb1} values(100);\"" "clean_table" "optimistic"
   141  }
   142  
   143  function DM_4219_CASE() {
   144  	run_sql_source1 "insert into ${db}.${tb1} values(1);"
   145  	run_sql_source2 "insert into ${db}.${tb1} values(2);"
   146  	run_sql_source1 "alter table ${db}.${tb1} add column c varchar(20) character set utf32;"
   147  	run_sql_source2 "alter table ${db}.${tb1} add column c varchar(20) character set utf32;"
   148  
   149  	run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
   150  		"query-status test" \
   151  		"Unknown character set" 2
   152  
   153  	run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
   154  		"binlog replace test -s $source1 alter table ${db}.${tb1} add column c varchar(20);" \
   155  		"\"result\": true" 2
   156  
   157  	run_sql_source1 "insert into ${db}.${tb1} values(3,3);"
   158  
   159  	run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
   160  		"query-status test" \
   161  		"Unknown character set" 1
   162  
   163  	run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
   164  		"binlog replace test -s $source2 alter table ${db}.${tb1} add column c varchar(20);" \
   165  		"\"result\": true" 2
   166  
   167  	run_sql_source2 "insert into ${db}.${tb1} values(4,4);"
   168  
   169  	run_sql_tidb_with_retry "select count(1) from ${db}.${tb};" "count(1): 4"
   170  }
   171  
   172  function DM_4219() {
   173  	run_case 4219 "double-source-pessimistic" "init_table 11 21" "clean_table" "pessimistic"
   174  	run_case 4219 "double-source-optimistic" "init_table 11 21" "clean_table" "optimistic"
   175  }
   176  
   177  # 4220, 4224, 4226, 4229, 4194, 4195, 4196
   178  function DM_4220_CASE() {
   179  	run_sql_source1 "insert into ${db}.${tb1} values(1);"
   180  	run_sql_source2 "insert into ${db}.${tb1} values(2);"
   181  	run_sql_source1 "alter table ${db}.${tb1} modify id varchar(10);"
   182  	run_sql_source1 "alter table ${db}.${tb1} modify id varchar(20);"
   183  	run_sql_source1 "alter table ${db}.${tb1} modify id varchar(30);"
   184  	run_sql_source2 "alter table ${db}.${tb1} modify id varchar(10);"
   185  	run_sql_source2 "alter table ${db}.${tb1} modify id varchar(20);"
   186  	run_sql_source2 "alter table ${db}.${tb1} modify id varchar(30);"
   187  
   188  	run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
   189  		"query-status test" \
   190  		"Unsupported modify column: this column has primary key flag" 2
   191  
   192  	run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
   193  		"binlog revert test" \
   194  		"operator not exist" 2
   195  
   196  	first_pos1=$(get_start_pos 127.0.0.1:$MASTER_PORT $source1)
   197  	first_pos2=$(get_start_pos 127.0.0.1:$MASTER_PORT $source2)
   198  	first_name1=$(get_start_name 127.0.0.1:$MASTER_PORT $source1)
   199  	first_name2=$(get_start_name 127.0.0.1:$MASTER_PORT $source2)
   200  
   201  	second_pos1=$(get_next_query_pos $MYSQL_PORT1 $MYSQL_PASSWORD1 $first_pos1)
   202  	second_pos2=$(get_next_query_pos $MYSQL_PORT2 $MYSQL_PASSWORD2 $first_pos2)
   203  	third_pos1=$(get_next_query_pos $MYSQL_PORT1 $MYSQL_PASSWORD1 $second_pos1)
   204  	third_pos2=$(get_next_query_pos $MYSQL_PORT2 $MYSQL_PASSWORD2 $second_pos2)
   205  
   206  	run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
   207  		"binlog skip test -s $source1 -b $first_name1:$second_pos1" \
   208  		"\"result\": true" 2
   209  	run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
   210  		"binlog skip test -s $source2 -b $first_name2:$second_pos2" \
   211  		"\"result\": true" 2
   212  
   213  	run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
   214  		"query-status test" \
   215  		"Unsupported modify column: this column has primary key flag" 2
   216  
   217  	run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
   218  		"binlog revert test" \
   219  		"operator not exist" 2
   220  
   221  	run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
   222  		"binlog skip test -s $source1 -b $first_name1:$third_pos1" \
   223  		"\"result\": true" 2
   224  	run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
   225  		"binlog skip test -s $source2 -b $first_name2:$third_pos2" \
   226  		"\"result\": true" 2
   227  
   228  	run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
   229  		"query-status test" \
   230  		"Unsupported modify column: this column has primary key flag" 2
   231  
   232  	run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
   233  		"binlog revert test -s $source1 -b $first_name1:$third_pos1" \
   234  		"\"result\": true" 2
   235  	run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
   236  		"binlog revert test -s $source2 -b $first_name2:$third_pos2" \
   237  		"\"result\": true" 2
   238  
   239  	run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
   240  		"query-status test" \
   241  		"Unsupported modify column: this column has primary key flag" 2
   242  
   243  	run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
   244  		"binlog skip test" \
   245  		"\"result\": true" 3
   246  
   247  	run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
   248  		"query-status test" \
   249  		"Unsupported modify column: this column has primary key flag" 2
   250  
   251  	run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
   252  		"binlog skip test" \
   253  		"\"result\": true" 3
   254  
   255  	# flush checkpoint, otherwise revert may "succeed"
   256  	run_sql_source1 "alter table ${db}.${tb1} add column new_col int;"
   257  	run_sql_source2 "alter table ${db}.${tb1} add column new_col int;"
   258  
   259  	run_sql_source1 "insert into ${db}.${tb1} values(3,3);"
   260  	run_sql_source2 "insert into ${db}.${tb1} values(4,4);"
   261  	run_sql_tidb_with_retry "select count(1) from ${db}.${tb};" "count(1): 4"
   262  
   263  	run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
   264  		"binlog revert test -s $source1 -b $first_name1:$third_pos1" \
   265  		"operator not exist" 1
   266  	run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
   267  		"binlog revert test -s $source2 -b $first_name2:$third_pos2" \
   268  		"operator not exist" 1
   269  	run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
   270  		"binlog revert test -b $first_name2:$third_pos2" \
   271  		"operator not exist" 2
   272  
   273  	run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
   274  		"binlog revert test" \
   275  		"source.*has no error" 2
   276  
   277  	run_sql_source1 "insert into ${db}.${tb1} values(5,5);"
   278  	run_sql_source2 "insert into ${db}.${tb1} values(6,6);"
   279  
   280  	run_sql_tidb_with_retry "select count(1) from ${db}.${tb};" "count(1): 6"
   281  }
   282  
   283  function DM_4220() {
   284  	run_case 4220 "double-source-pessimistic" "init_table 11 21" "clean_table" "pessimistic"
   285  	run_case 4220 "double-source-optimistic" "init_table 11 21" "clean_table" "optimistic"
   286  }
   287  
   288  # 4185, 4187, 4186
   289  function DM_4185_CASE() {
   290  	run_sql_source1 "insert into ${db}.${tb1} values(1);"
   291  	run_sql_source2 "insert into ${db}.${tb1} values(2);"
   292  	run_sql_source1 "alter table ${db}.${tb1} modify id varchar(10);"
   293  	run_sql_source2 "alter table ${db}.${tb1} modify id varchar(10);"
   294  	run_sql_source1 "alter table ${db}.${tb1} modify id varchar(20);"
   295  	run_sql_source2 "alter table ${db}.${tb1} modify id varchar(20);"
   296  
   297  	run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
   298  		"query-status test" \
   299  		"Unsupported modify column: this column has primary key flag" 2
   300  
   301  	first_pos1=$(get_start_pos 127.0.0.1:$MASTER_PORT $source1)
   302  	first_pos2=$(get_start_pos 127.0.0.1:$MASTER_PORT $source2)
   303  	first_name1=$(get_start_name 127.0.0.1:$MASTER_PORT $source1)
   304  	first_name2=$(get_start_name 127.0.0.1:$MASTER_PORT $source2)
   305  	second_pos1=$(get_next_query_pos $MYSQL_PORT1 $MYSQL_PASSWORD1 $first_pos1)
   306  	second_pos2=$(get_next_query_pos $MYSQL_PORT2 $MYSQL_PASSWORD2 $first_pos2)
   307  
   308  	if [ "$second_pos1" = "$second_pos2" ]; then
   309  		run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
   310  			"binlog skip test -b $first_name1:$second_pos1" \
   311  			"\"result\": true" 3
   312  	else
   313  		# WARN: may skip unknown event like later insert, test will fail
   314  		# It hasn't happened yet.
   315  		run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
   316  			"binlog skip test -b $first_name1:$second_pos1" \
   317  			"\"result\": true" 3
   318  
   319  		run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
   320  			"query-status test" \
   321  			"Unsupported modify column: this column has primary key flag" 2
   322  
   323  		run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
   324  			"binlog skip test -b $first_name1:$second_pos2" \
   325  			"\"result\": true" 3
   326  	fi
   327  
   328  	run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
   329  		"query-status test" \
   330  		"Unsupported modify column: this column has primary key flag" 2
   331  
   332  	run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
   333  		"binlog skip test" \
   334  		"\"result\": true" 3
   335  
   336  	run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
   337  		"query-status test" \
   338  		"\"result\": true" 3
   339  
   340  	run_sql_source1 "insert into ${db}.${tb1} values(3);"
   341  	run_sql_source2 "insert into ${db}.${tb1} values(4);"
   342  
   343  	run_sql_tidb_with_retry "select count(1) from ${db}.${tb} where id<100;" "count(1): 4"
   344  }
   345  
   346  function DM_4185() {
   347  	run_case 4185 "double-source-pessimistic" "init_table 11 21" "clean_table" "pessimistic"
   348  	run_case 4185 "double-source-optimistic" "init_table 11 21" "clean_table" "optimistic"
   349  
   350  	# test different error locations
   351  	run_case 4185 "double-source-pessimistic" "init_table 11 21;run_sql_source1 \"insert into ${db}.${tb1} values(100);\"" "clean_table" "pessimistic"
   352  	run_case 4185 "double-source-optimistic" "init_table 11 21;run_sql_source1 \"insert into ${db}.${tb1} values(100);\"" "clean_table" "optimistic"
   353  }
   354  
   355  # 4201, 4203, 4205
   356  function DM_4201_CASE() {
   357  	run_sql_source1 "insert into ${db}.${tb1} values(1);"
   358  	run_sql_source1 "alter table ${db}.${tb1} modify id varchar(10);"
   359  	run_sql_source1 "alter table ${db}.${tb1} modify id varchar(20);"
   360  
   361  	run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
   362  		"query-status test" \
   363  		"Unsupported modify column: this column has primary key flag" 1
   364  
   365  	first_pos1=$(get_start_pos 127.0.0.1:$MASTER_PORT $source1)
   366  	first_name1=$(get_start_name 127.0.0.1:$MASTER_PORT $source1)
   367  	second_pos1=$(get_next_query_pos $MYSQL_PORT1 $MYSQL_PASSWORD1 $first_pos1)
   368  
   369  	run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
   370  		"binlog skip test -b $first_name1:$second_pos1" \
   371  		"\"result\": true" 2
   372  
   373  	run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
   374  		"query-status test" \
   375  		"Unsupported modify column: this column has primary key flag" 1
   376  
   377  	run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
   378  		"binlog skip test" \
   379  		"\"result\": true" 2
   380  
   381  	run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
   382  		"query-status test" \
   383  		"\"result\": true" 2
   384  
   385  	run_sql_source1 "insert into ${db}.${tb1} values(2);"
   386  
   387  	run_sql_tidb_with_retry "select count(1) from ${db}.${tb} where id<100;" "count(1): 2"
   388  }
   389  
   390  function DM_4201() {
   391  	run_case 4201 "single-source-no-sharding" "init_table 11" "clean_table" ""
   392  }
   393  
   394  function run() {
   395  	init_cluster
   396  	init_database
   397  
   398  	implement=(4215 4216 4219 4220 4185 4201)
   399  	for i in ${implement[@]}; do
   400  		DM_${i}
   401  		sleep 1
   402  	done
   403  }
   404  
   405  cleanup_data $db
   406  # also cleanup dm processes in case of last run failed
   407  cleanup_process $*
   408  run $*
   409  cleanup_process $*
   410  
   411  echo "[$(date)] <<<<<< test case $TEST_NAME success! >>>>>>"