-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
Copy pathsecondary_region
467 lines (399 loc) · 24.2 KB
/
secondary_region
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
# tenant-cluster-setting-override-opt: allow-multi-region-abstractions-for-secondary-tenants
# LogicTest: multiregion-15node-5region-3azs
query TTTT colnames
SHOW REGIONS
----
region zones database_names primary_region_of
ap-southeast-2 {ap-az1,ap-az2,ap-az3} {} {}
ca-central-1 {ca-az1,ca-az2,ca-az3} {} {}
us-central-1 {usc-az1,usc-az2,usc-az3} {} {}
us-east-1 {us-az1,us-az2,us-az3} {} {}
us-west-1 {usw-az1,usw-az2,usw-az3} {} {}
statement ok
CREATE DATABASE non_mr;
statement error database must be multi-region to support a secondary region
ALTER DATABASE non_mr SET SECONDARY REGION "ap-southeast2"
statement error pq: region .* has not been added to the database
CREATE DATABASE no_list PRIMARY REGION "ap-southeast-2" SECONDARY REGION "ca-central-1"
statement ok
CREATE DATABASE db PRIMARY REGION "ap-southeast-2" REGIONS "ca-central-1" SECONDARY REGION "ca-central-1"
# Verify that the zone configuration on the database is expected.
query TT
SHOW ZONE CONFIGURATION FOR DATABASE db;
----
DATABASE db ALTER DATABASE db CONFIGURE ZONE USING
range_min_bytes = 134217728,
range_max_bytes = 536870912,
gc.ttlseconds = 90000,
num_replicas = 4,
num_voters = 3,
constraints = '{+region=ap-southeast-2: 1, +region=ca-central-1: 1}',
voter_constraints = '[+region=ap-southeast-2]',
lease_preferences = '[[+region=ap-southeast-2, +region=ca-central-1]]'
# Secondary region cannot be the current primary region.
statement error the secondary region cannot be the same as the current primary region
ALTER DATABASE db SET SECONDARY REGION "ap-southeast-2"
# Secondary region has to be a part of the database.
statement error region "us-east-1" has not been added to the database
ALTER DATABASE db SET SECONDARY REGION "us-east-1"
# Create a regional table in the primary region.
statement ok
CREATE TABLE db.rbt_in_primary() LOCALITY REGIONAL BY TABLE;
statement ok
ALTER DATABASE db ADD REGION "us-east-1"
statement error pq: region .* is currently the secondary region
ALTER DATABASE db SET PRIMARY REGION "ca-central-1"
statement ok
ALTER DATABASE db SET SECONDARY REGION "us-east-1"
# Create a regional table outside of the primary region.
statement ok
CREATE TABLE db.rbt_in_us_east() LOCALITY REGIONAL BY TABLE IN "us-east-1";
# Create a regional table in the secondary region.
statement ok
CREATE TABLE db.rbt_in_ca_central() LOCALITY REGIONAL BY TABLE IN "ca-central-1";
statement ok
CREATE TABLE db.rbr() LOCALITY REGIONAL BY ROW
# Add a secondary region.
statement ok
ALTER DATABASE db SET SECONDARY REGION "ca-central-1"
# Verify that the zone configuration on the database is expected.
query TT
SHOW ZONE CONFIGURATION FOR DATABASE db;
----
DATABASE db ALTER DATABASE db CONFIGURE ZONE USING
range_min_bytes = 134217728,
range_max_bytes = 536870912,
gc.ttlseconds = 90000,
num_replicas = 5,
num_voters = 3,
constraints = '{+region=ap-southeast-2: 1, +region=ca-central-1: 1, +region=us-east-1: 1}',
voter_constraints = '[+region=ap-southeast-2]',
lease_preferences = '[[+region=ap-southeast-2, +region=ca-central-1]]'
# Verify that the zone configuration on the table is expected.
query TT
SHOW ZONE CONFIGURATION FOR TABLE db.rbt_in_primary
----
TABLE db.public.rbt_in_primary ALTER TABLE db.public.rbt_in_primary CONFIGURE ZONE USING
range_min_bytes = 134217728,
range_max_bytes = 536870912,
gc.ttlseconds = 90000,
num_replicas = 5,
num_voters = 3,
constraints = '{+region=ap-southeast-2: 1, +region=ca-central-1: 1, +region=us-east-1: 1}',
voter_constraints = '[+region=ap-southeast-2]',
lease_preferences = '[[+region=ap-southeast-2, +region=ca-central-1]]'
query TT
SHOW ZONE CONFIGURATION FOR TABLE db.rbt_in_us_east
----
TABLE db.public.rbt_in_us_east ALTER TABLE db.public.rbt_in_us_east CONFIGURE ZONE USING
range_min_bytes = 134217728,
range_max_bytes = 536870912,
gc.ttlseconds = 90000,
num_replicas = 5,
num_voters = 3,
constraints = '{+region=ap-southeast-2: 1, +region=ca-central-1: 1, +region=us-east-1: 1}',
voter_constraints = '[+region=us-east-1]',
lease_preferences = '[[+region=us-east-1, +region=ca-central-1]]'
query TT
SHOW ZONE CONFIGURATION FOR TABLE db.rbt_in_ca_central
----
TABLE db.public.rbt_in_ca_central ALTER TABLE db.public.rbt_in_ca_central CONFIGURE ZONE USING
range_min_bytes = 134217728,
range_max_bytes = 536870912,
gc.ttlseconds = 90000,
num_replicas = 5,
num_voters = 3,
constraints = '{+region=ap-southeast-2: 1, +region=ca-central-1: 1, +region=us-east-1: 1}',
voter_constraints = '[+region=ca-central-1]',
lease_preferences = '[[+region=ca-central-1]]'
# Verify that the zone configuration on a partition is expected.
query TT
SHOW ZONE CONFIGURATION FOR PARTITION "us-east-1" OF TABLE db.rbr
----
PARTITION "us-east-1" OF TABLE db.public.rbr ALTER PARTITION "us-east-1" OF TABLE db.public.rbr CONFIGURE ZONE USING
range_min_bytes = 134217728,
range_max_bytes = 536870912,
gc.ttlseconds = 90000,
num_replicas = 5,
num_voters = 3,
constraints = '{+region=ap-southeast-2: 1, +region=ca-central-1: 1, +region=us-east-1: 1}',
voter_constraints = '[+region=us-east-1]',
lease_preferences = '[[+region=us-east-1, +region=ca-central-1]]'
query TT
SHOW ZONE CONFIGURATION FOR PARTITION "ap-southeast-2" OF TABLE db.rbr
----
PARTITION "ap-southeast-2" OF TABLE db.public.rbr ALTER PARTITION "ap-southeast-2" OF TABLE db.public.rbr CONFIGURE ZONE USING
range_min_bytes = 134217728,
range_max_bytes = 536870912,
gc.ttlseconds = 90000,
num_replicas = 5,
num_voters = 3,
constraints = '{+region=ap-southeast-2: 1, +region=ca-central-1: 1, +region=us-east-1: 1}',
voter_constraints = '[+region=ap-southeast-2]',
lease_preferences = '[[+region=ap-southeast-2, +region=ca-central-1]]'
query TT
SHOW ZONE CONFIGURATION FOR PARTITION "ca-central-1" OF TABLE db.rbr
----
PARTITION "ca-central-1" OF TABLE db.public.rbr ALTER PARTITION "ca-central-1" OF TABLE db.public.rbr CONFIGURE ZONE USING
range_min_bytes = 134217728,
range_max_bytes = 536870912,
gc.ttlseconds = 90000,
num_replicas = 5,
num_voters = 3,
constraints = '{+region=ap-southeast-2: 1, +region=ca-central-1: 1, +region=us-east-1: 1}',
voter_constraints = '[+region=ca-central-1]',
lease_preferences = '[[+region=ca-central-1]]'
statement ok
SELECT crdb_internal.validate_multi_region_zone_configs()
statement ok
ALTER DATABASE db SURVIVE REGION FAILURE
# Update database to region failure with < 5 regions.
# Verify that the zone configuration on the database is expected.
query TT
SHOW ZONE CONFIGURATION FOR DATABASE db;
----
DATABASE db ALTER DATABASE db CONFIGURE ZONE USING
range_min_bytes = 134217728,
range_max_bytes = 536870912,
gc.ttlseconds = 90000,
num_replicas = 5,
num_voters = 5,
constraints = '{+region=ap-southeast-2: 1, +region=ca-central-1: 1, +region=us-east-1: 1}',
voter_constraints = e'{\'+region=ap-southeast-2,+region=ca-central-1\': 2}',
lease_preferences = '[[+region=ap-southeast-2, +region=ca-central-1]]'
# Verify that the zone configuration on the table is expected.
query TT
SHOW ZONE CONFIGURATION FOR TABLE db.rbt_in_primary
----
TABLE db.public.rbt_in_primary ALTER TABLE db.public.rbt_in_primary CONFIGURE ZONE USING
range_min_bytes = 134217728,
range_max_bytes = 536870912,
gc.ttlseconds = 90000,
num_replicas = 5,
num_voters = 5,
constraints = '{+region=ap-southeast-2: 1, +region=ca-central-1: 1, +region=us-east-1: 1}',
voter_constraints = e'{\'+region=ap-southeast-2,+region=ca-central-1\': 2}',
lease_preferences = '[[+region=ap-southeast-2, +region=ca-central-1]]'
query TT
SHOW ZONE CONFIGURATION FOR TABLE db.rbt_in_us_east
----
TABLE db.public.rbt_in_us_east ALTER TABLE db.public.rbt_in_us_east CONFIGURE ZONE USING
range_min_bytes = 134217728,
range_max_bytes = 536870912,
gc.ttlseconds = 90000,
num_replicas = 5,
num_voters = 5,
constraints = '{+region=ap-southeast-2: 1, +region=ca-central-1: 1, +region=us-east-1: 1}',
voter_constraints = e'{\'+region=us-east-1,+region=ca-central-1\': 2}',
lease_preferences = '[[+region=us-east-1, +region=ca-central-1]]'
query TT
SHOW ZONE CONFIGURATION FOR TABLE db.rbt_in_ca_central
----
TABLE db.public.rbt_in_ca_central ALTER TABLE db.public.rbt_in_ca_central CONFIGURE ZONE USING
range_min_bytes = 134217728,
range_max_bytes = 536870912,
gc.ttlseconds = 90000,
num_replicas = 5,
num_voters = 5,
constraints = '{+region=ap-southeast-2: 1, +region=ca-central-1: 1, +region=us-east-1: 1}',
voter_constraints = '{+region=ca-central-1: 2}',
lease_preferences = '[[+region=ca-central-1]]'
# Verify that the zone configuration on a partition is expected.
query TT
SHOW ZONE CONFIGURATION FOR PARTITION "us-east-1" OF TABLE db.rbr
----
PARTITION "us-east-1" OF TABLE db.public.rbr ALTER PARTITION "us-east-1" OF TABLE db.public.rbr CONFIGURE ZONE USING
range_min_bytes = 134217728,
range_max_bytes = 536870912,
gc.ttlseconds = 90000,
num_replicas = 5,
num_voters = 5,
constraints = '{+region=ap-southeast-2: 1, +region=ca-central-1: 1, +region=us-east-1: 1}',
voter_constraints = e'{\'+region=us-east-1,+region=ca-central-1\': 2}',
lease_preferences = '[[+region=us-east-1, +region=ca-central-1]]'
query TT
SHOW ZONE CONFIGURATION FOR PARTITION "ap-southeast-2" OF TABLE db.rbr
----
PARTITION "ap-southeast-2" OF TABLE db.public.rbr ALTER PARTITION "ap-southeast-2" OF TABLE db.public.rbr CONFIGURE ZONE USING
range_min_bytes = 134217728,
range_max_bytes = 536870912,
gc.ttlseconds = 90000,
num_replicas = 5,
num_voters = 5,
constraints = '{+region=ap-southeast-2: 1, +region=ca-central-1: 1, +region=us-east-1: 1}',
voter_constraints = e'{\'+region=ap-southeast-2,+region=ca-central-1\': 2}',
lease_preferences = '[[+region=ap-southeast-2, +region=ca-central-1]]'
query TT
SHOW ZONE CONFIGURATION FOR PARTITION "ca-central-1" OF TABLE db.rbr
----
PARTITION "ca-central-1" OF TABLE db.public.rbr ALTER PARTITION "ca-central-1" OF TABLE db.public.rbr CONFIGURE ZONE USING
range_min_bytes = 134217728,
range_max_bytes = 536870912,
gc.ttlseconds = 90000,
num_replicas = 5,
num_voters = 5,
constraints = '{+region=ap-southeast-2: 1, +region=ca-central-1: 1, +region=us-east-1: 1}',
voter_constraints = '{+region=ca-central-1: 2}',
lease_preferences = '[[+region=ca-central-1]]'
# Update DATABASE db ADD REGION "us-central-1";
query TT
SHOW ZONE CONFIGURATION FOR DATABASE db;
----
DATABASE db ALTER DATABASE db CONFIGURE ZONE USING
range_min_bytes = 134217728,
range_max_bytes = 536870912,
gc.ttlseconds = 90000,
num_replicas = 5,
num_voters = 5,
constraints = '{+region=ap-southeast-2: 1, +region=ca-central-1: 1, +region=us-east-1: 1}',
voter_constraints = e'{\'+region=ap-southeast-2,+region=ca-central-1\': 2}',
lease_preferences = '[[+region=ap-southeast-2, +region=ca-central-1]]'
# Verify that the zone configuration on the table is expected.
# The number of replicas should be 7.
# We have 5 regions, the primary and secondary region should
# each have 2 replicas. The 3 replicas are distributed between the remaining
# 3 non-primary and non-secondary regions.
query TT
SHOW ZONE CONFIGURATION FOR TABLE db.rbt_in_us_east
----
TABLE db.public.rbt_in_us_east ALTER TABLE db.public.rbt_in_us_east CONFIGURE ZONE USING
range_min_bytes = 134217728,
range_max_bytes = 536870912,
gc.ttlseconds = 90000,
num_replicas = 5,
num_voters = 5,
constraints = '{+region=ap-southeast-2: 1, +region=ca-central-1: 1, +region=us-east-1: 1}',
voter_constraints = e'{\'+region=us-east-1,+region=ca-central-1\': 2}',
lease_preferences = '[[+region=us-east-1, +region=ca-central-1]]'
query TT
SHOW ZONE CONFIGURATION FOR TABLE db.rbt_in_ca_central
----
TABLE db.public.rbt_in_ca_central ALTER TABLE db.public.rbt_in_ca_central CONFIGURE ZONE USING
range_min_bytes = 134217728,
range_max_bytes = 536870912,
gc.ttlseconds = 90000,
num_replicas = 5,
num_voters = 5,
constraints = '{+region=ap-southeast-2: 1, +region=ca-central-1: 1, +region=us-east-1: 1}',
voter_constraints = '{+region=ca-central-1: 2}',
lease_preferences = '[[+region=ca-central-1]]'
# Verify that the zone configuration on a partition is expected.
query TT
SHOW ZONE CONFIGURATION FOR PARTITION "us-east-1" OF TABLE db.rbr
----
PARTITION "us-east-1" OF TABLE db.public.rbr ALTER PARTITION "us-east-1" OF TABLE db.public.rbr CONFIGURE ZONE USING
range_min_bytes = 134217728,
range_max_bytes = 536870912,
gc.ttlseconds = 90000,
num_replicas = 5,
num_voters = 5,
constraints = '{+region=ap-southeast-2: 1, +region=ca-central-1: 1, +region=us-east-1: 1}',
voter_constraints = e'{\'+region=us-east-1,+region=ca-central-1\': 2}',
lease_preferences = '[[+region=us-east-1, +region=ca-central-1]]'
query TT
SHOW ZONE CONFIGURATION FOR PARTITION "ap-southeast-2" OF TABLE db.rbr
----
PARTITION "ap-southeast-2" OF TABLE db.public.rbr ALTER PARTITION "ap-southeast-2" OF TABLE db.public.rbr CONFIGURE ZONE USING
range_min_bytes = 134217728,
range_max_bytes = 536870912,
gc.ttlseconds = 90000,
num_replicas = 5,
num_voters = 5,
constraints = '{+region=ap-southeast-2: 1, +region=ca-central-1: 1, +region=us-east-1: 1}',
voter_constraints = e'{\'+region=ap-southeast-2,+region=ca-central-1\': 2}',
lease_preferences = '[[+region=ap-southeast-2, +region=ca-central-1]]'
query TT
SHOW ZONE CONFIGURATION FOR PARTITION "ca-central-1" OF TABLE db.rbr
----
PARTITION "ca-central-1" OF TABLE db.public.rbr ALTER PARTITION "ca-central-1" OF TABLE db.public.rbr CONFIGURE ZONE USING
range_min_bytes = 134217728,
range_max_bytes = 536870912,
gc.ttlseconds = 90000,
num_replicas = 5,
num_voters = 5,
constraints = '{+region=ap-southeast-2: 1, +region=ca-central-1: 1, +region=us-east-1: 1}',
voter_constraints = '{+region=ca-central-1: 2}',
lease_preferences = '[[+region=ca-central-1]]'
statement error database must be multi-region to support a secondary region
ALTER DATABASE non_mr DROP SECONDARY REGION
statement error pq: cannot drop region .*
ALTER DATABASE db DROP REGION "ca-central-1"
statement ok
ALTER DATABASE db DROP SECONDARY REGION
statement error pq: database .* doesn't have a secondary region defined
ALTER DATABASE db DROP SECONDARY REGION
query T noticetrace
ALTER DATABASE db DROP SECONDARY REGION IF EXISTS
----
NOTICE: No secondary region is defined on the database; skipping
query TT
SHOW ZONE CONFIGURATION FOR TABLE db.rbt_in_us_east
----
TABLE db.public.rbt_in_us_east ALTER TABLE db.public.rbt_in_us_east CONFIGURE ZONE USING
range_min_bytes = 134217728,
range_max_bytes = 536870912,
gc.ttlseconds = 90000,
num_replicas = 5,
num_voters = 5,
constraints = '{+region=ap-southeast-2: 1, +region=ca-central-1: 1, +region=us-east-1: 1}',
voter_constraints = '{+region=us-east-1: 2}',
lease_preferences = '[[+region=us-east-1]]'
query TT
SHOW ZONE CONFIGURATION FOR PARTITION "ap-southeast-2" OF TABLE db.rbr
----
PARTITION "ap-southeast-2" OF TABLE db.public.rbr ALTER PARTITION "ap-southeast-2" OF TABLE db.public.rbr CONFIGURE ZONE USING
range_min_bytes = 134217728,
range_max_bytes = 536870912,
gc.ttlseconds = 90000,
num_replicas = 5,
num_voters = 5,
constraints = '{+region=ap-southeast-2: 1, +region=ca-central-1: 1, +region=us-east-1: 1}',
voter_constraints = '{+region=ap-southeast-2: 2}',
lease_preferences = '[[+region=ap-southeast-2]]'
query TT
SHOW ZONE CONFIGURATION FOR PARTITION "ca-central-1" OF TABLE db.rbr
----
PARTITION "ca-central-1" OF TABLE db.public.rbr ALTER PARTITION "ca-central-1" OF TABLE db.public.rbr CONFIGURE ZONE USING
range_min_bytes = 134217728,
range_max_bytes = 536870912,
gc.ttlseconds = 90000,
num_replicas = 5,
num_voters = 5,
constraints = '{+region=ap-southeast-2: 1, +region=ca-central-1: 1, +region=us-east-1: 1}',
voter_constraints = '{+region=ca-central-1: 2}',
lease_preferences = '[[+region=ca-central-1]]'
# Verify super region interactions
statement ok
SET enable_super_regions = 'on'
# Primary in super region
statement ok
CREATE DATABASE mr1 PRIMARY REGION "us-east-1" REGIONS "ap-southeast-2", "us-central-1","ca-central-1", "us-west-1"
statement ok
ALTER DATABASE mr1 ADD SUPER REGION "test1" VALUES "us-east-1", "us-west-1"
statement error pq: the secondary region must be in the same super region as the current primary region
ALTER DATABASE mr1 SET SECONDARY REGION "ap-southeast-2"
statement ok
ALTER DATABASE mr1 SET SECONDARY REGION "us-west-1"
# Primary outside super region
statement ok
CREATE DATABASE mr2 PRIMARY REGION "ap-southeast-2" REGIONS "ap-southeast-2", "us-central-1","ca-central-1", "us-east-1", "us-west-1"
statement ok
ALTER DATABASE mr2 ADD SUPER REGION "test1" VALUES "us-east-1", "us-west-1"
statement error pq: the secondary region can not be in a super region, unless the primary is also within a super region
ALTER DATABASE mr2 SET SECONDARY REGION "us-east-1"
statement ok
ALTER DATABASE mr2 SET SECONDARY REGION "ca-central-1"
# Multiple super region
statement ok
CREATE DATABASE mr3 PRIMARY REGION "ca-central-1" REGIONS "ap-southeast-2", "us-central-1","ca-central-1", "us-east-1", "us-west-1"
statement ok
ALTER DATABASE mr3 ADD SUPER REGION "test1" VALUES "us-east-1", "us-west-1"
statement ok
ALTER DATABASE mr3 ADD SUPER REGION "test2" VALUES "us-central-1", "ca-central-1"
statement error pq: the secondary region must be in the same super region as the current primary region
ALTER DATABASE mr3 SET SECONDARY REGION "us-east-1"
statement ok
ALTER DATABASE mr3 SET SECONDARY REGION "us-central-1"
# Make sure a secondary region can not be removed from a super region
statement error pq: the secondary region must be in the same super region as the current primary region
ALTER DATABASE mr1 ALTER SUPER REGION "test1" VALUES "us-east-1"