-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
Copy pathconfig_test.go
415 lines (403 loc) · 11.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
/*
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
// 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 two important things:
// 1. Composite or multi-column primary keys
// 2. PKs that contain an ENUM column
//
// 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.
var (
// All standard user tables should have a primary key and at least one secondary key.
initialProductSchema = `
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, name varchar(128) collate utf8mb4_bin, meta json default null, typ enum('individual','soho','enterprise'), 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), 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;
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 customer_nopk(id int, name varchar(128)) CHARSET=utf8;
`
// 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": {},
"customer": {},
"customer_seq": {
"type": "sequence"
},
"customer2": {},
"customer_seq2": {
"type": "sequence"
},
"order_seq": {
"type": "sequence"
},
"Lead": {},
"Lead-1": {},
"db_order_test": {},
"datze": {},
"customer_nopk": {}
}
}
`
customerSchema = ""
customerVSchema = `
{
"sharded": true,
"vindexes": {
"reverse_bits": {
"type": "reverse_bits"
},
"xxhash": {
"type": "xxhash"
},
"bmd5": {
"type": "binary_md5"
}
},
"tables": {
"customer": {
"column_vindexes": [
{
"column": "cid",
"name": "reverse_bits"
}
],
"auto_increment": {
"column": "cid",
"sequence": "customer_seq"
}
},
"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"
}
]
},
"datze": {
"column_vindexes": [
{
"column": "id",
"name": "reverse_bits"
}
]
},
"customer_nopk": {
"column_vindexes": [
{
"column": "id",
"name": "reverse_bits"
}
]
}
}
}
`
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": "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"
},
"xxhash": {
"type": "xxhash"
}
},
"tables": {
"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"
}
]
},
"cproduct": {
"type": "reference"
},
"vproduct": {
"type": "reference"
}
}
}
`
materializeProductSpec = `
{
"workflow": "cproduct",
"sourceKeyspace": "product",
"targetKeyspace": "customer",
"tableSettings": [{
"targetTable": "cproduct",
"sourceExpression": "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"
}]
}
`
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",
"sourceKeyspace": "customer",
"targetKeyspace": "merchant-type",
"tableSettings": [{
"targetTable": "morders",
"sourceExpression": "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",
"sourceKeyspace": "customer",
"targetKeyspace": "merchant-type",
"tableSettings": [{
"targetTable": "msales",
"sourceExpression": "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",
"sourceKeyspace": "customer",
"targetKeyspace": "product",
"tableSettings": [{
"targetTable": "sales",
"sourceExpression": "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",
"sourceKeyspace": "product",
"targetKeyspace": "product",
"tableSettings": [{
"targetTable": "rollup",
"sourceExpression": "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": {}
}
}
`
)