forked from vitessio/vitess
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathonlineddl_revert_test.go
1472 lines (1344 loc) · 57.7 KB
/
onlineddl_revert_test.go
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
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright 2021 The Vitess Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package revert
import (
"context"
"flag"
"fmt"
"math/rand/v2"
"os"
"path"
"strings"
"sync"
"sync/atomic"
"testing"
"time"
"vitess.io/vitess/go/mysql"
"vitess.io/vitess/go/mysql/capabilities"
"vitess.io/vitess/go/vt/log"
tabletmanagerdatapb "vitess.io/vitess/go/vt/proto/tabletmanagerdata"
"vitess.io/vitess/go/vt/schema"
"vitess.io/vitess/go/vt/vttablet/tabletserver/throttle/throttlerapp"
"vitess.io/vitess/go/test/endtoend/cluster"
"vitess.io/vitess/go/test/endtoend/onlineddl"
"vitess.io/vitess/go/test/endtoend/throttler"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
type WriteMetrics struct {
mu sync.Mutex
insertsAttempts, insertsFailures, insertsNoops, inserts int64
updatesAttempts, updatesFailures, updatesNoops, updates int64
deletesAttempts, deletesFailures, deletesNoops, deletes int64
}
func (w *WriteMetrics) Clear() {
w.mu.Lock()
defer w.mu.Unlock()
w.inserts = 0
w.updates = 0
w.deletes = 0
w.insertsAttempts = 0
w.insertsFailures = 0
w.insertsNoops = 0
w.updatesAttempts = 0
w.updatesFailures = 0
w.updatesNoops = 0
w.deletesAttempts = 0
w.deletesFailures = 0
w.deletesNoops = 0
}
func (w *WriteMetrics) String() string {
return fmt.Sprintf(`WriteMetrics: inserts-deletes=%d, updates-deletes=%d,
insertsAttempts=%d, insertsFailures=%d, insertsNoops=%d, inserts=%d,
updatesAttempts=%d, updatesFailures=%d, updatesNoops=%d, updates=%d,
deletesAttempts=%d, deletesFailures=%d, deletesNoops=%d, deletes=%d,
`,
w.inserts-w.deletes, w.updates-w.deletes,
w.insertsAttempts, w.insertsFailures, w.insertsNoops, w.inserts,
w.updatesAttempts, w.updatesFailures, w.updatesNoops, w.updates,
w.deletesAttempts, w.deletesFailures, w.deletesNoops, w.deletes,
)
}
var (
clusterInstance *cluster.LocalProcessCluster
primaryTablet *cluster.Vttablet
shards []cluster.Shard
vtParams mysql.ConnParams
mysqlVersion string
hostname = "localhost"
keyspaceName = "ks"
cell = "zone1"
schemaChangeDirectory = ""
tableName = `stress_test`
viewBaseTableName = `view_base_table_test`
viewName = `view_test`
insertRowStatement = `
INSERT IGNORE INTO stress_test (id, rand_val) VALUES (%d, left(md5(rand()), 8))
`
updateRowStatement = `
UPDATE stress_test SET updates=updates+1 WHERE id=%d
`
deleteRowStatement = `
DELETE FROM stress_test WHERE id=%d AND updates=1
`
// We use CAST(SUM(updates) AS SIGNED) because SUM() returns a DECIMAL datatype, and we want to read a SIGNED INTEGER type
selectCountRowsStatement = `
SELECT COUNT(*) AS num_rows, CAST(SUM(updates) AS SIGNED) AS sum_updates FROM stress_test
`
truncateStatement = `
TRUNCATE TABLE stress_test
`
writeMetrics WriteMetrics
)
const (
maxTableRows = 4096
maxConcurrency = 5
)
type revertibleTestCase struct {
name string
fromSchema string
toSchema string
// expectProblems bool
removedForeignKeyNames string
removedUniqueKeyNames string
droppedNoDefaultColumnNames string
expandedColumnNames string
onlyIfFKOnlineDDLPossible bool
}
func TestMain(m *testing.M) {
flag.Parse()
exitcode, err := func() (int, error) {
clusterInstance = cluster.NewCluster(cell, hostname)
schemaChangeDirectory = path.Join("/tmp", fmt.Sprintf("schema_change_dir_%d", clusterInstance.GetAndReserveTabletUID()))
defer os.RemoveAll(schemaChangeDirectory)
defer clusterInstance.Teardown()
if _, err := os.Stat(schemaChangeDirectory); os.IsNotExist(err) {
_ = os.Mkdir(schemaChangeDirectory, 0700)
}
clusterInstance.VtctldExtraArgs = []string{
"--schema_change_dir", schemaChangeDirectory,
"--schema_change_controller", "local",
"--schema_change_check_interval", "1s",
}
clusterInstance.VtTabletExtraArgs = []string{
"--heartbeat_interval", "250ms",
"--heartbeat_on_demand_duration", "5s",
"--migration_check_interval", "5s",
"--watch_replication_stream",
}
clusterInstance.VtGateExtraArgs = []string{
"--ddl_strategy", "online",
}
if err := clusterInstance.StartTopo(); err != nil {
return 1, err
}
// Start keyspace
keyspace := &cluster.Keyspace{
Name: keyspaceName,
}
// No need for replicas in this stress test
if err := clusterInstance.StartKeyspace(*keyspace, []string{"1"}, 0, false); err != nil {
return 1, err
}
vtgateInstance := clusterInstance.NewVtgateInstance()
// Start vtgate
if err := vtgateInstance.Setup(); err != nil {
return 1, err
}
// ensure it is torn down during cluster TearDown
clusterInstance.VtgateProcess = *vtgateInstance
vtParams = mysql.ConnParams{
Host: clusterInstance.Hostname,
Port: clusterInstance.VtgateMySQLPort,
}
primaryTablet = clusterInstance.Keyspaces[0].Shards[0].PrimaryTablet()
return m.Run(), nil
}()
if err != nil {
fmt.Printf("%v\n", err)
os.Exit(1)
} else {
os.Exit(exitcode)
}
}
func TestRevertSchemaChanges(t *testing.T) {
shards = clusterInstance.Keyspaces[0].Shards
require.Equal(t, 1, len(shards))
throttler.EnableLagThrottlerAndWaitForStatus(t, clusterInstance)
throttler.WaitForCheckThrottlerResult(t, clusterInstance, primaryTablet, throttlerapp.TestingName, nil, tabletmanagerdatapb.CheckThrottlerResponseCode_OK, time.Minute)
t.Run("revertible", testRevertible)
t.Run("revert", testRevert)
}
func testRevertible(t *testing.T) {
fkOnlineDDLPossible := false
t.Run("check 'rename_table_preserve_foreign_key' variable", func(t *testing.T) {
// Online DDL is not possible on vanilla MySQL 8.0 for reasons described in https://vitess.io/blog/2021-06-15-online-ddl-why-no-fk/.
// However, Online DDL is made possible in via these changes:
// - https://github.com/planetscale/mysql-server/commit/bb777e3e86387571c044fb4a2beb4f8c60462ced
// - https://github.com/planetscale/mysql-server/commit/c2f1344a6863518d749f2eb01a4c74ca08a5b889
// as part of https://github.com/planetscale/mysql-server/releases/tag/8.0.34-ps3.
// Said changes introduce a new global/session boolean variable named 'rename_table_preserve_foreign_key'. It defaults 'false'/0 for backwards compatibility.
// When enabled, a `RENAME TABLE` to a FK parent "pins" the children's foreign keys to the table name rather than the table pointer. Which means after the RENAME,
// the children will point to the newly instated table rather than the original, renamed table.
// (Note: this applies to a particular type of RENAME where we swap tables, see the above blog post).
// For FK children, the MySQL changes simply ignore any Vitess-internal table.
//
// In this stress test, we enable Online DDL if the variable 'rename_table_preserve_foreign_key' is present. The Online DDL mechanism will in turn
// query for this variable, and manipulate it, when starting the migration and when cutting over.
rs, err := shards[0].Vttablets[0].VttabletProcess.QueryTablet("show global variables like 'rename_table_preserve_foreign_key'", keyspaceName, false)
require.NoError(t, err)
fkOnlineDDLPossible = len(rs.Rows) > 0
t.Logf("MySQL support for 'rename_table_preserve_foreign_key': %v", fkOnlineDDLPossible)
})
var testCases = []revertibleTestCase{
{
name: "identical schemas",
fromSchema: `id int primary key, i1 int not null default 0`,
toSchema: `id int primary key, i2 int not null default 0`,
},
{
name: "different schemas, nothing to note",
fromSchema: `id int primary key, i1 int not null default 0, unique key i1_uidx(i1)`,
toSchema: `id int primary key, i1 int not null default 0, i2 int not null default 0, unique key i1_uidx(i1)`,
},
{
name: "removed non-nullable unique key",
fromSchema: `id int primary key, i1 int not null default 0, unique key i1_uidx(i1)`,
toSchema: `id int primary key, i2 int not null default 0`,
removedUniqueKeyNames: `i1_uidx`,
},
{
name: "removed nullable unique key",
fromSchema: `id int primary key, i1 int default null, unique key i1_uidx(i1)`,
toSchema: `id int primary key, i2 int default null`,
removedUniqueKeyNames: `i1_uidx`,
},
{
name: "removed expression unique key, skipped",
fromSchema: `id int primary key, i1 int default null, unique key idx1 ((id + 1))`,
toSchema: `id int primary key, i2 int default null`,
},
{
name: "expanding unique key removes unique constraint",
fromSchema: `id int primary key, i1 int default null, unique key i1_uidx(i1)`,
toSchema: `id int primary key, i1 int default null, unique key i1_uidx(i1, id)`,
removedUniqueKeyNames: `i1_uidx`,
},
{
name: "reducing unique key does not remove unique constraint",
fromSchema: `id int primary key, i1 int default null, unique key i1_uidx(i1, id)`,
toSchema: `id int primary key, i1 int default null, unique key i1_uidx(i1)`,
removedUniqueKeyNames: ``,
},
{
name: "removed foreign key",
fromSchema: "id int primary key, i int, constraint some_fk_1 foreign key (i) references parent (id) on delete cascade",
toSchema: "id int primary key, i int",
removedForeignKeyNames: "some_fk_1",
onlyIfFKOnlineDDLPossible: true,
},
{
name: "renamed foreign key",
fromSchema: "id int primary key, i int, constraint f1 foreign key (i) references parent (id) on delete cascade",
toSchema: "id int primary key, i int, constraint f2 foreign key (i) references parent (id) on delete cascade",
onlyIfFKOnlineDDLPossible: true,
},
{
name: "remove column without default",
fromSchema: `id int primary key, i1 int not null`,
toSchema: `id int primary key, i2 int not null default 0`,
droppedNoDefaultColumnNames: `i1`,
},
{
name: "expanded: nullable",
fromSchema: `id int primary key, i1 int not null, i2 int default null`,
toSchema: `id int primary key, i1 int default null, i2 int not null`,
expandedColumnNames: `i1`,
},
{
name: "expanded: longer text",
fromSchema: `id int primary key, i1 int default null, v1 varchar(40) not null, v2 varchar(5), v3 varchar(3)`,
toSchema: `id int primary key, i1 int not null, v1 varchar(100) not null, v2 char(3), v3 char(5)`,
expandedColumnNames: `v1,v3`,
},
{
name: "expanded: int numeric precision and scale",
fromSchema: `id int primary key, i1 int, i2 tinyint, i3 mediumint, i4 bigint`,
toSchema: `id int primary key, i1 int, i2 mediumint, i3 int, i4 tinyint`,
expandedColumnNames: `i2,i3`,
},
{
name: "expanded: floating point",
fromSchema: `id int primary key, i1 int, n2 bigint, n3 bigint, n4 float, n5 double`,
toSchema: `id int primary key, i1 int, n2 float, n3 double, n4 double, n5 float`,
expandedColumnNames: `n2,n3,n4`,
},
{
name: "expanded: decimal numeric precision and scale",
fromSchema: `id int primary key, i1 int, d1 decimal(10,2), d2 decimal (10,2), d3 decimal (10,2)`,
toSchema: `id int primary key, i1 int, d1 decimal(11,2), d2 decimal (9,1), d3 decimal (10,3)`,
expandedColumnNames: `d1,d3`,
},
{
name: "expanded: signed, unsigned",
fromSchema: `id int primary key, i1 bigint signed, i2 int unsigned, i3 bigint unsigned`,
toSchema: `id int primary key, i1 int signed, i2 int signed, i3 int signed`,
expandedColumnNames: `i2,i3`,
},
{
name: "expanded: signed, unsigned: range",
fromSchema: `id int primary key, i1 int signed, i2 bigint signed, i3 int signed`,
toSchema: `id int primary key, i1 int unsigned, i2 int unsigned, i3 bigint unsigned`,
expandedColumnNames: `i1,i3`,
},
{
name: "expanded: datetime precision",
fromSchema: `id int primary key, dt1 datetime, ts1 timestamp, ti1 time, dt2 datetime(3), dt3 datetime(6), ts2 timestamp(3)`,
toSchema: `id int primary key, dt1 datetime(3), ts1 timestamp(6), ti1 time(3), dt2 datetime(6), dt3 datetime(3), ts2 timestamp`,
expandedColumnNames: `dt1,ts1,ti1,dt2`,
},
{
name: "expanded: strange data type changes",
fromSchema: `id int primary key, dt1 datetime, ts1 timestamp, i1 int, d1 date, e1 enum('a', 'b')`,
toSchema: `id int primary key, dt1 char(32), ts1 varchar(32), i1 tinytext, d1 char(2), e1 varchar(2)`,
expandedColumnNames: `dt1,ts1,i1,d1,e1`,
},
{
name: "expanded: temporal types",
fromSchema: `id int primary key, t1 time, t2 timestamp, t3 date, t4 datetime, t5 time, t6 date`,
toSchema: `id int primary key, t1 datetime, t2 datetime, t3 timestamp, t4 timestamp, t5 timestamp, t6 datetime`,
expandedColumnNames: `t1,t2,t3,t5,t6`,
},
{
name: "expanded: character sets",
fromSchema: `id int primary key, c1 char(3) charset utf8, c2 char(3) charset utf8mb4, c3 char(3) charset ascii, c4 char(3) charset utf8mb4, c5 char(3) charset utf8, c6 char(3) charset latin1`,
toSchema: `id int primary key, c1 char(3) charset utf8mb4, c2 char(3) charset utf8, c3 char(3) charset utf8, c4 char(3) charset ascii, c5 char(3) charset utf8, c6 char(3) charset utf8mb4`,
expandedColumnNames: `c1,c3,c6`,
},
{
name: "expanded: enum",
fromSchema: `id int primary key, e1 enum('a', 'b'), e2 enum('a', 'b'), e3 enum('a', 'b'), e4 enum('a', 'b'), e5 enum('a', 'b'), e6 enum('a', 'b'), e7 enum('a', 'b'), e8 enum('a', 'b')`,
toSchema: `id int primary key, e1 enum('a', 'b'), e2 enum('a'), e3 enum('a', 'b', 'c'), e4 enum('a', 'x'), e5 enum('a', 'x', 'b'), e6 enum('b'), e7 varchar(1), e8 tinyint`,
expandedColumnNames: `e3,e4,e5,e6,e7,e8`,
},
{
name: "expanded: set",
fromSchema: `id int primary key, e1 set('a', 'b'), e2 set('a', 'b'), e3 set('a', 'b'), e4 set('a', 'b'), e5 set('a', 'b'), e6 set('a', 'b'), e7 set('a', 'b'), e8 set('a', 'b')`,
toSchema: `id int primary key, e1 set('a', 'b'), e2 set('a'), e3 set('a', 'b', 'c'), e4 set('a', 'x'), e5 set('a', 'x', 'b'), e6 set('b'), e7 varchar(1), e8 tinyint`,
expandedColumnNames: `e3,e4,e5,e6,e7,e8`,
},
}
var (
createTableWrapper = `CREATE TABLE onlineddl_test(%s)`
dropTableStatement = `
DROP TABLE onlineddl_test
`
tableName = "onlineddl_test"
ddlStrategy = "online --declarative --allow-zero-in-date --unsafe-allow-foreign-keys"
createParentTable = "create table parent (id int primary key)"
)
onlineddl.VtgateExecQuery(t, &vtParams, createParentTable, "")
removeBackticks := func(s string) string {
return strings.Replace(s, "`", "", -1)
}
for _, testcase := range testCases {
t.Run(testcase.name, func(t *testing.T) {
if testcase.onlyIfFKOnlineDDLPossible && !fkOnlineDDLPossible {
t.Skipf("skipped because backing database does not support 'rename_table_preserve_foreign_key'")
return
}
t.Run("ensure table dropped", func(t *testing.T) {
// A preparation step, to clean up anything from the previous test case
uuid := testOnlineDDLStatement(t, dropTableStatement, ddlStrategy, "vtgate", tableName, "")
onlineddl.CheckMigrationStatus(t, &vtParams, shards, uuid, schema.OnlineDDLStatusComplete)
checkTable(t, tableName, false)
})
t.Run("create from-table", func(t *testing.T) {
// A preparation step, to re-create the base table
fromStatement := fmt.Sprintf(createTableWrapper, testcase.fromSchema)
uuid := testOnlineDDLStatement(t, fromStatement, ddlStrategy, "vtgate", tableName, "")
onlineddl.CheckMigrationStatus(t, &vtParams, shards, uuid, schema.OnlineDDLStatusComplete)
checkTable(t, tableName, true)
})
var uuid string
t.Run("run migration", func(t *testing.T) {
// This is the migration we will test, and see whether it is revertible or not (and why not).
toStatement := fmt.Sprintf(createTableWrapper, testcase.toSchema)
uuid = testOnlineDDLStatement(t, toStatement, ddlStrategy, "vtgate", tableName, "")
if !onlineddl.CheckMigrationStatus(t, &vtParams, shards, uuid, schema.OnlineDDLStatusComplete) {
resp, err := throttler.CheckThrottler(clusterInstance, primaryTablet, throttlerapp.TestingName, nil)
assert.NoError(t, err)
fmt.Println("Throttler check response: ", resp)
output, err := throttler.GetThrottlerStatusRaw(&clusterInstance.VtctldClientProcess, primaryTablet)
assert.NoError(t, err)
fmt.Println("Throttler status response: ", output)
}
checkTable(t, tableName, true)
})
t.Run("check migration", func(t *testing.T) {
// All right, the actual test
rs := onlineddl.ReadMigrations(t, &vtParams, uuid)
require.NotNil(t, rs)
for _, row := range rs.Named().Rows {
removedForeignKeyNames := row.AsString("removed_foreign_key_names", "")
removedUniqueKeyNames := row.AsString("removed_unique_key_names", "")
droppedNoDefaultColumnNames := row.AsString("dropped_no_default_column_names", "")
expandedColumnNames := row.AsString("expanded_column_names", "")
// Online DDL renames constraint names, and keeps the original name as a prefix.
// The name of e.g. "some_fk_2_" might turn into "some_fk_2_518ubnm034rel35l1m0u1dc7m"
expectRemovedForeignKeyNames := strings.Split(testcase.removedForeignKeyNames, ",")
actualRemovedForeignKeyNames := strings.Split(removeBackticks(removedForeignKeyNames), ",")
assert.Equal(t, len(expectRemovedForeignKeyNames), len(actualRemovedForeignKeyNames))
for _, actualRemovedForeignKeyName := range actualRemovedForeignKeyNames {
found := false
for _, expectRemovedForeignKeyName := range expectRemovedForeignKeyNames {
if strings.HasPrefix(actualRemovedForeignKeyName, expectRemovedForeignKeyName) {
found = true
}
}
assert.Truef(t, found, "unexpected FK name", "%s", actualRemovedForeignKeyName)
}
assert.Equal(t, testcase.removedUniqueKeyNames, removeBackticks(removedUniqueKeyNames))
assert.Equal(t, testcase.droppedNoDefaultColumnNames, removeBackticks(droppedNoDefaultColumnNames))
assert.Equal(t, testcase.expandedColumnNames, removeBackticks(expandedColumnNames))
}
})
})
}
t.Run("drop fk child table", func(t *testing.T) {
t.Run("ensure table dropped", func(t *testing.T) {
// A preparation step, to clean up anything from the previous test case
uuid := testOnlineDDLStatement(t, dropTableStatement, ddlStrategy, "vtgate", tableName, "")
onlineddl.CheckMigrationStatus(t, &vtParams, shards, uuid, schema.OnlineDDLStatusComplete)
checkTable(t, tableName, false)
})
t.Run("create child table", func(t *testing.T) {
fromStatement := fmt.Sprintf(createTableWrapper, "id int primary key, i int, constraint some_fk_2 foreign key (i) references parent (id) on delete cascade")
uuid := testOnlineDDLStatement(t, fromStatement, ddlStrategy, "vtgate", tableName, "")
onlineddl.CheckMigrationStatus(t, &vtParams, shards, uuid, schema.OnlineDDLStatusComplete)
checkTable(t, tableName, true)
})
var uuid string
t.Run("drop", func(t *testing.T) {
uuid = testOnlineDDLStatement(t, dropTableStatement, ddlStrategy, "vtgate", tableName, "")
onlineddl.CheckMigrationStatus(t, &vtParams, shards, uuid, schema.OnlineDDLStatusComplete)
checkTable(t, tableName, false)
})
t.Run("check migration", func(t *testing.T) {
// All right, the actual test
rs := onlineddl.ReadMigrations(t, &vtParams, uuid)
require.NotNil(t, rs)
for _, row := range rs.Named().Rows {
removedForeignKeyNames := row.AsString("removed_foreign_key_names", "")
removedUniqueKeyNames := row.AsString("removed_unique_key_names", "")
droppedNoDefaultColumnNames := row.AsString("dropped_no_default_column_names", "")
expandedColumnNames := row.AsString("expanded_column_names", "")
// Online DDL renames constraint names, and keeps the original name as a prefix. The name will be e.g. some_fk_2_518ubnm034rel35l1m0u1dc7m
assert.Contains(t, removeBackticks(removedForeignKeyNames), "some_fk_2")
assert.Equal(t, "", removeBackticks(removedUniqueKeyNames))
assert.Equal(t, "", removeBackticks(droppedNoDefaultColumnNames))
assert.Equal(t, "", removeBackticks(expandedColumnNames))
}
})
})
}
func testRevert(t *testing.T) {
var (
partitionedTableName = `part_test`
createStatement = `
CREATE TABLE stress_test (
id bigint(20) not null,
rand_val varchar(32) null default '',
hint_col varchar(64) not null default 'just-created',
created_timestamp timestamp not null default current_timestamp,
updates int unsigned not null default 0,
PRIMARY KEY (id),
key created_idx(created_timestamp),
key updates_idx(updates)
) ENGINE=InnoDB
`
createIfNotExistsStatement = `
CREATE TABLE IF NOT EXISTS stress_test (
id bigint(20) not null,
PRIMARY KEY (id)
) ENGINE=InnoDB
`
dropStatement = `
DROP TABLE stress_test
`
dropIfExistsStatement = `
DROP TABLE IF EXISTS stress_test
`
alterHintStatement = `
ALTER TABLE stress_test modify hint_col varchar(64) not null default '%s'
`
createViewBaseTableStatement = `
CREATE TABLE view_base_table_test (id INT PRIMARY KEY)
`
createViewStatement = `
CREATE VIEW view_test AS SELECT 'success_create' AS msg FROM view_base_table_test
`
createOrReplaceViewStatement = `
CREATE OR REPLACE VIEW view_test AS SELECT 'success_replace' AS msg FROM view_base_table_test
`
alterViewStatement = `
ALTER VIEW view_test AS SELECT 'success_alter' AS msg FROM view_base_table_test
`
dropViewStatement = `
DROP VIEW view_test
`
dropViewIfExistsStatement = `
DROP VIEW IF EXISTS view_test
`
createPartitionedTableStatement = `
CREATE TABLE part_test (
id INT NOT NULL,
ts TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
primary key (id)
)
PARTITION BY RANGE (id) (
PARTITION p1 VALUES LESS THAN (10),
PARTITION p2 VALUES LESS THAN (20),
PARTITION p3 VALUES LESS THAN (30),
PARTITION p4 VALUES LESS THAN (40),
PARTITION p5 VALUES LESS THAN (50),
PARTITION p6 VALUES LESS THAN (60)
)
`
populatePartitionedTableStatement = `
INSERT INTO part_test (id) VALUES (2),(11),(23),(37),(41),(53)
`
)
populatePartitionedTable := func(t *testing.T) {
onlineddl.VtgateExecQuery(t, &vtParams, populatePartitionedTableStatement, "")
}
mysqlVersion = onlineddl.GetMySQLVersion(t, primaryTablet)
require.NotEmpty(t, mysqlVersion)
capableOf := mysql.ServerVersionCapableOf(mysqlVersion)
var uuids []string
ddlStrategy := "online"
testRevertedUUID := func(t *testing.T, uuid string, expectRevertedUUID string) {
rs := onlineddl.ReadMigrations(t, &vtParams, uuid)
require.NotNil(t, rs)
for _, row := range rs.Named().Rows {
revertedUUID := row["reverted_uuid"].ToString()
assert.Equal(t, expectRevertedUUID, revertedUUID)
}
}
t.Run("create base table for view", func(t *testing.T) {
uuid := testOnlineDDLStatementForView(t, createViewBaseTableStatement, ddlStrategy, "vtgate", "")
uuids = append(uuids, uuid)
onlineddl.CheckMigrationStatus(t, &vtParams, shards, uuid, schema.OnlineDDLStatusComplete)
checkTable(t, viewBaseTableName, true)
testRevertedUUID(t, uuid, "")
})
// CREATE VIEW
t.Run("CREATE VIEW where view does not exist", func(t *testing.T) {
// The view does not exist
uuid := testOnlineDDLStatementForView(t, createViewStatement, ddlStrategy, "vtgate", "success_create")
uuids = append(uuids, uuid)
onlineddl.CheckMigrationStatus(t, &vtParams, shards, uuid, schema.OnlineDDLStatusComplete)
checkTable(t, viewName, true)
testRevertedUUID(t, uuid, "")
})
t.Run("revert CREATE VIEW where view does not exist", func(t *testing.T) {
// The view was created, so it will now be dropped (renamed)
revertedUUID := uuids[len(uuids)-1]
uuid := testRevertMigration(t, revertedUUID, ddlStrategy)
uuids = append(uuids, uuid)
onlineddl.CheckMigrationStatus(t, &vtParams, shards, uuid, schema.OnlineDDLStatusComplete)
checkTable(t, viewName, false)
testRevertedUUID(t, uuid, revertedUUID)
})
t.Run("revert revert CREATE VIEW where view does not exist", func(t *testing.T) {
// View was dropped (renamed) so it will now be restored
revertedUUID := uuids[len(uuids)-1]
uuid := testRevertMigration(t, revertedUUID, ddlStrategy)
uuids = append(uuids, uuid)
onlineddl.CheckMigrationStatus(t, &vtParams, shards, uuid, schema.OnlineDDLStatusComplete)
checkTable(t, viewName, true)
testRevertedUUID(t, uuid, revertedUUID)
})
// CREATE OR REPLACE VIEW
t.Run("CREATE PR REPLACE VIEW where view exists", func(t *testing.T) {
// The view exists
uuid := testOnlineDDLStatementForView(t, createOrReplaceViewStatement, ddlStrategy, "vtgate", "success_replace")
uuids = append(uuids, uuid)
onlineddl.CheckMigrationStatus(t, &vtParams, shards, uuid, schema.OnlineDDLStatusComplete)
checkTable(t, viewName, true)
testRevertedUUID(t, uuid, "")
})
t.Run("revert CREATE PR REPLACE VIEW where view exists", func(t *testing.T) {
// Restore original view
revertedUUID := uuids[len(uuids)-1]
uuid := testRevertMigration(t, revertedUUID, ddlStrategy)
uuids = append(uuids, uuid)
onlineddl.CheckMigrationStatus(t, &vtParams, shards, uuid, schema.OnlineDDLStatusComplete)
checkTable(t, viewName, true)
checkMigratedTable(t, viewName, "success_create")
testRevertedUUID(t, uuid, revertedUUID)
})
t.Run("revert revert CREATE PR REPLACE VIEW where view exists", func(t *testing.T) {
// View was dropped (renamed) so it will now be restored
revertedUUID := uuids[len(uuids)-1]
uuid := testRevertMigration(t, revertedUUID, ddlStrategy)
uuids = append(uuids, uuid)
onlineddl.CheckMigrationStatus(t, &vtParams, shards, uuid, schema.OnlineDDLStatusComplete)
checkTable(t, viewName, true)
checkMigratedTable(t, viewName, "success_replace")
testRevertedUUID(t, uuid, revertedUUID)
})
// ALTER VIEW
t.Run("ALTER VIEW where view exists", func(t *testing.T) {
// The view exists
checkTable(t, viewName, true)
uuid := testOnlineDDLStatementForView(t, alterViewStatement, ddlStrategy, "vtgate", "success_alter")
uuids = append(uuids, uuid)
onlineddl.CheckMigrationStatus(t, &vtParams, shards, uuid, schema.OnlineDDLStatusComplete)
checkTable(t, viewName, true)
testRevertedUUID(t, uuid, "")
})
t.Run("revert ALTER VIEW where view exists", func(t *testing.T) {
// Restore original view
revertedUUID := uuids[len(uuids)-1]
uuid := testRevertMigration(t, revertedUUID, ddlStrategy)
uuids = append(uuids, uuid)
onlineddl.CheckMigrationStatus(t, &vtParams, shards, uuid, schema.OnlineDDLStatusComplete)
checkTable(t, viewName, true)
checkMigratedTable(t, viewName, "success_replace")
testRevertedUUID(t, uuid, revertedUUID)
})
t.Run("revert revert ALTER VIEW where view exists", func(t *testing.T) {
// View was dropped (renamed) so it will now be restored
revertedUUID := uuids[len(uuids)-1]
uuid := testRevertMigration(t, revertedUUID, ddlStrategy)
uuids = append(uuids, uuid)
onlineddl.CheckMigrationStatus(t, &vtParams, shards, uuid, schema.OnlineDDLStatusComplete)
checkTable(t, viewName, true)
checkMigratedTable(t, viewName, "success_alter")
testRevertedUUID(t, uuid, revertedUUID)
})
// DROP VIEW
t.Run("online DROP VIEW", func(t *testing.T) {
// view exists
uuid := testOnlineDDLStatementForTable(t, dropViewStatement, "online", "vtgate", "")
uuids = append(uuids, uuid)
onlineddl.CheckMigrationStatus(t, &vtParams, shards, uuid, schema.OnlineDDLStatusComplete)
checkTable(t, viewName, false)
})
t.Run("ALTER VIEW where view does not exist", func(t *testing.T) {
// The view does not exist. Expect failure
uuid := testOnlineDDLStatementForView(t, alterViewStatement, ddlStrategy, "vtgate", "")
onlineddl.CheckMigrationStatus(t, &vtParams, shards, uuid, schema.OnlineDDLStatusFailed)
checkTable(t, viewName, false)
})
t.Run("revert DROP VIEW", func(t *testing.T) {
// This will recreate the view (well, actually, rename it back into place)
uuid := testRevertMigration(t, uuids[len(uuids)-1], ddlStrategy)
uuids = append(uuids, uuid)
onlineddl.CheckMigrationStatus(t, &vtParams, shards, uuid, schema.OnlineDDLStatusComplete)
checkTable(t, viewName, true)
})
t.Run("revert revert DROP VIEW", func(t *testing.T) {
// This will reapply DROP VIEW
uuid := testRevertMigration(t, uuids[len(uuids)-1], ddlStrategy)
uuids = append(uuids, uuid)
onlineddl.CheckMigrationStatus(t, &vtParams, shards, uuid, schema.OnlineDDLStatusComplete)
checkTable(t, viewName, false)
})
t.Run("fail online DROP VIEW", func(t *testing.T) {
// The view does now exist
uuid := testOnlineDDLStatementForTable(t, dropViewStatement, "online", "vtgate", "")
uuids = append(uuids, uuid)
onlineddl.CheckMigrationStatus(t, &vtParams, shards, uuid, schema.OnlineDDLStatusFailed)
checkTable(t, viewName, false)
})
// DROP VIEW IF EXISTS
t.Run("online DROP VIEW IF EXISTS", func(t *testing.T) {
// The view doesn't actually exist right now
uuid := testOnlineDDLStatementForTable(t, dropViewIfExistsStatement, "online", "vtgate", "")
uuids = append(uuids, uuid)
onlineddl.CheckMigrationStatus(t, &vtParams, shards, uuid, schema.OnlineDDLStatusComplete)
checkTable(t, viewName, false)
})
t.Run("revert DROP VIEW IF EXISTS", func(t *testing.T) {
// View will not be recreated because it didn't exist during the DROP VIEW IF EXISTS
uuid := testRevertMigration(t, uuids[len(uuids)-1], ddlStrategy)
uuids = append(uuids, uuid)
onlineddl.CheckMigrationStatus(t, &vtParams, shards, uuid, schema.OnlineDDLStatusComplete)
checkTable(t, viewName, false)
})
t.Run("revert revert DROP VIEW IF EXISTS", func(t *testing.T) {
// View still does not exist
uuid := testRevertMigration(t, uuids[len(uuids)-1], ddlStrategy)
uuids = append(uuids, uuid)
onlineddl.CheckMigrationStatus(t, &vtParams, shards, uuid, schema.OnlineDDLStatusComplete)
checkTable(t, viewName, false)
})
t.Run("revert revert revert DROP VIEW IF EXISTS", func(t *testing.T) {
// View still does not exist
uuid := testRevertMigration(t, uuids[len(uuids)-1], ddlStrategy)
uuids = append(uuids, uuid)
onlineddl.CheckMigrationStatus(t, &vtParams, shards, uuid, schema.OnlineDDLStatusComplete)
checkTable(t, viewName, false)
})
// CREATE
t.Run("CREATE TABLE IF NOT EXISTS where table does not exist", func(t *testing.T) {
// The table does not exist
uuid := testOnlineDDLStatementForTable(t, createIfNotExistsStatement, ddlStrategy, "vtgate", "")
uuids = append(uuids, uuid)
onlineddl.CheckMigrationStatus(t, &vtParams, shards, uuid, schema.OnlineDDLStatusComplete)
checkTable(t, tableName, true)
testRevertedUUID(t, uuid, "")
})
t.Run("revert CREATE TABLE IF NOT EXISTS where did not exist", func(t *testing.T) {
// The table was created, so it will now be dropped (renamed)
revertedUUID := uuids[len(uuids)-1]
uuid := testRevertMigration(t, revertedUUID, ddlStrategy)
uuids = append(uuids, uuid)
onlineddl.CheckMigrationStatus(t, &vtParams, shards, uuid, schema.OnlineDDLStatusComplete)
checkTable(t, tableName, false)
testRevertedUUID(t, uuid, revertedUUID)
})
t.Run("revert revert CREATE TABLE IF NOT EXISTS where did not exist", func(t *testing.T) {
// Table was dropped (renamed) so it will now be restored
revertedUUID := uuids[len(uuids)-1]
uuid := testRevertMigration(t, revertedUUID, ddlStrategy)
uuids = append(uuids, uuid)
onlineddl.CheckMigrationStatus(t, &vtParams, shards, uuid, schema.OnlineDDLStatusComplete)
checkTable(t, tableName, true)
testRevertedUUID(t, uuid, revertedUUID)
})
t.Run("revert revert revert CREATE TABLE IF NOT EXISTS where did not exist", func(t *testing.T) {
// Table was restored, so it will now be dropped (renamed)
revertedUUID := uuids[len(uuids)-1]
uuid := testRevertMigration(t, revertedUUID, ddlStrategy)
uuids = append(uuids, uuid)
onlineddl.CheckMigrationStatus(t, &vtParams, shards, uuid, schema.OnlineDDLStatusComplete)
checkTable(t, tableName, false)
testRevertedUUID(t, uuid, revertedUUID)
})
t.Run("online CREATE TABLE", func(t *testing.T) {
uuid := testOnlineDDLStatementForTable(t, createStatement, ddlStrategy, "vtgate", "just-created")
uuids = append(uuids, uuid)
onlineddl.CheckMigrationStatus(t, &vtParams, shards, uuid, schema.OnlineDDLStatusComplete)
checkTable(t, tableName, true)
initTable(t)
testSelectTableMetrics(t)
testRevertedUUID(t, uuid, "")
})
t.Run("revert CREATE TABLE", func(t *testing.T) {
// This will drop the table (well, actually, rename it away)
uuid := testRevertMigration(t, uuids[len(uuids)-1], ddlStrategy)
uuids = append(uuids, uuid)
onlineddl.CheckMigrationStatus(t, &vtParams, shards, uuid, schema.OnlineDDLStatusComplete)
checkTable(t, tableName, false)
})
t.Run("revert revert CREATE TABLE", func(t *testing.T) {
// Restore the table. Data should still be in the table!
uuid := testRevertMigration(t, uuids[len(uuids)-1], ddlStrategy)
uuids = append(uuids, uuid)
onlineddl.CheckMigrationStatus(t, &vtParams, shards, uuid, schema.OnlineDDLStatusComplete)
checkTable(t, tableName, true)
testSelectTableMetrics(t)
})
t.Run("fail revert older change", func(t *testing.T) {
// We shouldn't be able to revert one-before-last succcessful migration.
uuid := testRevertMigration(t, uuids[len(uuids)-2], ddlStrategy)
uuids = append(uuids, uuid)
onlineddl.CheckMigrationStatus(t, &vtParams, shards, uuid, schema.OnlineDDLStatusFailed)
})
t.Run("CREATE TABLE IF NOT EXISTS where table exists", func(t *testing.T) {
// The table exists. A noop.
uuid := testOnlineDDLStatementForTable(t, createIfNotExistsStatement, ddlStrategy, "vtgate", "")
uuids = append(uuids, uuid)
onlineddl.CheckMigrationStatus(t, &vtParams, shards, uuid, schema.OnlineDDLStatusComplete)
checkTable(t, tableName, true)
})
t.Run("revert CREATE TABLE IF NOT EXISTS where table existed", func(t *testing.T) {
// Since the table already existed, thus not created by the reverts migration,
// we expect to _not_ drop it in this revert. A noop.
uuid := testRevertMigration(t, uuids[len(uuids)-1], ddlStrategy)
uuids = append(uuids, uuid)
onlineddl.CheckMigrationStatus(t, &vtParams, shards, uuid, schema.OnlineDDLStatusComplete)
checkTable(t, tableName, true)
})
t.Run("revert revert CREATE TABLE IF NOT EXISTS where table existed", func(t *testing.T) {
// Table was not dropped, thus isn't re-created, and it just still exists. A noop.
uuid := testRevertMigration(t, uuids[len(uuids)-1], ddlStrategy)
uuids = append(uuids, uuid)
onlineddl.CheckMigrationStatus(t, &vtParams, shards, uuid, schema.OnlineDDLStatusComplete)
checkTable(t, tableName, true)
})
t.Run("fail online CREATE TABLE", func(t *testing.T) {
// Table already exists
uuid := testOnlineDDLStatementForTable(t, createStatement, "online", "vtgate", "just-created")
uuids = append(uuids, uuid)
onlineddl.CheckMigrationStatus(t, &vtParams, shards, uuid, schema.OnlineDDLStatusFailed)
checkTable(t, tableName, true)
})
// ALTER
// Run two ALTER TABLE statements.
// These tests are similar to `onlineddl_vrepl_stress` endtond tests.
// If they fail, it has nothing to do with revert.
// We run these tests because we expect their functionality to work in the next step.
var alterHints []string
for i := 0; i < 2; i++ {
testName := fmt.Sprintf("online ALTER TABLE %d", i)
hint := fmt.Sprintf("hint-alter-%d", i)
alterHints = append(alterHints, hint)
t.Run(testName, func(t *testing.T) {
// One alter. We're not going to revert it.
// This specific test is similar to `onlineddl_vrepl_stress` endtond tests.
// If it fails, it has nothing to do with revert.
// We run this test because we expect its functionality to work in the next step.
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
runMultipleConnections(ctx, t)
}()
func() {
// Ensures runMultipleConnections completes before the overall
// test does, even in the face of calls to t.FailNow() in the
// main goroutine, which still executes deferred functions
defer func() {
cancel() // will cause runMultipleConnections() to terminate
wg.Wait()
}()
uuid := testOnlineDDLStatementForTable(t, fmt.Sprintf(alterHintStatement, hint), "online", "vtgate", hint)
uuids = append(uuids, uuid)
onlineddl.CheckMigrationStatus(t, &vtParams, shards, uuid, schema.OnlineDDLStatusComplete)
}()
testSelectTableMetrics(t)
})
}
t.Run("revert ALTER TABLE", func(t *testing.T) {
// This reverts the last ALTER TABLE.
// And we run traffic on the table during the revert
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
runMultipleConnections(ctx, t)
}()
func() {
// Ensures runMultipleConnections completes before the overall
// test does, even in the face of calls to t.FailNow() in the
// main goroutine, which still executes deferred functions
defer func() {
cancel() // will cause runMultipleConnections() to terminate
wg.Wait()
}()
uuid := testRevertMigration(t, uuids[len(uuids)-1], ddlStrategy)
uuids = append(uuids, uuid)
onlineddl.CheckMigrationStatus(t, &vtParams, shards, uuid, schema.OnlineDDLStatusComplete)
}()
checkMigratedTable(t, tableName, alterHints[0])
testSelectTableMetrics(t)
})
t.Run("revert revert ALTER TABLE", func(t *testing.T) {
// This reverts the last revert (reapplying the last ALTER TABLE).
// And we run traffic on the table during the revert
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
runMultipleConnections(ctx, t)
}()
func() {
// Ensures runMultipleConnections completes before the overall
// test does, even in the face of calls to t.FailNow() in the
// main goroutine, which still executes deferred functions
defer func() {
cancel() // will cause runMultipleConnections() to terminate
wg.Wait()
}()
uuid := testRevertMigration(t, uuids[len(uuids)-1], ddlStrategy)
uuids = append(uuids, uuid)
onlineddl.CheckMigrationStatus(t, &vtParams, shards, uuid, schema.OnlineDDLStatusComplete)
}()
checkMigratedTable(t, tableName, alterHints[1])
testSelectTableMetrics(t)
})
t.Run("revert revert revert ALTER TABLE", func(t *testing.T) {
// For good measure, let's verify that revert-revert-revert works...
// So this again pulls us back to first ALTER
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
runMultipleConnections(ctx, t)
}()
func() {
// Ensures runMultipleConnections completes before the overall
// test does, even in the face of calls to t.FailNow() in the
// main goroutine, which still executes deferred functions
defer func() {
cancel() // will cause runMultipleConnections() to terminate
wg.Wait()
}()
uuid := testRevertMigration(t, uuids[len(uuids)-1], ddlStrategy)
uuids = append(uuids, uuid)
onlineddl.CheckMigrationStatus(t, &vtParams, shards, uuid, schema.OnlineDDLStatusComplete)
}()
checkMigratedTable(t, tableName, alterHints[0])
testSelectTableMetrics(t)
})
testPostponedRevert := func(t *testing.T, expectStatuses ...schema.OnlineDDLStatus) {
require.NotEmpty(t, expectStatuses)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
runMultipleConnections(ctx, t)
}()
// Ensures runMultipleConnections completes before the overall
// test does, even in the face of calls to t.FailNow() in the
// main goroutine, which still executes deferred functions
defer func() {
cancel() // will cause runMultipleConnections() to terminate
wg.Wait()
}()
uuid := testRevertMigration(t, uuids[len(uuids)-1], ddlStrategy+" --postpone-completion")