github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/dm/tests/shardddl1_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_006_CASE() { 11 run_sql_source1 "alter table ${shardddl1}.${tb1} add column new_col1 int;" 12 run_sql_source1 "insert into ${shardddl1}.${tb1} values (1,1)" 13 run_sql_source2 "alter table ${shardddl1}.${tb1} add column new_col1 int;" 14 run_sql_source2 "insert into ${shardddl1}.${tb1} values (2,2)" 15 check_sync_diff $WORK_DIR $cur/conf/diff_config.toml 16 } 17 18 function DM_006() { 19 run_case 006 "double-source-pessimistic" "init_table 111 211" "clean_table" "" 20 } 21 22 function DM_007_CASE() { 23 run_sql_source1 "alter table ${shardddl1}.${tb1} add column new_col1 int;" 24 run_sql_source1 "insert into ${shardddl1}.${tb1} values (1,1)" 25 run_sql_source2 "alter table ${shardddl1}.${tb2} add column new_col1 int;" 26 run_sql_source2 "insert into ${shardddl1}.${tb2} values (2,2)" 27 check_sync_diff $WORK_DIR $cur/conf/diff_config.toml 28 } 29 30 function DM_007() { 31 run_case 007 "double-source-pessimistic" "init_table 111 212" "clean_table" "" 32 } 33 34 function DM_008_CASE() { 35 run_sql_source1 "alter table ${shardddl1}.${tb1} add column new_col1 int;" 36 run_sql_source1 "insert into ${shardddl1}.${tb1} values (1,1)" 37 run_sql_source2 "alter table ${shardddl2}.${tb1} add column new_col1 int;" 38 run_sql_source2 "insert into ${shardddl2}.${tb1} values (2,2)" 39 check_sync_diff $WORK_DIR $cur/conf/diff_config.toml 40 } 41 42 function DM_008() { 43 run_case 008 "double-source-pessimistic" "init_table 111 221" "clean_table" "" 44 } 45 46 function DM_009_CASE() { 47 run_sql_source1 "alter table ${shardddl1}.${tb1} add column new_col1 int;" 48 run_sql_source1 "insert into ${shardddl1}.${tb1} values (1,1)" 49 run_sql_source2 "alter table ${shardddl2}.${tb2} add column new_col1 int;" 50 run_sql_source2 "insert into ${shardddl2}.${tb2} values (2,2)" 51 check_sync_diff $WORK_DIR $cur/conf/diff_config.toml 52 } 53 54 function DM_009() { 55 run_case 009 "double-source-pessimistic" "init_table 111 222" "clean_table" "" 56 } 57 58 function DM_010_CASE() { 59 run_sql_source1 "alter table ${shardddl1}.${tb1} add column new_col1 int;" 60 run_sql_source1 "insert into ${shardddl1}.${tb1} values (1,1)" 61 run_sql_source1 "alter table ${shardddl1}.${tb1} add column new_col2 int;" 62 run_sql_source1 "insert into ${shardddl1}.${tb1} values (2,2,2)" 63 run_sql_source1 "alter table ${shardddl1}.${tb2} add column new_col1 int;" 64 run_sql_source1 "insert into ${shardddl1}.${tb2} values (3,3)" 65 run_sql_source1 "alter table ${shardddl1}.${tb2} add column new_col2 int;" 66 run_sql_source1 "insert into ${shardddl1}.${tb2} values (4,4,4)" 67 check_sync_diff $WORK_DIR $cur/conf/diff_config.toml 68 } 69 70 function DM_010() { 71 run_case 010 "single-source-pessimistic" "init_table 111 112" "clean_table" "" 72 } 73 74 function DM_011_CASE() { 75 run_sql_source1 "alter table ${shardddl1}.${tb1} add column new_col1 int;" 76 run_sql_source1 "insert into ${shardddl1}.${tb1} values (1,1)" 77 run_sql_source1 "alter table ${shardddl1}.${tb1} add column new_col2 int;" 78 run_sql_source1 "insert into ${shardddl1}.${tb1} values (2,2,2)" 79 run_sql_source2 "alter table ${shardddl1}.${tb1} add column new_col1 float;" 80 run_sql_source2 "insert into ${shardddl1}.${tb1} values (3,3.0)" 81 run_sql_source2 "alter table ${shardddl1}.${tb1} add column new_col2 float;" 82 run_sql_source2 "insert into ${shardddl1}.${tb1} values (4,4.0,4.0)" 83 check_log_contain_with_retry "is different with" $WORK_DIR/master/log/dm-master.log 84 } 85 86 function DM_011() { 87 run_case 011 "double-source-pessimistic" "init_table 111 211" "clean_table" "" 88 } 89 90 function DM_012_CASE() { 91 run_sql_source1 "alter table ${shardddl1}.${tb1} add column new_col1 int;" 92 run_sql_source1 "insert into ${shardddl1}.${tb1} values (1,1)" 93 run_sql_source1 "alter table ${shardddl1}.${tb1} add column new_col2 int;" 94 run_sql_source1 "insert into ${shardddl1}.${tb1} values (2,2,2)" 95 run_sql_source2 "alter table ${shardddl1}.${tb1} add column new_col2 int;" 96 run_sql_source2 "insert into ${shardddl1}.${tb1} values (3,3)" 97 run_sql_source2 "alter table ${shardddl1}.${tb1} add column new_col1 int;" 98 run_sql_source2 "insert into ${shardddl1}.${tb1} values (4,4,4)" 99 check_log_contain_with_retry "is different with" $WORK_DIR/master/log/dm-master.log 100 } 101 102 function DM_012() { 103 run_case 012 "double-source-pessimistic" "init_table 111 211" "clean_table" "" 104 } 105 function DM_013_CASE() { 106 run_sql_source1 "alter table ${shardddl1}.${tb1} add column new_col1 int;" 107 run_sql_source1 "insert into ${shardddl1}.${tb1} values (1,1)" 108 run_sql_source1 "alter table ${shardddl1}.${tb1} add column new_col2 int;" 109 run_sql_source1 "insert into ${shardddl1}.${tb1} values (2,2,2)" 110 run_sql_source1 "alter table ${shardddl1}.${tb2} add column new_col1 int;" 111 run_sql_source1 "insert into ${shardddl1}.${tb2} values (3,3)" 112 run_sql_source1 "alter table ${shardddl1}.${tb2} add column new_col2 int;" 113 run_sql_source1 "insert into ${shardddl1}.${tb2} values (4,4,4)" 114 check_sync_diff $WORK_DIR $cur/conf/diff_config.toml 115 } 116 117 function DM_013() { 118 run_case 013 "single-source-optimistic" "init_table 111 112" "clean_table" "" 119 } 120 121 function DM_014_CASE() { 122 run_sql_source1 "alter table ${shardddl1}.${tb1} add column new_col1 int;" 123 run_sql_source1 "insert into ${shardddl1}.${tb1} values (1,1)" 124 run_sql_source1 "alter table ${shardddl1}.${tb1} add column new_col2 int;" 125 run_sql_source1 "insert into ${shardddl1}.${tb1} values (2,2,2)" 126 run_sql_source1 "alter table ${shardddl1}.${tb2} add column new_col2 int;" 127 run_sql_source1 "insert into ${shardddl1}.${tb2} values (3,3)" 128 run_sql_source1 "alter table ${shardddl1}.${tb2} add column new_col1 int;" 129 run_sql_source1 "insert into ${shardddl1}.${tb2} values (4,4,4)" 130 run_sql_tidb_with_retry "select count(1) from ${shardddl}.${tb};" "count(1): 4" 131 } 132 133 function DM_014() { 134 run_case 014 "single-source-optimistic" "init_table 111 112" "clean_table" "" 135 } 136 137 function DM_015_CASE() { 138 run_sql_source1 "drop database ${shardddl1};" 139 check_log_contain_with_retry "skip event, need handled ddls is empty" $WORK_DIR/worker1/log/dm-worker.log $WORK_DIR/worker2/log/dm-worker.log 140 run_sql_source1 "create database ${shardddl1};" 141 check_log_contain_with_retry "CREATE DATABASE IF NOT EXISTS \`${shardddl1}\`" $WORK_DIR/worker1/log/dm-worker.log $WORK_DIR/worker2/log/dm-worker.log 142 } 143 144 function DM_015() { 145 run_case 015 "single-source-pessimistic" "init_table 111" "clean_table 111" "" 146 } 147 148 function DM_016_CASE() { 149 run_sql_source1 "drop database ${shardddl1};" 150 check_log_contain_with_retry "skip event, need handled ddls is empty" $WORK_DIR/worker1/log/dm-worker.log $WORK_DIR/worker2/log/dm-worker.log 151 run_sql_source1 "create database if not exists ${shardddl1};" 152 check_log_contain_with_retry "CREATE DATABASE IF NOT EXISTS \`${shardddl1}\`" $WORK_DIR/worker1/log/dm-worker.log $WORK_DIR/worker2/log/dm-worker.log 153 } 154 155 function DM_016() { 156 run_case 016 "single-source-pessimistic" "init_table 111" "clean_table" "" 157 } 158 159 function DM_017_CASE() { 160 run_sql_source1 "drop table ${shardddl1}.${tb1};" 161 check_log_contain_with_retry "skip event, need handled ddls is empty" $WORK_DIR/worker1/log/dm-worker.log $WORK_DIR/worker2/log/dm-worker.log 162 run_sql_source1 "create table ${shardddl1}.${tb1}(id int);" 163 check_log_contain_with_retry "CREATE TABLE IF NOT EXISTS \`${shardddl1}\`.\`${tb1}\` (\`id\` INT)" $WORK_DIR/worker1/log/dm-worker.log $WORK_DIR/worker2/log/dm-worker.log 164 } 165 166 function DM_017() { 167 run_case 017 "single-source-pessimistic" "init_table 111" "clean_table" "" 168 } 169 170 function DM_018_CASE() { 171 run_sql_source1 "drop table ${shardddl1}.${tb1};" 172 check_log_contain_with_retry "skip event, need handled ddls is empty" $WORK_DIR/worker1/log/dm-worker.log $WORK_DIR/worker2/log/dm-worker.log 173 run_sql_source1 "create table if not exists ${shardddl1}.${tb1}(id int);" 174 check_log_contain_with_retry "CREATE TABLE IF NOT EXISTS \`${shardddl1}\`.\`${tb1}\` (\`id\` INT)" $WORK_DIR/worker1/log/dm-worker.log $WORK_DIR/worker2/log/dm-worker.log 175 } 176 177 function DM_018() { 178 run_case 018 "single-source-pessimistic" "init_table 111" "clean_table" "" 179 } 180 181 function DM_019_CASE() { 182 run_sql_source1 "truncate table ${shardddl1}.${tb1};" 183 check_log_contain_with_retry "skip event, need handled ddls is empty" $WORK_DIR/worker1/log/dm-worker.log $WORK_DIR/worker2/log/dm-worker.log 184 } 185 186 function DM_019() { 187 run_case 019 "single-source-pessimistic" "init_table 111" "clean_table" "" 188 run_case 019 "single-source-optimistic" "init_table 111" "clean_table" "" 189 } 190 191 function DM_020_CASE() { 192 run_sql_source1 "rename table ${shardddl1}.${tb1} to ${shardddl1}.${tb2};" 193 run_sql_source1 "insert into ${shardddl1}.${tb2} values (1);" 194 run_sql_tidb_with_retry "show tables from ${shardddl1};" "${tb2}" 195 run_sql_tidb_with_retry "select count(1) from ${shardddl1}.${tb2};" "count(1): 1" 196 } 197 198 function DM_020() { 199 run_case 020 "single-source-no-routes" "init_table 111" "clean_table;run_sql_tidb \"drop database ${shardddl1};\"" "" 200 } 201 202 function DM_021_CASE() { 203 # same as "rename ${shardddl}.${tb} to ${shardddl}.${tb};" 204 run_sql_source1 "rename table ${shardddl1}.${tb1} to ${shardddl1}.${tb2};" 205 check_log_contain_with_retry "Table '${shardddl}.${tb}' already exist" $WORK_DIR/worker1/log/dm-worker.log $WORK_DIR/worker2/log/dm-worker.log 206 } 207 208 function DM_021() { 209 run_case 021 "single-source-pessimistic" "init_table 111" "clean_table" "" 210 } 211 212 function DM_022_CASE() { 213 run_sql_tidb "create table ${shardddl1}.${tb2} (id int);" 214 run_sql_source1 "rename table ${shardddl1}.${tb1} to ${shardddl1}.${tb2};" 215 check_log_contain_with_retry "Table '${shardddl1}.${tb2}' already exists" $WORK_DIR/worker1/log/dm-worker.log $WORK_DIR/worker2/log/dm-worker.log 216 } 217 218 function DM_022() { 219 run_case 022 "single-source-no-routes" "init_table 111" "clean_table;run_sql_tidb \"drop database ${shardddl1};\"" "" 220 } 221 222 function DM_023_CASE() { 223 run_sql_source1 "rename table ${shardddl1}.${tb1} to ${shardddl1}.${tb3}, ${shardddl1}.${tb2} to ${shardddl1}.${tb4};" 224 run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \ 225 "query-status test" \ 226 "rename table .* not supported" 1 227 } 228 229 function DM_023() { 230 run_case 023 "double-source-pessimistic" "init_table 111 112" "clean_table" "" 231 } 232 233 function DM_026_CASE() { 234 run_sql_source1 "insert into ${shardddl1}.${tb1} values (1)" 235 run_sql_source1 "insert into ${shardddl1}.${tb2} values (2)" 236 run_sql_source1 "create table ${shardddl1}.${tb3}(id int primary key);" 237 run_sql_source1 "insert into ${shardddl1}.${tb1} values (3)" 238 run_sql_source1 "insert into ${shardddl1}.${tb2} values (4)" 239 run_sql_source1 "insert into ${shardddl1}.${tb3} values (5)" 240 check_sync_diff $WORK_DIR $cur/conf/diff_config.toml 241 } 242 243 function DM_026() { 244 run_case 026 "single-source-pessimistic" "init_table 111 112" "clean_table" "" 245 } 246 247 function DM_027_CASE() { 248 run_sql_source1 "insert into ${shardddl1}.${tb1} values (1)" 249 run_sql_source1 "insert into ${shardddl1}.${tb2} values (2)" 250 run_sql_source1 "create table ${shardddl1}.${tb3}(id int,val int);" 251 run_sql_source1 "insert into ${shardddl1}.${tb1} values (3)" 252 run_sql_source1 "insert into ${shardddl1}.${tb2} values (4)" 253 run_sql_source1 "insert into ${shardddl1}.${tb3} values (5,6)" 254 run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \ 255 "query-status test" \ 256 "Error 1054 (42S22): Unknown column 'val' in 'field list'" 1 257 } 258 259 function DM_027() { 260 run_case 027 "single-source-pessimistic" "init_table 111 112" "clean_table" "" 261 } 262 263 function DM_028_CASE() { 264 run_sql_source1 "alter table ${shardddl1}.${tb1} drop primary key;" 265 run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \ 266 "query-status test" \ 267 "Unsupported drop primary key" 1 268 } 269 270 function DM_028() { 271 run_sql_tidb "create table ${shardddl}.${tb} (a varchar(10), primary key(a) clustered);" 272 run_case 028 "single-source-pessimistic" "run_sql_source1 \"create table ${shardddl1}.${tb1} (a varchar(10), PRIMARY KEY (a));\"" "clean_table" "" 273 } 274 275 function DM_030_CASE() { 276 run_sql_source1 "alter table ${shardddl1}.${tb1} add new_col1 int;" 277 run_sql_source1 "insert into ${shardddl1}.${tb1} values(1,1);" 278 run_sql_source2 "insert into ${shardddl1}.${tb1} values(2);" 279 run_sql_source2 "alter table ${shardddl1}.${tb1} add new_col1 int;" 280 run_sql_source1 "insert into ${shardddl1}.${tb1} values(3,3);" 281 run_sql_source2 "insert into ${shardddl1}.${tb1} values(4,4);" 282 check_sync_diff $WORK_DIR $cur/conf/diff_config.toml 283 } 284 285 function DM_030() { 286 run_case 030 "double-source-pessimistic" "init_table 111 211" "clean_table" "pessimistic" 287 run_case 030 "double-source-optimistic" "init_table 111 211" "clean_table" "optimistic" 288 } 289 290 function DM_031_CASE() { 291 run_sql_source1 "alter table ${shardddl1}.${tb1} add new_col1 int;" 292 run_sql_source1 "insert into ${shardddl1}.${tb1} values(1,1);" 293 run_sql_source2 "insert into ${shardddl1}.${tb1} values(2);" 294 run_sql_source2 "alter table ${shardddl1}.${tb1} add new_col1 varchar(10);" 295 run_sql_source1 "insert into ${shardddl1}.${tb1} values(3,3);" 296 run_sql_source2 "insert into ${shardddl1}.${tb1} values(4,'dkfj');" 297 if [[ "$1" = "pessimistic" ]]; then 298 check_log_contain_with_retry "is different with" $WORK_DIR/master/log/dm-master.log 299 else 300 run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \ 301 "query-status test" \ 302 'ALTER TABLE `shardddl`.`tb` ADD COLUMN `new_col1`' 1 \ 303 "\`${shardddl1}\`.\`${tb1}\`\"" 1 304 fi 305 } 306 307 function DM_031() { 308 run_case 031 "double-source-pessimistic" "init_table 111 211" "clean_table" "pessimistic" 309 run_case 031 "double-source-optimistic" "init_table 111 211" "clean_table" "optimistic" 310 } 311 312 function DM_032_CASE() { 313 run_sql_source1 "alter table ${shardddl1}.${tb1} add new_col1 int;" 314 run_sql_source1 "insert into ${shardddl1}.${tb1} values(1,1);" 315 run_sql_source1 "alter table ${shardddl1}.${tb1} drop column new_col1;" 316 run_sql_source1 "insert into ${shardddl1}.${tb1} values(2);" 317 run_sql_source1 "alter table ${shardddl1}.${tb1} add new_col2 float;" 318 run_sql_source1 "insert into ${shardddl1}.${tb1} values(3,3.0);" 319 run_sql_source2 "alter table ${shardddl1}.${tb1} add new_col2 float;" 320 run_sql_source1 "insert into ${shardddl1}.${tb1} values(4,4.0);" 321 run_sql_source2 "insert into ${shardddl1}.${tb1} values(5,5.0);" 322 run_sql_source2 "insert into ${shardddl1}.${tb2} values(6);" 323 run_sql_source2 "alter table ${shardddl1}.${tb2} add new_col2 float;" 324 run_sql_source1 "insert into ${shardddl1}.${tb1} values(7,7.0);" 325 run_sql_source2 "insert into ${shardddl1}.${tb1} values(8,8.0);" 326 run_sql_source2 "insert into ${shardddl1}.${tb2} values(9,9.0);" 327 check_sync_diff $WORK_DIR $cur/conf/diff_config.toml 328 } 329 330 function DM_032() { 331 # currently not support pessimistic 332 # run_case 032 "double-source-pessimistic" "init_table 111 211 212" "clean_table" "pessimistic" 333 run_case 032 "double-source-optimistic" "init_table 111 211 212" "clean_table" "optimistic" 334 } 335 336 function DM_033_CASE() { 337 run_sql_source1 "alter table ${shardddl1}.${tb1} add new_col1 int not null;" 338 run_sql_source1 "insert into ${shardddl1}.${tb1} values(1,1,1);" 339 run_sql_source2 "insert into ${shardddl1}.${tb1} values(2,null);" 340 run_sql_source2 "alter table ${shardddl1}.${tb1} add new_col1 int not null;" 341 run_sql_source1 "insert into ${shardddl1}.${tb1} values(3,3,3);" 342 run_sql_source2 "insert into ${shardddl1}.${tb1} values(4,4,4);" 343 run_sql_source2 "insert into ${shardddl1}.${tb2} values(5,null);" 344 run_sql_source2 "alter table ${shardddl1}.${tb2} add new_col1 int not null;" 345 check_sync_diff $WORK_DIR $cur/conf/diff_config.toml 346 } 347 348 function DM_033() { 349 run_case 033 "double-source-pessimistic" \ 350 "run_sql_source1 \"create table ${shardddl1}.${tb1} (a int primary key, b int);\"; \ 351 run_sql_source2 \"create table ${shardddl1}.${tb1} (a int primary key, b int);\"; \ 352 run_sql_source2 \"create table ${shardddl1}.${tb2} (a int primary key, b int);\";" \ 353 "clean_table" "pessimistic" 354 # currently not support optimistic 355 # run_case 033 "double-source-optimistic" \ 356 # "run_sql_source1 \"create table ${shardddl1}.${tb1} (a int primary key, b int);\"; \ 357 # run_sql_source2 \"create table ${shardddl1}.${tb1} (a int primary key, b int);\"; \ 358 # run_sql_source2 \"create table ${shardddl1}.${tb2} (a int primary key, b int);\";" \ 359 # "clean_table" "optimistic" 360 } 361 362 function DM_034_CASE() { 363 run_sql_source1 "alter table ${shardddl1}.${tb1} add new_col1 int unique auto_increment;" 364 run_sql_source1 "insert into ${shardddl1}.${tb1} values(1,0);" 365 run_sql_source2 "insert into ${shardddl1}.${tb1} values(2);" 366 run_sql_source2 "alter table ${shardddl1}.${tb1} add new_col1 int unique auto_increment;" 367 run_sql_source1 "insert into ${shardddl1}.${tb1} values(3,0);" 368 run_sql_source2 "insert into ${shardddl1}.${tb1} values(4,0);" 369 run_sql_source2 "insert into ${shardddl1}.${tb2} values(5);" 370 run_sql_source2 "alter table ${shardddl1}.${tb2} add new_col1 int unique auto_increment;" 371 372 if [[ "$1" = "pessimistic" ]]; then 373 run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \ 374 "query-status test" \ 375 "unsupported add column 'new_col1' constraint UNIQUE KEY when altering" 1 376 else 377 run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \ 378 "query-status test" \ 379 "there will be conflicts" 2 380 fi 381 382 } 383 384 function DM_034() { 385 run_case 034 "double-source-pessimistic" "init_table 111 211 212" "clean_table" "pessimistic" 386 run_case 034 "double-source-optimistic" "init_table 111 211 212" "clean_table" "optimistic" 387 } 388 389 function DM_035_CASE() { 390 run_sql_source1 "alter table ${shardddl1}.${tb1} add new_col1 int;" 391 run_sql_source1 "alter table ${shardddl1}.${tb1} add new_col2 int;" 392 run_sql_source1 "insert into ${shardddl1}.${tb1} values(1,1,1);" 393 run_sql_source2 "insert into ${shardddl1}.${tb1} values(2);" 394 run_sql_source2 "insert into ${shardddl1}.${tb2} values(3);" 395 run_sql_source2 "alter table ${shardddl1}.${tb1} add new_col2 int;" 396 run_sql_source2 "alter table ${shardddl1}.${tb1} add new_col1 int;" 397 run_sql_source1 "insert into ${shardddl1}.${tb1} values(4,4,4);" 398 run_sql_source2 "insert into ${shardddl1}.${tb1} values(5,5,5);" 399 run_sql_source2 "insert into ${shardddl1}.${tb2} values(6);" 400 run_sql_source2 "alter table ${shardddl1}.${tb2} add new_col2 int;" 401 run_sql_source2 "alter table ${shardddl1}.${tb2} add new_col1 int;" 402 run_sql_source1 "insert into ${shardddl1}.${tb1} values(7,7,7);" 403 run_sql_source2 "insert into ${shardddl1}.${tb1} values(8,8,8);" 404 run_sql_source2 "insert into ${shardddl1}.${tb2} values(9,9,9);" 405 run_sql_tidb_with_retry "select count(1) from ${shardddl}.${tb};" "count(1): 9" 406 } 407 408 function DM_035() { 409 # currently not support pessimistic 410 # run_case 035 "double-source-pessimistic" "init_table 111 211 212" "clean_table" "pessimistic" 411 run_case 035 "double-source-optimistic" "init_table 111 211 212" "clean_table" "optimistic" 412 } 413 414 function DM_SAME_DDL_TWICE_CASE() { 415 # source1.tb1 add column 416 run_sql_source1 "alter table ${shardddl1}.${tb1} add new_col1 int;" 417 run_sql_source1 "insert into ${shardddl1}.${tb1} values(1,1);" 418 run_sql_source2 "insert into ${shardddl1}.${tb1} values(2);" 419 run_sql_source2 "insert into ${shardddl1}.${tb2} values(3);" 420 421 # source2.tb1 add column 422 run_sql_source2 "alter table ${shardddl1}.${tb1} add new_col1 int;" 423 run_sql_source1 "insert into ${shardddl1}.${tb1} values(4,4);" 424 run_sql_source2 "insert into ${shardddl1}.${tb1} values(5,5);" 425 run_sql_source2 "insert into ${shardddl1}.${tb2} values(6);" 426 # source2.tb1 drop column 427 run_sql_source2 "alter table ${shardddl1}.${tb1} drop new_col1;" 428 run_sql_source1 "insert into ${shardddl1}.${tb1} values(7,7);" 429 run_sql_source2 "insert into ${shardddl1}.${tb1} values(8);" 430 run_sql_source2 "insert into ${shardddl1}.${tb2} values(9);" 431 # source2.tb1 add column back 432 run_sql_source2 "alter table ${shardddl1}.${tb1} add new_col1 int;" 433 run_sql_source1 "insert into ${shardddl1}.${tb1} values(10,10);" 434 run_sql_source2 "insert into ${shardddl1}.${tb1} values(11,11);" 435 run_sql_source2 "insert into ${shardddl1}.${tb2} values(12);" 436 # source2.tb1 drop column again 437 run_sql_source2 "alter table ${shardddl1}.${tb1} drop new_col1;" 438 run_sql_source1 "insert into ${shardddl1}.${tb1} values(13,13);" 439 run_sql_source2 "insert into ${shardddl1}.${tb1} values(14);" 440 run_sql_source2 "insert into ${shardddl1}.${tb2} values(15);" 441 # source2.tb1 add column back again 442 run_sql_source2 "alter table ${shardddl1}.${tb1} add new_col1 int;" 443 run_sql_source1 "insert into ${shardddl1}.${tb1} values(16,16);" 444 run_sql_source2 "insert into ${shardddl1}.${tb1} values(17,17);" 445 run_sql_source2 "insert into ${shardddl1}.${tb2} values(18);" 446 447 # source2.tb2 add column 448 run_sql_source2 "alter table ${shardddl1}.${tb2} add new_col1 int;" 449 run_sql_source1 "insert into ${shardddl1}.${tb1} values(19,19);" 450 run_sql_source2 "insert into ${shardddl1}.${tb1} values(20,20);" 451 run_sql_source2 "insert into ${shardddl1}.${tb2} values(21,21);" 452 # source2.tb2 drop column 453 run_sql_source2 "alter table ${shardddl1}.${tb2} drop new_col1;" 454 run_sql_source1 "insert into ${shardddl1}.${tb1} values(22,22);" 455 run_sql_source2 "insert into ${shardddl1}.${tb1} values(23,23);" 456 run_sql_source2 "insert into ${shardddl1}.${tb2} values(24);" 457 # source2.tb2 add column back 458 run_sql_source2 "alter table ${shardddl1}.${tb2} add new_col1 int;" 459 run_sql_source1 "insert into ${shardddl1}.${tb1} values(25,25);" 460 run_sql_source2 "insert into ${shardddl1}.${tb1} values(26,26);" 461 run_sql_source2 "insert into ${shardddl1}.${tb2} values(27,27);" 462 # source2.tb2 drop column again 463 run_sql_source2 "alter table ${shardddl1}.${tb2} drop new_col1;" 464 run_sql_source1 "insert into ${shardddl1}.${tb1} values(28,28);" 465 run_sql_source2 "insert into ${shardddl1}.${tb1} values(29,29);" 466 run_sql_source2 "insert into ${shardddl1}.${tb2} values(30);" 467 # source2.tb2 add column back again 468 run_sql_source2 "alter table ${shardddl1}.${tb2} add new_col1 int;" 469 run_sql_source1 "insert into ${shardddl1}.${tb1} values(31,31);" 470 run_sql_source2 "insert into ${shardddl1}.${tb1} values(32,32);" 471 run_sql_source2 "insert into ${shardddl1}.${tb2} values(33,33);" 472 473 # source1.tb1 drop column 474 run_sql_source1 "alter table ${shardddl1}.${tb1} drop new_col1;" 475 run_sql_source1 "insert into ${shardddl1}.${tb1} values(34);" 476 run_sql_source2 "insert into ${shardddl1}.${tb1} values(35,35);" 477 run_sql_source2 "insert into ${shardddl1}.${tb2} values(36,36);" 478 # source1.tb1 add column back 479 run_sql_source1 "alter table ${shardddl1}.${tb1} add new_col1 int;" 480 run_sql_source1 "insert into ${shardddl1}.${tb1} values(37,37);" 481 run_sql_source2 "insert into ${shardddl1}.${tb1} values(38,38);" 482 run_sql_source2 "insert into ${shardddl1}.${tb2} values(39,39);" 483 # source1.tb1 drop column again 484 run_sql_source1 "alter table ${shardddl1}.${tb1} drop new_col1;" 485 run_sql_source1 "insert into ${shardddl1}.${tb1} values(40);" 486 run_sql_source2 "insert into ${shardddl1}.${tb1} values(41,41);" 487 run_sql_source2 "insert into ${shardddl1}.${tb2} values(42,42);" 488 # source1.tb1 add column back again 489 run_sql_source1 "alter table ${shardddl1}.${tb1} add new_col1 int;" 490 run_sql_source1 "insert into ${shardddl1}.${tb1} values(43,43);" 491 run_sql_source2 "insert into ${shardddl1}.${tb1} values(44,44);" 492 run_sql_source2 "insert into ${shardddl1}.${tb2} values(45,45);" 493 494 check_sync_diff $WORK_DIR $cur/conf/diff_config.toml 495 } 496 497 function DM_SAME_DDL_TWICE() { 498 run_case SAME_DDL_TWICE "double-source-pessimistic" "init_table 111 211 212" "clean_table" "pessimistic" 499 } 500 501 function DM_BINARY_COLUMN_CASE() { 502 run_sql_source1 "insert into ${shardddl1}.${tb1}(a,b) values(1,0xBF500C00A2034521B819D6EB7065D200)" 503 check_sync_diff $WORK_DIR $cur/conf/diff_config.toml 504 run_sql_source1 "update ${shardddl1}.${tb1} set a=2 where b=0xBF500C00A2034521B819D6EB7065D200" 505 check_sync_diff $WORK_DIR $cur/conf/diff_config.toml 506 run_sql_source1 "delete from ${shardddl1}.${tb1} where b=0xBF500C00A2034521B819D6EB7065D200" 507 check_sync_diff $WORK_DIR $cur/conf/diff_config.toml 508 509 # padding by mysql 510 run_sql_source1 "insert into ${shardddl1}.${tb1}(a,b) values(1,0xBF500C00A2034521B819D6EB7065D2)" 511 check_sync_diff $WORK_DIR $cur/conf/diff_config.toml 512 run_sql_source1 "update ${shardddl1}.${tb1} set a=2 where b=0xBF500C00A2034521B819D6EB7065D200" 513 check_sync_diff $WORK_DIR $cur/conf/diff_config.toml 514 run_sql_source1 "delete from ${shardddl1}.${tb1} where b=0xBF500C00A2034521B819D6EB7065D200" 515 check_sync_diff $WORK_DIR $cur/conf/diff_config.toml 516 run_sql_tidb_with_retry "select count(1) from ${shardddl}.${tb};" "count(1): 0" 517 } 518 519 function DM_BINARY_COLUMN() { 520 run_case BINARY_COLUMN "single-source-no-sharding" \ 521 "run_sql_source1 \"create table ${shardddl1}.${tb1} (a int, b binary(16) primary key);\"" \ 522 "clean_table" "" 523 } 524 525 function run() { 526 init_cluster 527 init_database 528 DM_SAME_DDL_TWICE 529 DM_BINARY_COLUMN 530 start=6 531 end=35 532 except=(024 025 029) 533 for i in $(seq -f "%03g" ${start} ${end}); do 534 if [[ ${except[@]} =~ $i ]]; then 535 continue 536 fi 537 DM_${i} 538 sleep 1 539 done 540 } 541 542 cleanup_data $shardddl 543 cleanup_data $shardddl1 544 cleanup_data $shardddl2 545 # also cleanup dm processes in case of last run failed 546 cleanup_process $* 547 run $* 548 cleanup_process $* 549 550 echo "[$(date)] <<<<<< test case $TEST_NAME success! >>>>>>"