-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
Copy pathcrdb_internal
368 lines (300 loc) · 12.5 KB
/
crdb_internal
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
# LogicTest: local local-opt fakedist fakedist-opt fakedist-metadata
query error database "crdb_internal" does not exist
ALTER DATABASE crdb_internal RENAME TO not_crdb_internal
statement error schema cannot be modified: "crdb_internal"
CREATE TABLE crdb_internal.t (x INT)
query error database "crdb_internal" does not exist
DROP DATABASE crdb_internal
query TT
SHOW TABLES FROM crdb_internal WITH COMMENT
----
backward_dependencies NULL
builtin_functions NULL
cluster_queries NULL
cluster_sessions NULL
cluster_settings NULL
create_statements NULL
feature_usage NULL
forward_dependencies NULL
gossip_alerts NULL
gossip_liveness NULL
gossip_network NULL
gossip_nodes NULL
index_columns NULL
jobs NULL
kv_node_status NULL
kv_store_status NULL
leases NULL
node_build_info NULL
node_metrics NULL
node_queries NULL
node_runtime_info NULL
node_sessions NULL
node_statement_statistics NULL
partitions NULL
ranges NULL
ranges_no_leases NULL
schema_changes NULL
session_trace NULL
session_variables NULL
table_columns NULL
table_indexes NULL
tables NULL
zones NULL
statement ok
CREATE DATABASE testdb; CREATE TABLE testdb.foo(x INT)
query TIT
SELECT t.name, t.version, t.state FROM crdb_internal.tables AS t JOIN system.namespace AS n ON (n.id = t.parent_id and n.name = 'testdb');
----
foo 1 PUBLIC
# Ensure there is a lease taken on foo.
query I
SELECT * FROM testdb.foo
----
# Check the lease.
query T
SELECT l.name FROM crdb_internal.leases AS l JOIN system.namespace AS n ON (n.id = l.table_id and n.name = 'foo');
----
foo
# We merely check the column list for schema_changes.
query IITTITTT colnames
SELECT * FROM crdb_internal.schema_changes
----
table_id parent_id name type target_id target_name state direction
query IITTITRTTTTTT colnames
SELECT * FROM crdb_internal.tables WHERE NAME = 'namespace'
----
table_id parent_id name database_name version mod_time mod_time_logical format_version state sc_lease_node_id sc_lease_expiration_time drop_time audit_mode
2 1 namespace system 1 1970-01-01 00:00:00 +0000 +0000 0E-10 InterleavedFormatVersion PUBLIC NULL NULL NULL DISABLED
# Verify that table names are not double escaped.
statement ok
CREATE TABLE testdb." ""\'" (i int)
query T
SELECT NAME from crdb_internal.tables WHERE DATABASE_NAME = 'testdb'
----
foo
"\'
query TT colnames
SELECT field, value FROM crdb_internal.node_build_info WHERE field ILIKE 'name'
----
field value
Name CockroachDB
query T rowsort
SELECT field FROM crdb_internal.node_build_info
----
Name
Build
ClusterID
Organization
Version
Channel
# The validity of the rows in this table are tested elsewhere; we merely assert the columns.
query ITTTTTTTTTTRTTI colnames
SELECT * FROM crdb_internal.jobs WHERE false
----
job_id job_type description user_name descriptor_ids status running_status created started finished modified fraction_completed high_water_timestamp error coordinator_id
query IITTITTT colnames
SELECT * FROM crdb_internal.schema_changes WHERE table_id < 0
----
table_id parent_id name type target_id target_name state direction
query IITITB colnames
SELECT * FROM crdb_internal.leases WHERE node_id < 0
----
node_id table_id name parent_id expiration deleted
query ITTTTIIITFFFFFFFFFFFF colnames
SELECT * FROM crdb_internal.node_statement_statistics WHERE node_id < 0
----
node_id application_name flags key anonymized count first_attempt_count max_retries last_error rows_avg rows_var parse_lat_avg parse_lat_var plan_lat_avg plan_lat_var run_lat_avg run_lat_var service_lat_avg service_lat_var overhead_lat_avg overhead_lat_var
query IITTTTTTT colnames
SELECT * FROM crdb_internal.session_trace WHERE span_idx < 0
----
span_idx message_idx timestamp duration operation loc tag message age
query TTTT colnames
SELECT * FROM crdb_internal.cluster_settings WHERE variable = ''
----
variable value type description
query TI colnames
SELECT * FROM crdb_internal.feature_usage WHERE feature_name = ''
----
feature_name usage_count
query TT colnames
SELECT * FROM crdb_internal.session_variables WHERE variable = ''
----
variable value
query TITTTTTBT colnames
SELECT * FROM crdb_internal.node_queries WHERE node_id < 0
----
query_id node_id user_name start query client_address application_name distributed phase
query TITTTTTBT colnames
SELECT * FROM crdb_internal.cluster_queries WHERE node_id < 0
----
query_id node_id user_name start query client_address application_name distributed phase
query ITTTTTTTTTTT colnames
SELECT * FROM crdb_internal.node_sessions WHERE node_id < 0
----
node_id session_id user_name client_address application_name active_queries last_active_query session_start oldest_query_start kv_txn alloc_bytes max_alloc_bytes
query ITTTTTTTTTTT colnames
SELECT * FROM crdb_internal.cluster_sessions WHERE node_id < 0
----
node_id session_id user_name client_address application_name active_queries last_active_query session_start oldest_query_start kv_txn alloc_bytes max_alloc_bytes
query TTTT colnames
SELECT * FROM crdb_internal.builtin_functions WHERE function = ''
----
function signature category details
query ITTITTTTTTT colnames
SELECT * FROM crdb_internal.create_statements WHERE database_name = ''
----
database_id database_name schema_name descriptor_id descriptor_type descriptor_name create_statement state create_nofks alter_statements validate_statements
query ITITTBTB colnames
SELECT * FROM crdb_internal.table_columns WHERE descriptor_name = ''
----
descriptor_id descriptor_name column_id column_name column_type nullable default_expr hidden
query ITITTB colnames
SELECT * FROM crdb_internal.table_indexes WHERE descriptor_name = ''
----
descriptor_id descriptor_name index_id index_name index_type is_unique
query ITITTITT colnames
SELECT * FROM crdb_internal.index_columns WHERE descriptor_name = ''
----
descriptor_id descriptor_name index_id index_name column_type column_id column_name column_direction
query ITIIITITT colnames
SELECT * FROM crdb_internal.backward_dependencies WHERE descriptor_name = ''
----
descriptor_id descriptor_name index_id column_id dependson_id dependson_type dependson_index_id dependson_name dependson_details
query ITIITITT colnames
SELECT * FROM crdb_internal.forward_dependencies WHERE descriptor_name = ''
----
descriptor_id descriptor_name index_id dependedonby_id dependedonby_type dependedonby_index_id dependedonby_name dependedonby_details
query ITTTTT colnames
SELECT * FROM crdb_internal.zones WHERE false
----
zone_id zone_name cli_specifier config_yaml config_sql config_protobuf
statement ok
INSERT INTO system.zones (id, config) VALUES
(18, (SELECT config_protobuf FROM crdb_internal.zones WHERE zone_id = 0)),
(53, (SELECT config_protobuf FROM crdb_internal.zones WHERE zone_id = 0)),
(54, (SELECT config_protobuf FROM crdb_internal.zones WHERE zone_id = 0))
query IT
SELECT zone_id, cli_specifier FROM crdb_internal.zones ORDER BY 1
----
0 .default
1 system
15 system.jobs
16 .meta
17 .system
18 .timeseries
22 .liveness
53 testdb
54 testdb.foo
query T
SELECT quote_literal(config_yaml) FROM crdb_internal.zones WHERE zone_id = 0
----
e'range_min_bytes: 16777216\nrange_max_bytes: 67108864\ngc:\n ttlseconds: 90000\nnum_replicas: 3\nconstraints: []\nlease_preferences: []\n'
query T
SELECT config_sql FROM crdb_internal.zones WHERE zone_id = 0
----
ALTER RANGE default CONFIGURE ZONE USING
range_min_bytes = 16777216,
range_max_bytes = 67108864,
gc.ttlseconds = 90000,
num_replicas = 3,
constraints = '[]',
lease_preferences = '[]'
query error pq: foo
SELECT crdb_internal.force_error('', 'foo')
query error pgcode FOOYAA pq: foo
SELECT crdb_internal.force_error('FOOYAA', 'foo')
query I
select crdb_internal.force_retry(interval '0s')
----
0
query error pq: crdb_internal.set_vmodule\(\): syntax error: expect comma-separated list of filename=N
select crdb_internal.set_vmodule('not anything reasonable')
query I
select crdb_internal.set_vmodule('doesntexist=2,butitsok=4')
----
0
query I
select crdb_internal.set_vmodule('')
----
0
query T
select crdb_internal.node_executable_version()
----
2.1-3
query ITTT colnames
select node_id, component, field, regexp_replace(regexp_replace(value, '^\d+$', '<port>'), e':\\d+', ':<port>') as value from crdb_internal.node_runtime_info
----
node_id component field value
1 DB URL postgresql://root@127.0.0.1:<port>?sslcert=test_certs%2Fclient.root.crt&sslkey=test_certs%2Fclient.root.key&sslmode=verify-full&sslrootcert=test_certs%2Fca.crt
1 DB Scheme postgresql
1 DB User root
1 DB Host 127.0.0.1
1 DB Port <port>
1 DB URI /?sslcert=test_certs%2Fclient.root.crt&sslkey=test_certs%2Fclient.root.key&sslmode=verify-full&sslrootcert=test_certs%2Fca.crt
1 UI URL https://127.0.0.1:<port>
1 UI Scheme https
1 UI User ·
1 UI Host 127.0.0.1
1 UI Port <port>
1 UI URI /
query ITTTTT colnames
SELECT node_id, network, regexp_replace(address, '\d+$', '<port>') as address, attrs, locality, regexp_replace(server_version, '^\d+\.\d+(-\d+)?$', '<server_version>') as server_version FROM crdb_internal.gossip_nodes WHERE node_id = 1
----
node_id network address attrs locality server_version
1 tcp 127.0.0.1:<port> [] {"region": "test"} <server_version>
query IITBB colnames
SELECT node_id, epoch, regexp_replace(expiration, '^\d+\.\d+,\d+$', '<timestamp>') as expiration, draining, decommissioning FROM crdb_internal.gossip_liveness WHERE node_id = 1
----
node_id epoch expiration draining decommissioning
1 1 <timestamp> false false
query ITTTTTT colnames
SELECT node_id, network, regexp_replace(address, '\d+$', '<port>') as address, attrs, locality, regexp_replace(server_version, '^\d+\.\d+(-\d+)?$', '<server_version>') as server_version, regexp_replace(go_version, '^go.+$', '<go_version>') as go_version
FROM crdb_internal.kv_node_status WHERE node_id = 1
----
node_id network address attrs locality server_version go_version
1 tcp 127.0.0.1:<port> [] {"region": "test"} <server_version> <go_version>
query IITI colnames
SELECT node_id, store_id, attrs, used
FROM crdb_internal.kv_store_status WHERE node_id = 1
----
node_id store_id attrs used
1 1 [] 0
statement ok
CREATE TABLE foo (a INT PRIMARY KEY); INSERT INTO foo VALUES(1)
# Make sure that the cluster id isn't unset.
query B
select crdb_internal.cluster_id() != '00000000-0000-0000-0000-000000000000' FROM foo
----
true
# Check that privileged builtins are only allowed for 'root'
user testuser
query error insufficient privilege
select crdb_internal.force_retry(interval '0s')
query error insufficient privilege
select crdb_internal.force_panic('foo')
query error insufficient privilege
select crdb_internal.force_log_fatal('foo')
query error insufficient privilege
select crdb_internal.set_vmodule('')
query error pq: only superusers are allowed to access the node runtime information
select * from crdb_internal.node_runtime_info
query error pq: only superusers are allowed to read crdb_internal.ranges
select * from crdb_internal.ranges
query error pq: only superusers are allowed to read crdb_internal.gossip_nodes
select * from crdb_internal.gossip_nodes
query error pq: only superusers are allowed to read crdb_internal.gossip_liveness
select * from crdb_internal.gossip_liveness
query error pq: only superusers are allowed to read crdb_internal.node_metrics
select * from crdb_internal.node_metrics
query error pq: only superusers are allowed to read crdb_internal.kv_node_status
select * from crdb_internal.kv_node_status
query error pq: only superusers are allowed to read crdb_internal.kv_store_status
select * from crdb_internal.kv_store_status
query error pq: only superusers are allowed to read crdb_internal.gossip_alerts
select * from crdb_internal.gossip_alerts
# Anyone can see the executable version.
query T
select crdb_internal.node_executable_version()
----
2.1-3