-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
config_test.go
608 lines (593 loc) · 17.8 KB
/
config_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
/*
Copyright 2022 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 vreplication
import (
"fmt"
"strings"
)
// The product, customer, Lead, Lead-1 tables are used to exercise and test most Workflow variants.
// We violate the NO_ZERO_DATES and NO_ZERO_IN_DATE sql_modes that are enabled by default in
// MySQL 5.7+ and MariaDB 10.2+ to ensure that vreplication still works everywhere and the
// permissive sql_mode now used in vreplication causes no unwanted side effects.
// The customer table also tests several important things:
// 1. Composite or multi-column primary keys
// 2. PKs that contain an ENUM column
// 3. That we properly handle tables with auto_increment columns (which are stripped by default when
// moving the table to a sharded keyspace with vtctldclient and left in place when using vtctlclient)
//
// The Lead and Lead-1 tables also allows us to test several things:
// 1. Mixed case identifiers
// 2. Column and table names with special characters in them, namely a dash
// 3. Identifiers using reserved words, as lead is a reserved word in MySQL 8.0+ (https://dev.mysql.com/doc/refman/8.0/en/keywords.html)
//
// The internal table _vt_PURGE_4f9194b43b2011eb8a0104ed332e05c2_20221210194431 should be ignored by vreplication
// The db_order_test table is used to ensure vreplication and vdiff work well with complex non-integer PKs, even across DB versions.
// The db_order_test table needs to use a collation that exists in all versions for cross version tests as we use the collation for the PK
// based merge sort in VDiff. The table is using a non-default collation for any version with utf8mb4 as 5.7 does NOT show the default
// collation in the SHOW CREATE TABLE output which means in the cross version tests the source and target will be using a different collation.
// The vdiff_order table is used to test MySQL sort->VDiff merge sort ordering and ensure it aligns across Reshards. It must not use the
// default collation as it has to work across versions and the 8.0 default does not exist in 5.7.
var (
// All standard user tables should have a primary key and at least one secondary key.
customerTypes = []string{"'individual'", "'soho'", "'enterprise'"}
initialProductSchema = fmt.Sprintf(`
create table product(pid int, description varbinary(128), date1 datetime not null default '0000-00-00 00:00:00', date2 datetime not null default '2021-00-01 00:00:00', primary key(pid), key(date1,date2)) CHARSET=utf8mb4;
create table customer(cid int auto_increment, name varchar(128) collate utf8mb4_bin, meta json default null, industryCategory varchar(100) generated always as (json_extract(meta, _utf8mb4'$.industry')) virtual,
typ enum(%s), sport set('football','cricket','baseball'), ts timestamp not null default current_timestamp, bits bit(2) default b'11', date1 datetime not null default '0000-00-00 00:00:00',
date2 datetime not null default '2021-00-01 00:00:00', dec80 decimal(8,0), blb blob, primary key(cid,typ), key(name)) CHARSET=utf8mb4;
create table customer_seq(id int, next_id bigint, cache bigint, primary key(id)) comment 'vitess_sequence';
create table merchant(mname varchar(128), category varchar(128), primary key(mname), key(category)) CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
create table orders(oid int, cid int, pid int, mname varchar(128), price int, qty int, total int as (qty * price), total2 int as (qty * price) stored, primary key(oid), key(pid), key(cid)) CHARSET=utf8;
create table order_seq(id int, next_id bigint, cache bigint, primary key(id)) comment 'vitess_sequence';
create table customer2(cid int, name varchar(128), typ enum('individual','soho','enterprise'), sport set('football','cricket','baseball'),ts timestamp not null default current_timestamp, primary key(cid), key(ts)) CHARSET=utf8;
create table customer_seq2(id int, next_id bigint, cache bigint, primary key(id)) comment 'vitess_sequence';
create table `+"`Lead`(`Lead-id`"+` binary(16), name varbinary(16), date1 datetime not null default '0000-00-00 00:00:00', date2 datetime not null default '2021-00-01 00:00:00', primary key (`+"`Lead-id`"+`), key (date1));
create table `+"`Lead-1`(`Lead`"+` binary(16), name varbinary(16), date1 datetime not null default '0000-00-00 00:00:00', date2 datetime not null default '2021-00-01 00:00:00', primary key (`+"`Lead`"+`), key (date2));
create table _vt_PURGE_4f9194b43b2011eb8a0104ed332e05c2_20221210194431(id int, val varbinary(128), primary key(id), key(val));
create table db_order_test (c_uuid varchar(64) not null default '', created_at datetime not null, dstuff varchar(128), dtstuff text, dbstuff blob, cstuff char(32), primary key (c_uuid,created_at), key (dstuff)) CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
create table vdiff_order (order_id varchar(50) collate utf8mb4_unicode_ci not null, primary key (order_id), key (order_id)) charset=utf8mb4 COLLATE=utf8mb4_unicode_ci;
create table datze (id int, dt1 datetime not null default current_timestamp, dt2 datetime not null, ts1 timestamp default current_timestamp, primary key (id), key (dt1));
create table json_tbl (id int, j1 json, j2 json, j3 json not null, primary key(id));
create table geom_tbl (id int, g geometry, p point, ls linestring, pg polygon, mp multipoint, mls multilinestring, mpg multipolygon, gc geometrycollection, primary key(id));
create table `+"`blüb_tbl`"+` (id int, val1 varchar(20), `+"`blöb1`"+` blob, val2 varbinary(20), `+"`bl@b2`"+` longblob, txt1 text, blb3 tinyblob, txt2 longtext, blb4 mediumblob, primary key(id));
create table reftable (id int, val1 varchar(20), primary key(id), key(val1));
create table loadtest (id int, name varchar(256), primary key(id), key(name));
create table nopk (name varchar(128), age int unsigned);
`, strings.Join(customerTypes, ","))
// These should always be ignored in vreplication
internalSchema = `
create table _1e275eef_3b20_11eb_a38f_04ed332e05c2_20201210204529_gho(id int, val varbinary(128), primary key(id));
create table _0e8a27c8_1d73_11ec_a579_0aa0c75a6a1d_20210924200735_vrepl(id int, val varbinary(128), primary key(id));
create table _vt_PURGE_1f9194b43b2011eb8a0104ed332e05c2_20201210194431(id int, val varbinary(128), primary key(id));
create table _vt_EVAC_6ace8bcef73211ea87e9f875a4d24e90_29990915120410(id int, val varbinary(128), primary key(id));
create table _vt_DROP_2bce8bcef73211ea87e9f875a4d24e90_20200915120410(id int, val varbinary(128), primary key(id));
create table _vt_HOLD_4abe6bcef73211ea87e9f875a4d24e90_20220115120410(id int, val varbinary(128), primary key(id));
`
initialProductVSchema = `
{
"tables": {
"product": {},
"merchant": {},
"orders": {},
"loadtest": {},
"customer": {},
"customer_seq": {
"type": "sequence"
},
"customer2": {},
"customer_seq2": {
"type": "sequence"
},
"order_seq": {
"type": "sequence"
},
"Lead": {},
"Lead-1": {},
"db_order_test": {},
"vdiff_order": {},
"datze": {},
"nopk": {},
"reftable": {
"type": "reference"
}
}
}
`
customerSchema = ""
customerVSchema = `
{
"sharded": true,
"vindexes": {
"reverse_bits": {
"type": "reverse_bits"
},
"xxhash": {
"type": "xxhash"
},
"unicode_loose_md5": {
"type": "unicode_loose_md5"
},
"bmd5": {
"type": "binary_md5"
}
},
"tables": {
"loadtest": {
"column_vindexes": [
{
"column": "id",
"name": "reverse_bits"
}
]
},
"customer": {
"column_vindexes": [
{
"column": "cid",
"name": "reverse_bits"
}
],
"auto_increment": {
"column": "cid",
"sequence": "` + "`customer_seq`" + `"
}
},
"customer_name": {
"column_vindexes": [
{
"column": "cid",
"name": "xxhash"
}
]
},
"enterprise_customer": {
"column_vindexes": [
{
"column": "cid",
"name": "xxhash"
}
]
},
"customer2": {
"column_vindexes": [
{
"column": "cid",
"name": "reverse_bits"
}
],
"auto_increment": {
"column": "cid",
"sequence": "customer_seq2"
}
},
"Lead": {
"column_vindexes": [
{
"column": "Lead-id",
"name": "bmd5"
}
]
},
"Lead-1": {
"column_vindexes": [
{
"column": "Lead",
"name": "bmd5"
}
]
},
"db_order_test": {
"column_vindexes": [
{
"columns": ["c_uuid", "created_at"],
"name": "xxhash"
}
]
},
"vdiff_order": {
"column_vindexes": [
{
"column": "order_id",
"name": "unicode_loose_md5"
}
]
},
"geom_tbl": {
"column_vindexes": [
{
"column": "id",
"name": "reverse_bits"
}
]
},
"json_tbl": {
"column_vindexes": [
{
"column": "id",
"name": "reverse_bits"
}
]
},
"blüb_tbl": {
"column_vindexes": [
{
"column": "id",
"name": "reverse_bits"
}
]
},
"datze": {
"column_vindexes": [
{
"column": "id",
"name": "reverse_bits"
}
]
},
"nopk": {
"column_vindexes": [
{
"columns": ["name"],
"name": "unicode_loose_md5"
}
]
},
"reftable": {
"type": "reference"
}
}
}
`
merchantVSchema = `
{
"sharded": true,
"vindexes": {
"md5": {
"type": "unicode_loose_md5"
}
},
"tables": {
"merchant": {
"column_vindexes": [
{
"column": "mname",
"name": "md5"
}
]
}
}
}
`
//ordersSchema = "create table order_seq(id int, next_id bigint, cache bigint, primary key(id)) comment 'vitess_sequence';"
ordersVSchema = `
{
"sharded": true,
"vindexes": {
"reverse_bits": {
"type": "reverse_bits"
}
},
"tables": {
"customer": {
"column_vindexes": [
{
"column": "cid",
"name": "reverse_bits"
}
],
"auto_increment": {
"column": "cid",
"sequence": "` + "`product`.`customer_seq`" + `"
}
},
"orders": {
"column_vindexes": [
{
"column": "oid",
"name": "reverse_bits"
}
],
"auto_increment": {
"column": "oid",
"sequence": "order_seq"
}
}
}
}
`
materializeProductVSchema = `
{
"sharded": true,
"vindexes": {
"reverse_bits": {
"type": "reverse_bits"
},
"unicode_loose_md5": {
"type": "unicode_loose_md5"
},
"xxhash": {
"type": "xxhash"
}
},
"tables": {
"loadtest": {
"column_vindexes": [
{
"column": "id",
"name": "reverse_bits"
}
]
},
"customer": {
"column_vindexes": [
{
"column": "cid",
"name": "reverse_bits"
}
],
"auto_increment": {
"column": "cid",
"sequence": "` + "`customer_seq`" + `"
}
},
"orders": {
"column_vindexes": [
{
"column": "oid",
"name": "reverse_bits"
}
],
"auto_increment": {
"column": "oid",
"sequence": "order_seq"
}
},
"db_order_test": {
"column_vindexes": [
{
"columns": ["c_uuid", "created_at"],
"name": "xxhash"
}
]
},
"vdiff_order": {
"column_vindexes": [
{
"column": "order_id",
"name": "unicode_loose_md5"
}
]
},
"geom_tbl": {
"column_vindexes": [
{
"column": "id",
"name": "reverse_bits"
}
]
},
"json_tbl": {
"column_vindexes": [
{
"column": "id",
"name": "reverse_bits"
}
]
},
"blüb_tbl": {
"column_vindexes": [
{
"column": "id",
"name": "reverse_bits"
}
]
},
"cproduct": {
"type": "reference"
},
"vproduct": {
"type": "reference"
},
"reftable": {
"type": "reference"
}
}
}
`
materializeProductSpec = `
{
"workflow": "cproduct",
"source_keyspace": "product",
"target_keyspace": "customer",
"table_settings": [{
"target_table": "cproduct",
"source_expression": "select * from product",
"create_ddl": "create table cproduct(pid bigint, description varchar(128), date1 datetime not null default '0000-00-00 00:00:00', date2 datetime not null default '2021-00-01 00:00:00', primary key(pid)) CHARSET=utf8mb4"
}]
}
`
materializeCustomerNameSpec = `
{
"workflow": "customer_name",
"source_keyspace": "customer",
"target_keyspace": "customer",
"table_settings": [{
"target_table": "customer_name",
"source_expression": "select cid, name from customer",
"create_ddl": "create table if not exists customer_name (cid bigint not null, name varchar(128), primary key(cid), key(name))"
}]
}
`
materializeCustomerTypeSpec = `
{
"workflow": "enterprise_customer",
"source_keyspace": "customer",
"target_keyspace": "customer",
"table_settings": [{
"target_table": "enterprise_customer",
"source_expression": "select cid, name, typ from customer where typ = 'enterprise'",
"create_ddl": "create table if not exists enterprise_customer (cid bigint not null, name varchar(128), typ varchar(64), primary key(cid), key(typ))"
}]
}
`
merchantOrdersVSchema = `
{
"sharded": true,
"vindexes": {
"md5": {
"type": "unicode_loose_md5"
}
},
"tables": {
"merchant": {
"column_vindexes": [
{
"column": "mname",
"name": "md5"
}
]
},
"morders": {
"column_vindexes": [
{
"column": "mname",
"name": "md5"
}
],
"auto_increment": {
"column": "oid",
"sequence": "order_seq"
}
},
"msales": {
"column_vindexes": [
{
"column": "merchant_name",
"name": "md5"
}
]
}
}
}
`
// the merchant-type keyspace allows us to test keyspace names with special characters in them (dash)
materializeMerchantOrdersSpec = `
{
"workflow": "morders",
"source_keyspace": "customer",
"target_keyspace": "merchant-type",
"table_settings": [{
"target_table": "morders",
"source_expression": "select oid, cid, mname, pid, price, qty, total from orders",
"create_ddl": "create table morders(oid int, cid int, mname varchar(128), pid int, price int, qty int, total int, total2 int as (10 * total), primary key(oid)) CHARSET=utf8"
}]
}
`
materializeMerchantSalesSpec = `
{
"workflow": "msales",
"source_keyspace": "customer",
"target_keyspace": "merchant-type",
"table_settings": [{
"target_table": "msales",
"source_expression": "select mname as merchant_name, count(*) as kount, sum(price) as amount from orders group by merchant_name",
"create_ddl": "create table msales(merchant_name varchar(128), kount int, amount int, primary key(merchant_name)) CHARSET=utf8"
}]
}
`
materializeSalesVSchema = `
{
"tables": {
"product": {},
"sales": {},
"customer_seq": {
"type": "sequence"
},
"order_seq": {
"type": "sequence"
}
}
}
`
materializeSalesSpec = `
{
"workflow": "sales",
"source_keyspace": "customer",
"target_keyspace": "product",
"table_settings": [{
"target_Table": "sales",
"source_expression": "select pid, count(*) as kount, sum(price) as amount from orders group by pid",
"create_ddl": "create table sales(pid int, kount int, amount int, primary key(pid)) CHARSET=utf8"
}]
}
`
materializeRollupSpec = `
{
"workflow": "rollup",
"source_keyspace": "product",
"target_keyspace": "product",
"table_settings": [{
"target_table": "rollup",
"source_expression": "select 'total' as rollupname, count(*) as kount from product group by rollupname",
"create_ddl": "create table rollup(rollupname varchar(100), kount int, primary key (rollupname)) CHARSET=utf8mb4"
}]
}
`
initialExternalSchema = `
create table review(rid int, pid int, review varbinary(128), primary key(rid));
create table rating(gid int, pid int, rating int, primary key(gid));
`
initialExternalVSchema = `
{
"tables": {
"review": {},
"rating": {}
}
}
`
jsonValues = []string{
`"abc"`,
`123`,
`{"foo": 456}`,
`{"bar": "foo"}`,
`[1, "abc", 932409834098324908234092834092834, 234234234234234234234234.2342342342349]`,
`{"a":2947293482093480923840923840923, "cba":334234234234234234234234234.234234239090}`,
`[1, "abc", -1, 0.2342342342349, {"a":"b","c":"d","ab":"abc","bc":["x","y"]}]`,
`{"a":2947293482093480923840923840923, "cba":{"a":2947293482093480923840923840923, "cba":334234234234234234234234234.234234239090}}`,
`{"asdf":{"foo":123}}`,
`{"a":"b","c":"d","ab":"abc","bc":["x","y"]}`,
`["here",["I","am"],"!!!"]`,
`{"scopes":"AAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAEAAAAAAEAAAAAA8AAABgAAAAAABAAAACAAAAAAAAA"}`,
`"scalar string"`,
`"scalar stringscalar stringscalar stringscalar stringscalar stringscalar stringscalar stringscalar stringscalar stringscalar string"`,
`"first line\\r\\nsecond line\\rline with escapes\\\\ \\r\\n"`,
`true`,
`false`,
`""`,
`-1`,
`1`,
`32767`,
`32768`,
`-32768`,
`-32769`,
`2.147483647e+09`,
`1.8446744073709552e+19`,
`-9.223372036854776e+18`,
`{}`,
`[]`,
`"2015-01-15 23:24:25.000000"`,
`"23:24:25.000000"`,
`"23:24:25.120000"`,
`"2015-01-15"`,
}
)