This repository has been archived by the owner on Nov 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 188
/
Copy pathrun.sh
845 lines (669 loc) · 31.5 KB
/
run.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
#!/bin/bash
set -eux
cur=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
source $cur/../_utils/test_prepare
source $cur/../_utils/handle_error_lib.sh
WORK_DIR=$TEST_DIR/$TEST_NAME
# skip modify column, two sources, no sharding
function DM_SKIP_ERROR_CASE() {
run_sql_source1 "insert into ${db}.${tb1} values(1);"
run_sql_source2 "insert into ${db}.${tb2} values(2);"
run_sql_source1 "alter table ${db}.${tb1} add column new_col1 int;"
run_sql_source2 "alter table ${db}.${tb2} add column new_col1 int;"
run_sql_source1 "insert into ${db}.${tb1} values(3,3);"
run_sql_source2 "insert into ${db}.${tb2} values(4,4);"
# not support in TiDB
run_sql_source1 "alter table ${db}.${tb1} modify id varchar(10);"
run_sql_source2 "alter table ${db}.${tb2} modify id varchar(10);"
run_sql_source1 "insert into ${db}.${tb1} values('aaa',5);"
run_sql_source2 "insert into ${db}.${tb2} values('bbb',6);"
run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"query-status test" \
"Unsupported modify column" 2
# begin to handle error
# skip all sources
run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"binlog skip test" \
"\"result\": true" 3
# insert fail
run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"query-status test" \
"Error .*: Incorrect int value" 2
# skip one source
run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"binlog skip test -s mysql-replica-01" \
"only support to handle ddl error currently" 1
run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"query-status test" \
"\"stage\": \"Paused\"" 2
# skip all sources
run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"binlog skip test" \
"only support to handle ddl error currently" 2
run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"query-status test" \
"\"stage\": \"Paused\"" 2
}
function DM_SKIP_ERROR() {
run_case SKIP_ERROR "double-source-no-sharding" "init_table 11 22" "clean_table" ""
}
# skip modify column, two sources, 4 tables, sharding
# source1: tb1 first ddl -> tb1 second ddl -> tb2 first ddl -> tb2 second ddl
# source2: tb1 first ddl -> tb2 first ddl -> tb1 second ddl -> tb2 second ddl
function DM_SKIP_ERROR_SHARDING_CASE() {
run_sql_source1 "insert into ${db}.${tb1} values(1);"
run_sql_source1 "insert into ${db}.${tb2} values(2);"
run_sql_source2 "insert into ${db}.${tb1} values(3);"
run_sql_source2 "insert into ${db}.${tb2} values(4);"
# 11/21 first ddl
run_sql_source1 "alter table ${db}.${tb1} CHARACTER SET latin1 COLLATE latin1_danish_ci;"
run_sql_source2 "alter table ${db}.${tb1} CHARACTER SET latin1 COLLATE latin1_danish_ci;"
# 11 second ddl
run_sql_source1 "alter table ${db}.${tb1} add column new_col1 varchar(10);"
run_sql_source1 "insert into ${db}.${tb1} values(5,'aaa');"
# 12/22 first ddl
run_sql_source1 "alter table ${db}.${tb2} CHARACTER SET latin1 COLLATE latin1_danish_ci;"
run_sql_source2 "alter table ${db}.${tb2} CHARACTER SET latin1 COLLATE latin1_danish_ci;"
# 21 second ddl
run_sql_source2 "alter table ${db}.${tb1} add column new_col1 varchar(10);"
run_sql_source2 "insert into ${db}.${tb1} values(6,'bbb');"
# 12/22 second ddl
run_sql_source1 "alter table ${db}.${tb2} add column new_col1 varchar(10);"
run_sql_source1 "insert into ${db}.${tb2} values(7,'ccc');"
run_sql_source2 "alter table ${db}.${tb2} add column new_col1 varchar(10);"
run_sql_source2 "insert into ${db}.${tb2} values(8,'ddd');"
# begin to handle error
# 11/21 first ddl: unsupport error
run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"query-status test" \
"Unsupported modify change collate from latin1_bin to latin1_danish_ci" 2
# skip 11/21 first ddl
run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"binlog skip test" \
"\"result\": true" 3
if [[ "$1" = "pessimistic" ]]; then
# 11 second ddl bypass, 12 first ddl: detect conflict
# 22 first ddl: unsupport error
run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"query-status test" \
"detect inconsistent DDL sequence from source" 1 \
"Unsupported modify change collate from latin1_bin to latin1_danish_ci" 1
else
# 12/22 first ddl: unsupport error
run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"query-status test" \
"Unsupported modify change collate from latin1_bin to latin1_danish_ci" 2
fi
run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"binlog skip test -s mysql-replica-01,mysql-replica-02" \
"\"result\": true" 3
run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"query-status test" \
"\"stage\": \"Running\"" 2
run_sql_tidb_with_retry "select count(1) from ${db}.${tb}" "count(1): 8"
}
function DM_SKIP_ERROR_SHARDING() {
run_case SKIP_ERROR_SHARDING "double-source-pessimistic" "init_table 11 12 21 22" "clean_table" "pessimistic"
run_case SKIP_ERROR_SHARDING "double-source-optimistic" "init_table 11 12 21 22" "clean_table" "optimistic"
}
# replace add column unique
# one source, one table, no sharding
function DM_REPLACE_ERROR_CASE() {
run_sql_source1 "insert into ${db}.${tb1} values(1,1);"
# error in TiDB
run_sql_source1 "alter table ${db}.${tb1} add column new_col text, add column c int unique;"
run_sql_source1 "insert into ${db}.${tb1} values(2,2,'haha',2);"
run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"query-status test" \
"unsupported add column .* constraint UNIQUE KEY" 1 \
"origin SQL: \[alter table ${db}.${tb1} add column new_col text, add column c int unique\]" 1
# replace sql
run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"binlog replace test alter table ${db}.${tb1} add column new_col text, add column c int; alter table ${db}.${tb1} add unique(c);" \
"\"result\": true" 2
run_sql_source1 "insert into ${db}.${tb1} values(3,3,'hihi',3);"
run_sql_tidb_with_retry "select count(1) from ${db}.${tb1};" "count(1): 3"
}
function DM_REPLACE_ERROR() {
run_case REPLACE_ERROR "double-source-no-sharding" \
"run_sql_source1 \"create table ${db}.${tb1} (a int unique, b int);\"" \
"clean_table" ""
}
# replace add column unique twice
# two source, 4 tables
# source1: tb1 first ddl -> tb1 second ddl -> tb2 first ddl -> tb2 second ddl
# source2: tb1 first ddl -> tb2 first ddl -> tb1 second ddl -> tb2 second ddl
function DM_REPLACE_ERROR_SHARDING_CASE() {
# 11/21 first ddl
run_sql_source1 "alter table ${db}.${tb1} add column c int unique;"
run_sql_source2 "alter table ${db}.${tb1} add column c int unique;"
run_sql_source1 "insert into ${db}.${tb1} values(1,1,1);"
run_sql_source2 "insert into ${db}.${tb1} values(2,2,2);"
# 11 second ddl
run_sql_source1 "alter table ${db}.${tb1} add column d int unique;"
run_sql_source1 "insert into ${db}.${tb1} values(3,3,3,3);"
# 12/22 first ddl
run_sql_source1 "alter table ${db}.${tb2} add column c int unique;"
run_sql_source2 "alter table ${db}.${tb2} add column c int unique;"
run_sql_source1 "insert into ${db}.${tb2} values(4,4,4);"
run_sql_source2 "insert into ${db}.${tb2} values(5,5,5);"
# 21 second ddl
run_sql_source2 "alter table ${db}.${tb1} add column d int unique;"
run_sql_source2 "insert into ${db}.${tb1} values(6,6,6,6);"
# 12/22 second ddl
run_sql_source1 "alter table ${db}.${tb2} add column d int unique;"
run_sql_source2 "alter table ${db}.${tb2} add column d int unique;"
run_sql_source1 "insert into ${db}.${tb2} values(7,7,7,7);"
run_sql_source2 "insert into ${db}.${tb2} values(8,8,8,8);"
# 11/21 first ddl: unsupport error
run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"query-status test" \
"unsupported add column .* constraint UNIQUE KEY" 2
# begin to handle error
# split 11/21 first ddl into two ddls
run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"binlog replace test alter table ${db}.${tb1} add column c int;alter table ${db}.${tb1} add unique(c)" \
"\"result\": true" 3
if [[ "$1" = "pessimistic" ]]; then
# 11 second ddl bypass, 12 first ddl detect conflict
# 22 first ddl: detect conflict
run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"query-status test" \
"detect inconsistent DDL sequence from source" 2
# split 12,22 first ddl into two ddls
run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"binlog replace test -s mysql-replica-01,mysql-replica-02 alter table ${db}.${tb2} add column c int;alter table ${db}.${tb2} add unique(c);" \
"\"result\": true" 3
# 11/21 second ddl: unsupport error
run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"query-status test" \
"unsupported add column .* constraint UNIQUE KEY" 2
# split 11/21 second ddl into two ddls
run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"binlog replace test alter table ${db}.${tb1} add column d int;alter table ${db}.${tb1} add unique(d);" \
"\"result\": true" 3
# 12/22 second ddl: detect conflict
run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"query-status test" \
"detect inconsistent DDL sequence from source" 2
# split 11/21 second ddl into two ddls one by one
run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"binlog replace test -s mysql-replica-01 alter table ${db}.${tb2} add column d int;alter table ${db}.${tb2} add unique(d);" \
"\"result\": true" 2
run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"binlog replace test -s mysql-replica-02 alter table ${db}.${tb2} add column d int;alter table ${db}.${tb2} add unique(d);" \
"\"result\": true" 2
else
# 11 second ddl, 22 first ddl: unsupport error
run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"query-status test" \
"unsupported add column .* constraint UNIQUE KEY" 2
# replace 11 second ddl
run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"binlog replace test -s mysql-replica-01 alter table ${db}.${tb1} add column d int;alter table ${db}.${tb1} add unique(d);" \
"\"result\": true" 2
# replace 22 first ddl
run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"binlog replace test -s mysql-replica-02 alter table ${db}.${tb2} add column c int;alter table ${db}.${tb2} add unique(c);" \
"\"result\": true" 2
# 12 first ddl, 21 second ddl: unsupport error
run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"query-status test" \
"unsupported add column .* constraint UNIQUE KEY" 2
# replace 12 first ddl
run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"binlog replace test -s mysql-replica-01 alter table ${db}.${tb2} add column c int;alter table ${db}.${tb2} add unique(c);" \
"\"result\": true" 2
# replace 21 second ddl
run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"binlog replace test -s mysql-replica-02 alter table ${db}.${tb1} add column d int;alter table ${db}.${tb1} add unique(d);" \
"\"result\": true" 2
# 12 first ddl, 22 second ddl: unspport error
run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"query-status test" \
"unsupported add column .* constraint UNIQUE KEY" 2
# replace 12/22 second ddl
run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"binlog replace test alter table ${db}.${tb2} add column d int;alter table ${db}.${tb1} add unique(d);" \
"\"result\": true" 3
fi
run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"query-status test" \
"\"stage\": \"Running\"" 2
run_sql_tidb_with_retry "select count(1) from ${db}.${tb}" "count(1): 8"
}
function DM_REPLACE_ERROR_SHARDING() {
run_case REPLACE_ERROR_SHARDING "double-source-pessimistic" \
"run_sql_source1 \"create table ${db}.${tb1} (a int primary key, b int);\"; \
run_sql_source1 \"create table ${db}.${tb2} (a int primary key, b int);\"; \
run_sql_source2 \"create table ${db}.${tb1} (a int primary key, b int);\"; \
run_sql_source2 \"create table ${db}.${tb2} (a int primary key, b int);\"" \
"clean_table" "pessimistic"
run_case REPLACE_ERROR_SHARDING "double-source-optimistic" \
"run_sql_source1 \"create table ${db}.${tb1} (a int primary key, b int);\"; \
run_sql_source1 \"create table ${db}.${tb2} (a int primary key, b int);\"; \
run_sql_source2 \"create table ${db}.${tb1} (a int primary key, b int);\"; \
run_sql_source2 \"create table ${db}.${tb2} (a int primary key, b int);\"" \
"clean_table" "optimistic"
}
# test handle_error fail on second replace ddl
# two sources, two tables
function DM_REPLACE_ERROR_MULTIPLE_CASE() {
run_sql_source1 "alter table ${db}.${tb1} add column a int unique, add column b int unique;"
run_sql_source2 "alter table ${db}.${tb1} add column a int unique, add column b int unique;"
run_sql_source1 "insert into ${db}.${tb1} values(1,1,1);"
run_sql_source2 "insert into ${db}.${tb1} values(2,2,2);"
# 11, 21 unspported error
run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"query-status test" \
"unsupported add column 'a' constraint UNIQUE KEY" 2
# begin to handle error
# replace 11/21 ddl, wrong on second replace ddl
run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"binlog replace test \"alter table ${db}.${tb1} add column a int; alter table ${db}.${tb1} add column b int unique;\"" \
"\"result\": true" 3
run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"query-status test" \
"unsupported add column 'b' constraint UNIQUE KEY" 2
# now we change the second replace ddl, but first replace ddl will error because it has been executed in TiDB ...
run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"binlog replace test \"alter table ${db}.${tb1} add column a int; alter table ${db}.${tb1} add column b int;\"" \
"\"result\": true" 3
# 11, 21 first replace ddl error
run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"query-status test" \
"Duplicate column name 'a'" 2
# test handle-error revert
run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"binlog revert test" \
"\"result\": true" 3
run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"query-status test" \
"unsupported add column 'a' constraint UNIQUE KEY" 2
# now we only replace with ddl2
run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"binlog replace test \"alter table ${db}.${tb1} add column b int;\"" \
"\"result\": true" 3
run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"query-status test" \
"\"stage\": \"Running\"" 2
run_sql_tidb_with_retry "select count(1) from ${db}.${tb};" "count(1): 2"
}
function DM_REPLACE_ERROR_MULTIPLE() {
run_case REPLACE_ERROR_MULTIPLE "double-source-pessimistic" "init_table 11 21" "clean_table" "pessimistic"
run_case REPLACE_ERROR_MULTIPLE "double-source-optimistic" "init_table 11 21" "clean_table" "optimistic"
}
function DM_EXEC_ERROR_SKIP_CASE() {
run_sql_source1 "insert into ${db}.${tb1} values(1,1,1);"
run_sql_source2 "insert into ${db}.${tb1} values(2,2,2);"
run_sql_tidb "insert into ${db}.${tb} values(3,1,1);"
run_sql_tidb "insert into ${db}.${tb} values(4,2,2);"
run_sql_tidb_with_retry "select count(1) from ${db}.${tb};" "count(1): 4"
run_sql_source1 "alter table ${db}.${tb1} add unique index ua(a);"
run_sql_source2 "alter table ${db}.${tb1} add unique index ua(a);"
run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"query-status test" \
"Error 1062: Duplicate " 1
run_sql_tidb "insert into ${db}.${tb} values(5,3,3);"
run_sql_tidb "insert into ${db}.${tb} values(6,4,4);"
run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"binlog skip test" \
"\"result\": true" 2
run_sql_tidb_with_retry "select count(1) from ${db}.${tb};" "count(1): 6"
}
function DM_EXEC_ERROR_SKIP() {
run_case EXEC_ERROR_SKIP "double-source-pessimistic" \
"run_sql_source1 \"create table ${db}.${tb1} (id int primary key, a int, b int);\"; \
run_sql_source2 \"create table ${db}.${tb1} (id int primary key, a int, b int);\"" \
"clean_table" "pessimistic"
run_case EXEC_ERROR_SKIP "double-source-optimistic" \
"run_sql_source1 \"create table ${db}.${tb1} (id int primary key, a int, b int);\"; \
run_sql_source2 \"create table ${db}.${tb1} (id int primary key, a int, b int);\"" \
"clean_table" "optimistic"
}
function DM_SKIP_INCOMPATIBLE_DDL_CASE() {
run_sql_source1 "insert into ${db}.${tb1} values(1);"
run_sql_source1 "CREATE FUNCTION ${db}.hello (s CHAR(20)) RETURNS CHAR(50) DETERMINISTIC RETURN CONCAT('Hello, ',s,'!');"
run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"query-status test" \
"\"stage\": \"Running\"" 1
run_sql_source1 "/*!50003 drop function ${db}.hello*/;"
run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"query-status test" \
"drop function $(hello)" 2 \
"Please confirm your DDL statement is correct and needed." 1
run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"binlog skip test" \
"\"result\": true" 2
run_sql_source1 "insert into ${db}.${tb1} values(2);"
check_sync_diff $WORK_DIR $cur/conf/diff_config.toml
}
function DM_SKIP_INCOMPATIBLE_DDL() {
run_case SKIP_INCOMPATIBLE_DDL "single-source-no-sharding" "init_table 11" "clean_table" ""
}
function DM_REPLACE_DEFAULT_VALUE_CASE() {
run_sql_source1 "insert into ${db}.${tb1} values(1);"
run_sql_source2 "insert into ${db}.${tb1} values(2);"
run_sql_source2 "insert into ${db}.${tb2} values(3);"
run_sql_source1 "alter table ${db}.${tb1} add new_col1 int default 1;"
run_sql_source1 "insert into ${db}.${tb1} values(4,4);"
run_sql_source2 "insert into ${db}.${tb1} values(5);"
run_sql_source2 "insert into ${db}.${tb2} values(6);"
# make sure order is source1.table1, source2.table1, source2.table2
run_sql_tidb_with_retry "select count(1) from ${db}.${tb}" "count(1): 6"
run_sql_source2 "alter table ${db}.${tb1} add new_col1 int default 2;"
run_sql_source1 "insert into ${db}.${tb1} values(7,7);"
run_sql_source2 "insert into ${db}.${tb1} values(8,8);"
run_sql_source2 "insert into ${db}.${tb2} values(9);"
run_sql_source2 "alter table ${db}.${tb2} add new_col1 int default 3;"
run_sql_source1 "insert into ${db}.${tb1} values(10,10);"
run_sql_source2 "insert into ${db}.${tb1} values(11,11);"
run_sql_source2 "insert into ${db}.${tb2} values(12,12);"
run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"query-status test" \
"because schema conflict detected" 1
run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"binlog replace test -s mysql-replica-02 alter table ${db}.${tb1} add new_col1 int default 1;" \
"\"result\": true" 2
run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"query-status test" \
"because schema conflict detected" 1
run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"binlog replace test -s mysql-replica-02 alter table ${db}.${tb2} add new_col1 int default 1;" \
"\"result\": true" 2
run_sql_source1 "alter table ${db}.${tb1} add new_col2 int;"
run_sql_source2 "alter table ${db}.${tb1} add new_col2 int;"
run_sql_source2 "alter table ${db}.${tb2} add new_col2 int;"
run_sql_source1 "insert into ${db}.${tb1} values(13,13,13);"
run_sql_source2 "insert into ${db}.${tb1} values(14,14,14);"
run_sql_source2 "insert into ${db}.${tb2} values(15,15,15);"
# WARN: some data different
# all the value before alter table in TiDB will be 1, while upstream table is 1, 2 or 3
run_sql_tidb_with_retry "select count(1) from ${db}.${tb}" "count(1): 15"
run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"query-status test" \
"\"result\": true" 3
}
function DM_REPLACE_DEFAULT_VALUE() {
run_case REPLACE_DEFAULT_VALUE "double-source-optimistic" "init_table 11 21 22" "clean_table" ""
}
function DM_4202_CASE() {
run_sql_source1 "insert into ${db}.${tb1} values(1);"
run_sql_source1 "alter table ${db}.${tb1} modify id varchar(10);"
run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"query-status test" \
"Unsupported modify column" 1
start_location=$(get_start_location 127.0.0.1:$MASTER_PORT $source1)
run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"binlog skip test -b $start_location" \
"\"result\": true" 2
run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"query-status test" \
"\"result\": true" 2
run_sql_source1 "insert into ${db}.${tb1} values(2);"
run_sql_tidb_with_retry "select count(1) from ${db}.${tb};" "count(1): 2"
}
function DM_4202() {
run_case 4202 "single-source-no-sharding" "init_table 11" "clean_table" ""
}
function DM_4204_CASE() {
run_sql_source1 "insert into ${db}.${tb1} values(1);"
run_sql_source1 "alter table ${db}.${tb1} modify id varchar(10);"
run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"query-status test" \
"Unsupported modify column" 1
run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"binlog skip test" \
"\"result\": true" 2
run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"query-status test" \
"\"result\": true" 2
run_sql_source1 "insert into ${db}.${tb1} values(2);"
run_sql_tidb_with_retry "select count(1) from ${db}.${tb};" "count(1): 2"
}
function DM_4204() {
run_case 4204 "single-source-no-sharding" "init_table 11" "clean_table" ""
}
# 4206, 4208
function DM_4206_CASE() {
run_sql_source1 "insert into ${db}.${tb1} values(1);"
run_sql_source2 "insert into ${db}.${tb1} values(2);"
run_sql_source1 "alter table ${db}.${tb1} modify id varchar(10);"
run_sql_source2 "alter table ${db}.${tb1} modify id varchar(10);"
run_sql_source1 "alter table ${db}.${tb1} modify id varchar(20);"
run_sql_source2 "alter table ${db}.${tb1} modify id varchar(20);"
run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"query-status test" \
"Unsupported modify column: this column has primary key flag" 2
first_pos1=$(get_start_pos 127.0.0.1:$MASTER_PORT $source1)
first_pos2=$(get_start_pos 127.0.0.1:$MASTER_PORT $source2)
first_name1=$(get_start_name 127.0.0.1:$MASTER_PORT $source1)
first_name2=$(get_start_name 127.0.0.1:$MASTER_PORT $source2)
second_pos1=$(get_next_query_pos $MYSQL_PORT1 $MYSQL_PASSWORD1 $first_pos1)
second_pos2=$(get_next_query_pos $MYSQL_PORT2 $MYSQL_PASSWORD2 $first_pos2)
run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"binlog skip test -b $first_name1:$second_pos1 -s $source1" \
"\"result\": true" 2
run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"query-status test" \
"Unsupported modify column: this column has primary key flag" 2
run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"binlog skip test -b $first_name1:$first_pos1 -s $source1" \
"\"result\": true" 2
run_sql_source1 "insert into ${db}.${tb1} values(3);"
run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"query-status test" \
"Unsupported modify column: this column has primary key flag" 1
run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"binlog skip test -b $first_name2:$first_pos2 -s $source2" \
"\"result\": true" 2
run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"query-status test" \
"Unsupported modify column: this column has primary key flag" 1
run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"binlog skip test -b $first_name2:$second_pos2 -s $source2" \
"\"result\": true" 2
run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"query-status test" \
"\"result\": true" 3
run_sql_source2 "insert into ${db}.${tb1} values(4);"
run_sql_tidb_with_retry "select count(1) from ${db}.${tb};" "count(1): 4"
}
function DM_4206() {
run_case 4206 "double-source-pessimistic" "init_table 11 21" "clean_table" "pessimistic"
run_case 4206 "double-source-optimistic" "init_table 11 21" "clean_table" "optimistic"
}
function DM_4207_CASE() {
run_sql_source1 "insert into ${db}.${tb1} values(1);"
run_sql_source2 "insert into ${db}.${tb1} values(2);"
run_sql_source1 "alter table ${db}.${tb1} modify id varchar(10);"
run_sql_source2 "alter table ${db}.${tb1} modify id varchar(10);"
run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"query-status test" \
"Unsupported modify column" 2
start_location1=$(get_start_location 127.0.0.1:$MASTER_PORT $source1)
start_location2=$(get_start_location 127.0.0.1:$MASTER_PORT $source2)
if [ "$start_location1" = "$start_location2" ]; then
run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"binlog skip test -b $start_location1" \
"\"result\": true" 3
else
# WARN: may skip unknown event like later insert, test will fail
# It hasn't happened yet.
run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"binlog skip test -b $start_location1" \
"\"result\": true" 3
run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"query-status test" \
"Unsupported modify column" 1
run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"binlog skip test -b $start_location2" \
"\"result\": true" 3
fi
run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"query-status test" \
"\"result\": true" 3
run_sql_source1 "insert into ${db}.${tb1} values(3);"
run_sql_source2 "insert into ${db}.${tb1} values(4);"
run_sql_tidb_with_retry "select count(1) from ${db}.${tb} where id<100;" "count(1): 4"
}
function DM_4207() {
run_case 4207 "double-source-pessimistic" "init_table 11 21" "clean_table" "pessimistic"
run_case 4207 "double-source-optimistic" "init_table 11 21" "clean_table" "optimistic"
# test different error locations
run_case 4207 "double-source-pessimistic" "init_table 11 21;run_sql_source1 \"insert into ${db}.${tb1} values(100);\"" "clean_table" "pessimistic"
run_case 4207 "double-source-optimistic" "init_table 11 21;run_sql_source1 \"insert into ${db}.${tb1} values(100);\"" "clean_table" "optimistic"
}
function DM_4209_CASE() {
run_sql_source1 "insert into ${db}.${tb1} values(1);"
run_sql_source2 "insert into ${db}.${tb1} values(2);"
run_sql_source1 "alter table ${db}.${tb1} modify id varchar(10);"
run_sql_source2 "alter table ${db}.${tb1} modify id varchar(10);"
run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"query-status test" \
"Unsupported modify column" 2
run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"binlog skip test -s $source1" \
"\"result\": true" 2
run_sql_source1 "insert into ${db}.${tb1} values(3);"
run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"query-status test" \
"Unsupported modify column" 1
run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"binlog skip test -s $source2" \
"\"result\": true" 2
run_sql_source2 "insert into ${db}.${tb1} values(4);"
run_sql_tidb_with_retry "select count(1) from ${db}.${tb};" "count(1): 4"
}
function DM_4209() {
run_case 4209 "double-source-pessimistic" "init_table 11 21" "clean_table" "pessimistic"
run_case 4209 "double-source-optimistic" "init_table 11 21" "clean_table" "optimistic"
}
function DM_4211_CASE() {
run_sql_source1 "insert into ${db}.${tb1} values(1);"
run_sql_source1 "alter table ${db}.${tb1} add column c int unique;"
run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"query-status test" \
"unsupported add column .* constraint UNIQUE KEY" 1
run_sql_source1 "insert into ${db}.${tb1} values(2,2);"
start_location=$(get_start_location 127.0.0.1:$MASTER_PORT $source1)
run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"binlog replace test --binlog-pos $start_location alter table ${db}.${tb1} add column c int;" \
"\"result\": true" 2
run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"query-status test" \
"\"result\": true" 2
run_sql_source1 "insert into ${db}.${tb1} values(3,3);"
run_sql_tidb_with_retry "select count(1) from ${db}.${tb};" "count(1): 3"
}
function DM_4211() {
run_case 4211 "single-source-no-sharding" "init_table 11" "clean_table" ""
}
function DM_4213_CASE() {
run_sql_source1 "insert into ${db}.${tb1} values(1);"
run_sql_source1 "alter table ${db}.${tb1} add column c int unique;"
run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"query-status test" \
"unsupported add column .* constraint UNIQUE KEY" 1
run_sql_source1 "insert into ${db}.${tb1} values(2,2);"
run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"binlog replace test alter table ${db}.${tb1} add column c int;alter table ${db}.${tb1} add unique(c);" \
"\"result\": true" 2
run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"query-status test" \
"\"result\": true" 2
run_sql_source1 "insert into ${db}.${tb1} values(3,3);"
run_sql_tidb_with_retry "select count(1) from ${db}.${tb};" "count(1): 3"
}
function DM_4213() {
run_case 4213 "single-source-no-sharding" "init_table 11" "clean_table" ""
}
function DM_SKIP_INCOMPATIBLE_DDL_CASE() {
run_sql_source1 "insert into ${db}.${tb1} values(1);"
run_sql_source1 "CREATE FUNCTION ${db}.hello (s CHAR(20)) RETURNS CHAR(50) DETERMINISTIC RETURN CONCAT('Hello, ',s,'!');"
run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"query-status test" \
"\"stage\": \"Running\"" 1
run_sql_source1 "/*!50003 drop function ${db}.hello*/;"
run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"query-status test" \
"drop function $(hello)" 2 \
"Please confirm your DDL statement is correct and needed." 1
run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"binlog skip test" \
"\"result\": true" 2
run_sql_source1 "insert into ${db}.${tb1} values(2);"
check_sync_diff $WORK_DIR $cur/conf/diff_config.toml
}
function DM_SKIP_INCOMPATIBLE_DDL() {
run_case SKIP_INCOMPATIBLE_DDL "single-source-no-sharding" "init_table 11" "clean_table" ""
}
function DM_REPLACE_DEFAULT_VALUE_CASE() {
run_sql_source1 "insert into ${db}.${tb1} values(1);"
run_sql_source2 "insert into ${db}.${tb1} values(2);"
run_sql_source2 "insert into ${db}.${tb2} values(3);"
run_sql_source1 "alter table ${db}.${tb1} add new_col1 int default 1;"
run_sql_source1 "insert into ${db}.${tb1} values(4,4);"
run_sql_source2 "insert into ${db}.${tb1} values(5);"
run_sql_source2 "insert into ${db}.${tb2} values(6);"
# make sure order is source1.table1, source2.table1, source2.table2
run_sql_tidb_with_retry "select count(1) from ${db}.${tb}" "count(1): 6"
run_sql_source2 "alter table ${db}.${tb1} add new_col1 int default 2;"
run_sql_source1 "insert into ${db}.${tb1} values(7,7);"
run_sql_source2 "insert into ${db}.${tb1} values(8,8);"
run_sql_source2 "insert into ${db}.${tb2} values(9);"
run_sql_source2 "alter table ${db}.${tb2} add new_col1 int default 3;"
run_sql_source1 "insert into ${db}.${tb1} values(10,10);"
run_sql_source2 "insert into ${db}.${tb1} values(11,11);"
run_sql_source2 "insert into ${db}.${tb2} values(12,12);"
run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"query-status test" \
"because schema conflict detected" 1
run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"binlog replace test -s mysql-replica-02 alter table ${db}.${tb1} add new_col1 int default 1;" \
"\"result\": true" 2
run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"query-status test" \
"because schema conflict detected" 1
run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"binlog replace test -s mysql-replica-02 alter table ${db}.${tb2} add new_col1 int default 1;" \
"\"result\": true" 2
run_sql_source1 "alter table ${db}.${tb1} add new_col2 int;"
run_sql_source2 "alter table ${db}.${tb1} add new_col2 int;"
run_sql_source2 "alter table ${db}.${tb2} add new_col2 int;"
run_sql_source1 "insert into ${db}.${tb1} values(13,13,13);"
run_sql_source2 "insert into ${db}.${tb1} values(14,14,14);"
run_sql_source2 "insert into ${db}.${tb2} values(15,15,15);"
# WARN: some data different
# all the value before alter table in TiDB will be 1, while upstream table is 1, 2 or 3
run_sql_tidb_with_retry "select count(1) from ${db}.${tb}" "count(1): 15"
run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"query-status test" \
"\"result\": true" 3
}
function DM_REPLACE_DEFAULT_VALUE() {
run_case REPLACE_DEFAULT_VALUE "double-source-optimistic" "init_table 11 21 22" "clean_table" ""
}
function run() {
init_cluster
init_database
DM_SKIP_ERROR
DM_SKIP_ERROR_SHARDING
DM_REPLACE_ERROR
DM_REPLACE_ERROR_SHARDING
DM_REPLACE_ERROR_MULTIPLE
DM_EXEC_ERROR_SKIP
DM_SKIP_INCOMPATIBLE_DDL
DM_REPLACE_DEFAULT_VALUE
implement=(4202 4204 4206 4207 4209 4211 4213)
for i in ${implement[@]}; do
DM_${i}
sleep 1
done
}
cleanup_data $db
# also cleanup dm processes in case of last run failed
cleanup_process $*
run $*
cleanup_process $*
echo "[$(date)] <<<<<< test case $TEST_NAME success! >>>>>>"