-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
Copy pathzone_config
264 lines (223 loc) · 7.69 KB
/
zone_config
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
# LogicTest: !3node-tenant(49854)
# Check that we can alter the default zone config.
statement ok
ALTER RANGE default CONFIGURE ZONE USING num_replicas = 1
query IT
SELECT zone_id, raw_config_sql FROM [SHOW ZONE CONFIGURATION FOR RANGE default]
----
0 ALTER RANGE default CONFIGURE ZONE USING
range_min_bytes = 134217728,
range_max_bytes = 536870912,
gc.ttlseconds = 90000,
num_replicas = 1,
constraints = '[]',
lease_preferences = '[]'
# Check that we can reset the default zone config to defaults.
statement ok
ALTER RANGE default CONFIGURE ZONE USING DEFAULT
query IT
SELECT zone_id, raw_config_sql FROM [SHOW ZONE CONFIGURATION FOR RANGE default]
----
0 ALTER RANGE default CONFIGURE ZONE USING
range_min_bytes = 134217728,
range_max_bytes = 536870912,
gc.ttlseconds = 90000,
num_replicas = 3,
constraints = '[]',
lease_preferences = '[]'
# Make an override for the tests below
statement ok
ALTER RANGE default CONFIGURE ZONE USING range_min_bytes = 1234567
statement ok
CREATE TABLE a (id INT PRIMARY KEY)
# Ensure that SHOW ZONE CONFIGURATION retrieves the default zone (ID 0) if
# no zone was set.
query IT
SELECT zone_id, raw_config_sql FROM [SHOW ZONE CONFIGURATION FOR TABLE a]
----
0 ALTER RANGE default CONFIGURE ZONE USING
range_min_bytes = 1234567,
range_max_bytes = 536870912,
gc.ttlseconds = 90000,
num_replicas = 3,
constraints = '[]',
lease_preferences = '[]'
# Once USING DEFAULT has been used, we get the default config
# but with our own zone config ID.
statement ok
ALTER TABLE a CONFIGURE ZONE USING DEFAULT
query IT
SELECT zone_id, raw_config_sql FROM [SHOW ZONE CONFIGURATION FOR TABLE a]
----
53 ALTER TABLE a CONFIGURE ZONE USING
range_min_bytes = 1234567,
range_max_bytes = 536870912,
gc.ttlseconds = 90000,
num_replicas = 3,
constraints = '[]',
lease_preferences = '[]'
# Check that configurations can be adjusted with USING.
statement ok
ALTER TABLE a CONFIGURE ZONE USING
range_min_bytes = 200000 + 1,
range_max_bytes = 300000 + 1,
gc.ttlseconds = 3000 + 600,
num_replicas = floor(1.2)::int,
constraints = '[+region=test]',
lease_preferences = '[[+region=test]]'
# This should reflect in the metrics.
query T
SELECT feature_name FROM crdb_internal.feature_usage
WHERE feature_name IN (
'sql.schema.zone_config.table.range_min_bytes',
'sql.schema.zone_config.table.range_max_bytes',
'sql.schema.zone_config.table.gc.ttlseconds',
'sql.schema.zone_config.table.num_replicas',
'sql.schema.zone_config.table.constraints'
) AND usage_count > 0 ORDER BY feature_name
----
sql.schema.zone_config.table.constraints
sql.schema.zone_config.table.gc.ttlseconds
sql.schema.zone_config.table.num_replicas
sql.schema.zone_config.table.range_max_bytes
sql.schema.zone_config.table.range_min_bytes
query IT
SELECT zone_id, raw_config_sql FROM [SHOW ZONE CONFIGURATION FOR TABLE a]
----
53 ALTER TABLE a CONFIGURE ZONE USING
range_min_bytes = 200001,
range_max_bytes = 300001,
gc.ttlseconds = 3600,
num_replicas = 1,
constraints = '[+region=test]',
lease_preferences = '[[+region=test]]'
# Check that we can set just one value without altering the others.
statement ok
ALTER TABLE a CONFIGURE ZONE USING range_max_bytes = 400000
query IT
SELECT zone_id, raw_config_sql FROM [SHOW ZONE CONFIGURATION FOR TABLE a]
----
53 ALTER TABLE a CONFIGURE ZONE USING
range_min_bytes = 200001,
range_max_bytes = 400000,
gc.ttlseconds = 3600,
num_replicas = 1,
constraints = '[+region=test]',
lease_preferences = '[[+region=test]]'
# Check that we can configure zones in tables in non-public schemas, and that
# they don't conflict with tables of the same name in different schemas.
statement ok
CREATE SCHEMA test
statement ok
CREATE TABLE test.a (a INT PRIMARY KEY)
statement ok
ALTER TABLE test.a CONFIGURE ZONE USING gc.ttlseconds=1234
query IT
SELECT zone_id, raw_config_sql FROM [SHOW ZONE CONFIGURATION FOR TABLE test.a]
----
55 ALTER TABLE test.a CONFIGURE ZONE USING
range_min_bytes = 1234567,
range_max_bytes = 536870912,
gc.ttlseconds = 1234,
num_replicas = 3,
constraints = '[]',
lease_preferences = '[]'
# Check that the original table's zone config is unmodified.
query IT
SELECT zone_id, raw_config_sql FROM [SHOW ZONE CONFIGURATION FOR TABLE a]
----
53 ALTER TABLE a CONFIGURE ZONE USING
range_min_bytes = 200001,
range_max_bytes = 400000,
gc.ttlseconds = 3600,
num_replicas = 1,
constraints = '[+region=test]',
lease_preferences = '[[+region=test]]'
# Check that we can reset the configuration to defaults.
statement ok
ALTER TABLE a CONFIGURE ZONE USING DEFAULT
# Note: the range_min_bytes here should reflect the non-standard
# default that was set initially.
query IT
SELECT zone_id, raw_config_sql FROM [SHOW ZONE CONFIGURATION FOR TABLE a]
----
53 ALTER TABLE a CONFIGURE ZONE USING
range_min_bytes = 1234567,
range_max_bytes = 536870912,
gc.ttlseconds = 90000,
num_replicas = 3,
constraints = '[]',
lease_preferences = '[]'
# Check that we can drop a configuration to get back to inherinting
# the defaults.
statement ok
ALTER TABLE a CONFIGURE ZONE DISCARD
query I
SELECT zone_id FROM [SHOW ZONE CONFIGURATION FOR TABLE a]
----
0
subtest alter_table_telemetry
query T
SELECT feature_name FROM crdb_internal.feature_usage
WHERE feature_name IN ('sql.schema.alter_range.configure_zone', 'sql.schema.alter_table.configure_zone')
ORDER BY feature_name
----
sql.schema.alter_range.configure_zone
sql.schema.alter_table.configure_zone
# Check that configuring num_voters separately from num_replicas behaves as
# expected, across setting them directly and through inheritance.
#
# 1. Check that voter_constraints cannot be set without setting num_voters as
# well.
statement error pq: could not validate zone config: when voter_constraints are set, num_voters must be set as well
ALTER TABLE a CONFIGURE ZONE USING voter_constraints = '{"+region=test": 3}'
# 2. Check that num_voters and voter_constraints show up in tandem once
# num_voters is explicitly set.
statement ok
ALTER TABLE a CONFIGURE ZONE USING num_replicas = 3;
query IT
SELECT zone_id, raw_config_sql FROM [SHOW ZONE CONFIGURATION FOR TABLE a]
----
53 ALTER TABLE a CONFIGURE ZONE USING
range_min_bytes = 1234567,
range_max_bytes = 536870912,
gc.ttlseconds = 90000,
num_replicas = 3,
constraints = '[]',
lease_preferences = '[]'
statement ok
ALTER TABLE a CONFIGURE ZONE USING num_voters = 1;
query IT
SELECT zone_id, raw_config_sql FROM [SHOW ZONE CONFIGURATION FOR TABLE a]
----
53 ALTER TABLE a CONFIGURE ZONE USING
range_min_bytes = 1234567,
range_max_bytes = 536870912,
gc.ttlseconds = 90000,
num_replicas = 3,
num_voters = 1,
constraints = '[]',
voter_constraints = '[]',
lease_preferences = '[]'
# 3. Sanity check that `voter_constraints` can be reset.
statement ok
ALTER TABLE a CONFIGURE ZONE USING voter_constraints = '{"+region=test": 1}'
statement error pq: constraint "\+region=shouldFail" matches no existing nodes within the cluster - did you enter it correctly\?
ALTER TABLE a CONFIGURE ZONE USING voter_constraints = '{"+region=shouldFail": 1}'
# 3.1 Ensure that when copying num_voters from a parent that does not have
# num_voters explicitly configured, we copy the parent's num_replicas value
# instead.
statement ok
ALTER TABLE a CONFIGURE ZONE USING num_voters = COPY FROM PARENT
query IT
SELECT zone_id, raw_config_sql FROM [SHOW ZONE CONFIGURATION FOR TABLE a]
----
53 ALTER TABLE a CONFIGURE ZONE USING
range_min_bytes = 1234567,
range_max_bytes = 536870912,
gc.ttlseconds = 90000,
num_replicas = 3,
num_voters = 3,
constraints = '[]',
voter_constraints = '{+region=test: 1}',
lease_preferences = '[]'