-
Notifications
You must be signed in to change notification settings - Fork 465
/
Copy pathcluster.slt
1048 lines (804 loc) · 32.7 KB
/
cluster.slt
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
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Copyright Materialize, Inc. and contributors. All rights reserved.
#
# Use of this software is governed by the Business Source License
# included in the LICENSE file at the root of this repository.
#
# As of the Change Date specified in that file, in accordance with
# the Business Source License, use of this software will be governed
# by the Apache License, Version 2.0.
# Basic tests of the `CREATE CLUSTER` and `DROP CLUSTER` DDL statements.
mode cockroach
# Start from a pristine state
reset-server
simple conn=mz_system,user=mz_system
ALTER SYSTEM SET unsafe_enable_unorchestrated_cluster_replicas = on;
----
COMPLETE 0
statement error db error: ERROR: Expected one of AVAILABILITY or DISK or INTROSPECTION or MANAGED or REPLICAS or REPLICATION or SIZE or SCHEDULE or WORKLOAD, found EOF
CREATE CLUSTER foo
statement ok
CREATE CLUSTER foo REPLICAS ()
statement error db error: ERROR: Expected one of OWNER or RENAME or RESET or SET or SWAP, found dot
ALTER CLUSTER foo.bar RENAME TO bar
statement ok
ALTER CLUSTER foo RENAME TO bar
statement error unknown cluster 'foo'
ALTER CLUSTER foo RENAME TO bar
simple conn=mz_system,user=mz_system
ALTER SYSTEM SET enable_rbac_checks TO false;
----
COMPLETE 0
statement error db error: ERROR: must be owner of CLUSTER mz_catalog_server
ALTER CLUSTER mz_catalog_server RENAME TO foo
simple conn=mz_system,user=mz_system
ALTER SYSTEM RESET enable_rbac_checks;
----
COMPLETE 0
statement ok
ALTER CLUSTER IF EXISTS bar RENAME TO foo
statement ok
ALTER CLUSTER IF EXISTS bar RENAME TO foo
statement ok
CREATE CLUSTER bar REPLICAS ()
statement error uniqueness violation
ALTER CLUSTER foo RENAME TO bar
statement ok
DROP CLUSTER foo
statement ok
DROP CLUSTER bar
statement error REPLICAS specified more than once
CREATE CLUSTER foo REPLICAS (), REPLICAS()
# Creating cluster w/ remote replica works.
statement ok
CREATE CLUSTER foo REPLICAS (r1 (STORAGECTL ADDRESSES ['s:1234'], STORAGE ADDRESSES ['st:1235'], COMPUTECTL ADDRESSES ['c:1234'], COMPUTE ADDRESSES ['ct:1235']))
statement error cluster 'foo' already exists
CREATE CLUSTER foo REPLICAS (r1 (SIZE '1'))
statement error cannot create multiple replicas named 'r1' on cluster 'bar'
CREATE CLUSTER bar REPLICAS (r1 (SIZE '1'), r1 (SIZE '1'))
statement error COMPUTE ADDRESSES specified more than once
CREATE CLUSTER bar REPLICAS (r1 (COMPUTE ADDRESSES ['localhost:1235'], COMPUTE ADDRESSES ['localhost:1234']))
statement ok
CREATE CLUSTER bar REPLICAS (r1 (SIZE '1'), r2 (SIZE '1'))
query TT rowsort
SELECT id, name FROM mz_clusters
----
s1 mz_system
s2 mz_catalog_server
s3 mz_probe
s4 mz_support
s5 mz_analytics
u1 quickstart
u4 foo
u7 bar
query T rowsort
SELECT name FROM (SHOW CLUSTERS LIKE 'q%')
----
quickstart
# Test invalid option combinations.
statement error invalid mixture of orchestrated and unorchestrated replica options
CREATE CLUSTER baz REPLICAS (r1 (COMPUTE ADDRESSES ['localhost:1234'], SIZE 'small'))
statement error invalid mixture of orchestrated and unorchestrated replica options
CREATE CLUSTER baz REPLICAS (r1 (SIZE '2', WORKERS 1))
statement error invalid mixture of orchestrated and unorchestrated replica options
CREATE CLUSTER baz REPLICAS (r1 (SIZE '2', COMPUTE ADDRESSES ['localhost:1234']))
statement error COMPUTECTL ADDRESSES and COMPUTE ADDRESSES must have the same length
CREATE CLUSTER baz REPLICAS (r1 (STORAGECTL ADDRESSES ['localhost:1234'], STORAGE ADDRESSES ['localhost:1234'], COMPUTECTL ADDRESSES ['localhost:1234', 'localhost:4567'], COMPUTE ADDRESSES [], WORKERS 1))
statement error STORAGECTL ADDRESSES and STORAGE ADDRESSES must have the same length
CREATE CLUSTER baz REPLICAS (r1 (STORAGECTL ADDRESSES ['localhost:1234'], STORAGE ADDRESSES ['localhost:1234', 'localhost:4567'], COMPUTECTL ADDRESSES ['localhost:1234'], COMPUTE ADDRESSES ['localhost:1234'], WORKERS 1))
statement error COMPUTECTL ADDRESSES and STORAGECTL ADDRESSES must have the same length
CREATE CLUSTER baz REPLICAS (r1 (STORAGECTL ADDRESSES ['localhost:1234'], STORAGE ADDRESSES ['localhost:1234'], COMPUTECTL ADDRESSES [], COMPUTE ADDRESSES [], WORKERS 1))
statement error COMPUTECTL ADDRESSES and COMPUTE ADDRESSES must have the same length
CREATE CLUSTER baz REPLICAS (r1 (STORAGECTL ADDRESSES ['localhost:1234'], STORAGE ADDRESSES ['localhost:1234'], COMPUTECTL ADDRESSES [], COMPUTE ADDRESSES ['localhost:1234', 'localhost:4567'], WORKERS 1))
statement error WORKERS must be greater than 0
CREATE CLUSTER baz REPLICAS (r1 (STORAGECTL ADDRESSES ['s:1234'], STORAGE ADDRESSES ['st:1234'], COMPUTECTL ADDRESSES ['c:1234'], COMPUTE ADDRESSES ['t:1235'], WORKERS 0))
# Test `cluster` session variable.
query T
SHOW cluster
----
quickstart
statement ok
SET cluster = 'bar'
query T
SHOW cluster
----
bar
statement ok
CREATE VIEW v AS SELECT 1
statement ok
CREATE DEFAULT INDEX ON v
statement ok
SET cluster = 'quickstart'
query T
SELECT * FROM v
----
1
query TTTTT
SHOW INDEXES ON v IN CLUSTER bar;
----
v_primary_idx v bar {?column?} (empty)
statement ok
CREATE DEFAULT INDEX foo_v_idx IN CLUSTER foo ON v
query TTTTT
SHOW INDEXES IN CLUSTER bar WHERE name NOT LIKE 'mz_%';
----
v_primary_idx v bar {?column?} (empty)
query TTTTTTT
SELECT
clusters.name AS cluster,
objs.name AS on_name,
idxs.name AS key_name,
idx_cols.index_position AS seq_in_index,
obj_cols.name AS column_name,
idx_cols.on_expression AS expression,
idx_cols.nullable AS nullable
FROM
mz_catalog.mz_indexes AS idxs
JOIN mz_catalog.mz_index_columns AS idx_cols ON idxs.id = idx_cols.index_id
JOIN mz_catalog.mz_objects AS objs ON idxs.on_id = objs.id
JOIN mz_catalog.mz_clusters AS clusters ON clusters.id = idxs.cluster_id
LEFT JOIN mz_catalog.mz_columns AS obj_cols
ON idxs.on_id = obj_cols.id AND idx_cols.on_position = obj_cols.position
WHERE clusters.name = 'bar'
ORDER BY on_name, seq_in_index ASC;
----
bar mz_active_peeks_per_worker mz_active_peeks_per_worker_u7_primary_idx 1 id NULL false
bar mz_active_peeks_per_worker mz_active_peeks_per_worker_u7_primary_idx 2 worker_id NULL false
bar mz_arrangement_batcher_allocations_raw mz_arrangement_batcher_allocations_raw_u7_primary_idx 1 operator_id NULL false
bar mz_arrangement_batcher_allocations_raw mz_arrangement_batcher_allocations_raw_u7_primary_idx 2 worker_id NULL false
bar mz_arrangement_batcher_capacity_raw mz_arrangement_batcher_capacity_raw_u7_primary_idx 1 operator_id NULL false
bar mz_arrangement_batcher_capacity_raw mz_arrangement_batcher_capacity_raw_u7_primary_idx 2 worker_id NULL false
bar mz_arrangement_batcher_records_raw mz_arrangement_batcher_records_raw_u7_primary_idx 1 operator_id NULL false
bar mz_arrangement_batcher_records_raw mz_arrangement_batcher_records_raw_u7_primary_idx 2 worker_id NULL false
bar mz_arrangement_batcher_size_raw mz_arrangement_batcher_size_raw_u7_primary_idx 1 operator_id NULL false
bar mz_arrangement_batcher_size_raw mz_arrangement_batcher_size_raw_u7_primary_idx 2 worker_id NULL false
bar mz_arrangement_batches_raw mz_arrangement_batches_raw_u7_primary_idx 1 operator_id NULL false
bar mz_arrangement_batches_raw mz_arrangement_batches_raw_u7_primary_idx 2 worker_id NULL false
bar mz_arrangement_heap_allocations_raw mz_arrangement_heap_allocations_raw_u7_primary_idx 1 operator_id NULL false
bar mz_arrangement_heap_allocations_raw mz_arrangement_heap_allocations_raw_u7_primary_idx 2 worker_id NULL false
bar mz_arrangement_heap_capacity_raw mz_arrangement_heap_capacity_raw_u7_primary_idx 1 operator_id NULL false
bar mz_arrangement_heap_capacity_raw mz_arrangement_heap_capacity_raw_u7_primary_idx 2 worker_id NULL false
bar mz_arrangement_heap_size_raw mz_arrangement_heap_size_raw_u7_primary_idx 1 operator_id NULL false
bar mz_arrangement_heap_size_raw mz_arrangement_heap_size_raw_u7_primary_idx 2 worker_id NULL false
bar mz_arrangement_records_raw mz_arrangement_records_raw_u7_primary_idx 1 operator_id NULL false
bar mz_arrangement_records_raw mz_arrangement_records_raw_u7_primary_idx 2 worker_id NULL false
bar mz_arrangement_sharing_raw mz_arrangement_sharing_raw_u7_primary_idx 1 operator_id NULL false
bar mz_arrangement_sharing_raw mz_arrangement_sharing_raw_u7_primary_idx 2 worker_id NULL false
bar mz_compute_dataflow_global_ids_per_worker mz_compute_dataflow_global_ids_per_worker_u7_primary_idx 1 id NULL false
bar mz_compute_dataflow_global_ids_per_worker mz_compute_dataflow_global_ids_per_worker_u7_primary_idx 2 worker_id NULL false
bar mz_compute_error_counts_raw mz_compute_error_counts_raw_u7_primary_idx 1 export_id NULL false
bar mz_compute_error_counts_raw mz_compute_error_counts_raw_u7_primary_idx 2 worker_id NULL false
bar mz_compute_exports_per_worker mz_compute_exports_per_worker_u7_primary_idx 1 export_id NULL false
bar mz_compute_exports_per_worker mz_compute_exports_per_worker_u7_primary_idx 2 worker_id NULL false
bar mz_compute_frontiers_per_worker mz_compute_frontiers_per_worker_u7_primary_idx 1 export_id NULL false
bar mz_compute_frontiers_per_worker mz_compute_frontiers_per_worker_u7_primary_idx 2 worker_id NULL false
bar mz_compute_hydration_times_per_worker mz_compute_hydration_times_per_worker_u7_primary_idx 1 export_id NULL false
bar mz_compute_hydration_times_per_worker mz_compute_hydration_times_per_worker_u7_primary_idx 2 worker_id NULL false
bar mz_compute_import_frontiers_per_worker mz_compute_import_frontiers_per_worker_u7_primary_idx 1 export_id NULL false
bar mz_compute_import_frontiers_per_worker mz_compute_import_frontiers_per_worker_u7_primary_idx 2 import_id NULL false
bar mz_compute_import_frontiers_per_worker mz_compute_import_frontiers_per_worker_u7_primary_idx 3 worker_id NULL false
bar mz_compute_lir_mapping_per_worker mz_compute_lir_mapping_per_worker_u7_primary_idx 1 global_id NULL false
bar mz_compute_lir_mapping_per_worker mz_compute_lir_mapping_per_worker_u7_primary_idx 2 lir_id NULL false
bar mz_compute_lir_mapping_per_worker mz_compute_lir_mapping_per_worker_u7_primary_idx 3 worker_id NULL false
bar mz_compute_operator_durations_histogram_raw mz_compute_operator_durations_histogram_raw_u7_primary_idx 1 id NULL false
bar mz_compute_operator_durations_histogram_raw mz_compute_operator_durations_histogram_raw_u7_primary_idx 2 worker_id NULL false
bar mz_compute_operator_durations_histogram_raw mz_compute_operator_durations_histogram_raw_u7_primary_idx 3 duration_ns NULL false
bar mz_dataflow_addresses_per_worker mz_dataflow_addresses_per_worker_u7_primary_idx 1 id NULL false
bar mz_dataflow_addresses_per_worker mz_dataflow_addresses_per_worker_u7_primary_idx 2 worker_id NULL false
bar mz_dataflow_channels_per_worker mz_dataflow_channels_per_worker_u7_primary_idx 1 id NULL false
bar mz_dataflow_channels_per_worker mz_dataflow_channels_per_worker_u7_primary_idx 2 worker_id NULL false
bar mz_dataflow_operator_reachability_raw mz_dataflow_operator_reachability_raw_u7_primary_idx 1 id NULL false
bar mz_dataflow_operator_reachability_raw mz_dataflow_operator_reachability_raw_u7_primary_idx 2 worker_id NULL false
bar mz_dataflow_operator_reachability_raw mz_dataflow_operator_reachability_raw_u7_primary_idx 3 source NULL false
bar mz_dataflow_operator_reachability_raw mz_dataflow_operator_reachability_raw_u7_primary_idx 4 port NULL false
bar mz_dataflow_operator_reachability_raw mz_dataflow_operator_reachability_raw_u7_primary_idx 5 update_type NULL false
bar mz_dataflow_operator_reachability_raw mz_dataflow_operator_reachability_raw_u7_primary_idx 6 time NULL true
bar mz_dataflow_operators_per_worker mz_dataflow_operators_per_worker_u7_primary_idx 1 id NULL false
bar mz_dataflow_operators_per_worker mz_dataflow_operators_per_worker_u7_primary_idx 2 worker_id NULL false
bar mz_dataflow_shutdown_durations_histogram_raw mz_dataflow_shutdown_durations_histogram_raw_u7_primary_idx 1 worker_id NULL false
bar mz_dataflow_shutdown_durations_histogram_raw mz_dataflow_shutdown_durations_histogram_raw_u7_primary_idx 2 duration_ns NULL false
bar mz_message_batch_counts_received_raw mz_message_batch_counts_received_raw_u7_primary_idx 1 channel_id NULL false
bar mz_message_batch_counts_received_raw mz_message_batch_counts_received_raw_u7_primary_idx 2 from_worker_id NULL false
bar mz_message_batch_counts_received_raw mz_message_batch_counts_received_raw_u7_primary_idx 3 to_worker_id NULL false
bar mz_message_batch_counts_sent_raw mz_message_batch_counts_sent_raw_u7_primary_idx 1 channel_id NULL false
bar mz_message_batch_counts_sent_raw mz_message_batch_counts_sent_raw_u7_primary_idx 2 from_worker_id NULL false
bar mz_message_batch_counts_sent_raw mz_message_batch_counts_sent_raw_u7_primary_idx 3 to_worker_id NULL false
bar mz_message_counts_received_raw mz_message_counts_received_raw_u7_primary_idx 1 channel_id NULL false
bar mz_message_counts_received_raw mz_message_counts_received_raw_u7_primary_idx 2 from_worker_id NULL false
bar mz_message_counts_received_raw mz_message_counts_received_raw_u7_primary_idx 3 to_worker_id NULL false
bar mz_message_counts_sent_raw mz_message_counts_sent_raw_u7_primary_idx 1 channel_id NULL false
bar mz_message_counts_sent_raw mz_message_counts_sent_raw_u7_primary_idx 2 from_worker_id NULL false
bar mz_message_counts_sent_raw mz_message_counts_sent_raw_u7_primary_idx 3 to_worker_id NULL false
bar mz_peek_durations_histogram_raw mz_peek_durations_histogram_raw_u7_primary_idx 1 worker_id NULL false
bar mz_peek_durations_histogram_raw mz_peek_durations_histogram_raw_u7_primary_idx 2 type NULL false
bar mz_peek_durations_histogram_raw mz_peek_durations_histogram_raw_u7_primary_idx 3 duration_ns NULL false
bar mz_scheduling_elapsed_raw mz_scheduling_elapsed_raw_u7_primary_idx 1 id NULL false
bar mz_scheduling_elapsed_raw mz_scheduling_elapsed_raw_u7_primary_idx 2 worker_id NULL false
bar mz_scheduling_parks_histogram_raw mz_scheduling_parks_histogram_raw_u7_primary_idx 1 worker_id NULL false
bar mz_scheduling_parks_histogram_raw mz_scheduling_parks_histogram_raw_u7_primary_idx 2 slept_for_ns NULL false
bar mz_scheduling_parks_histogram_raw mz_scheduling_parks_histogram_raw_u7_primary_idx 3 requested_ns NULL false
bar v v_primary_idx 1 ?column? NULL false
query TTTTT
SHOW INDEXES;
----
foo_v_idx v foo {?column?} (empty)
v_primary_idx v bar {?column?} (empty)
query T
SELECT
mz_clusters.name
FROM
mz_clusters JOIN mz_indexes ON mz_clusters.id = mz_indexes.cluster_id
WHERE
mz_indexes.name = 'v_primary_idx';
----
bar
# Test invalid setting of `cluster`.
# It's okay to set the `cluster` variable to an invalid cluster.
statement ok
SET cluster = 'bad'
# But you can't do any reads on that cluster.
statement error unknown cluster 'bad'
SELECT * FROM v
# Nor can you create indexes on that cluster.
statement error unknown cluster 'bad'
CREATE MATERIALIZED VIEW v2 AS SELECT 1
# But you can create unmaterialized views on that cluster.
statement ok
CREATE VIEW unmat AS SELECT 1
# Test `CREATE INDEX ... IN CLUSTER`.
statement ok
SET cluster = 'quickstart'
query T
SELECT name FROM mz_indexes WHERE name NOT LIKE 'mz_%' AND name NOT LIKE 'pg_%';
----
foo_v_idx
v_primary_idx
statement ok
CREATE DEFAULT INDEX IN CLUSTER bar ON v
query TTTTT
SHOW INDEXES ON v IN CLUSTER bar;
----
v_primary_idx v bar {?column?} (empty)
v_primary_idx1 v bar {?column?} (empty)
statement error unknown cluster 'noexist'
CREATE DEFAULT INDEX IN CLUSTER noexist ON v
# Test invalid DROPs.
query T
SHOW cluster
----
quickstart
statement error unknown cluster 'baz'
DROP CLUSTER baz
statement error cannot drop cluster "bar" because other objects depend on it
DROP CLUSTER bar
query TTTTT
SHOW INDEXES IN CLUSTER bar WHERE on = 'v';
----
v_primary_idx v bar {?column?} (empty)
v_primary_idx1 v bar {?column?} (empty)
statement ok
DROP INDEX v_primary_idx
statement ok
DROP INDEX v_primary_idx1
# Test valid DROPs
statement ok
DROP CLUSTER bar
statement ok
DROP CLUSTER foo CASCADE
statement ok
CREATE CLUSTER baz REPLICAS (r1 (SIZE '1'))
statement ok
CREATE DEFAULT INDEX IN CLUSTER baz ON v
statement error cannot drop cluster "baz" because other objects depend on it
DROP CLUSTER baz
statement ok
DROP CLUSTER baz CASCADE
query T
SELECT name FROM mz_indexes WHERE name NOT LIKE 'mz_%' AND name NOT LIKE 'pg_%';
----
# Test that dropping a cluster and re-creating it with the same name is valid if introspection sources are enabled
statement ok
CREATE CLUSTER foo REPLICAS (r1 (SIZE '1', INTROSPECTION INTERVAL '1s'))
statement ok
DROP CLUSTER foo CASCADE
statement ok
CREATE CLUSTER foo REPLICAS (r1 (SIZE '1', INTROSPECTION INTERVAL '1s'))
statement ok
DROP CLUSTER foo CASCADE
# Test that bad cluster sizes don't cause a crash
statement error unknown cluster replica size
CREATE CLUSTER foo REPLICAS (a (SIZE 'lol'))
statement ok
CREATE CLUSTER foo REPLICAS (a (SIZE '1'))
statement ok
CREATE CLUSTER foo2 REPLICAS (a (SIZE '32'))
statement ok
CREATE CLUSTER foo3 REPLICAS (a (SIZE '2-2'))
# Ensure that identifiers are correctly handled in value position, even when
# they can't be printed bare. We previously had a bug where `"1"` was
# incorrectly parsed as size `"1"` (quotes included), but `"small"` was parsed
# as size `small` (quotes excluded).
statement ok
CREATE CLUSTER foo4 REPLICAS (a (SIZE "1"))
statement ok
DROP CLUSTER foo, foo2, foo3, foo4 CASCADE
# Test that introspection source indexes are created and dropped correctly
query I
SELECT COUNT(name) FROM mz_indexes WHERE cluster_id = 'u1';
----
31
query I
SELECT COUNT(name) FROM mz_indexes WHERE cluster_id <> 'u1' AND cluster_id NOT LIKE 's%';
----
0
statement ok
CREATE CLUSTER test REPLICAS (foo (SIZE '1'));
query I
SELECT COUNT(name) FROM mz_indexes;
----
286
statement ok
DROP CLUSTER test CASCADE
query T
SELECT COUNT(name) FROM mz_indexes;
----
255
simple conn=mz_system,user=mz_system
ALTER CLUSTER quickstart OWNER TO materialize
----
COMPLETE 0
statement ok
ALTER CLUSTER quickstart SET (MANAGED = false);
statement error invalid SIZE: must provide a string value
CREATE CLUSTER REPLICA quickstart.size_1 SIZE;
statement ok
CREATE CLUSTER REPLICA quickstart.size_1 SIZE '1';
query TTT
SELECT cluster, replica, size FROM (SHOW CLUSTER REPLICAS) ORDER BY 1, 2, 3
----
mz_catalog_server r1 2
mz_probe r1 2
mz_system r1 2
quickstart r1 2
quickstart size_1 1
statement ok
CREATE CLUSTER foo REPLICAS (size_1 (SIZE '1'), size_2 (SIZE '2'))
query TTT
SELECT cluster, replica, size FROM (SHOW CLUSTER REPLICAS) ORDER BY 1, 2, 3
----
foo size_1 1
foo size_2 2
mz_catalog_server r1 2
mz_probe r1 2
mz_system r1 2
quickstart r1 2
quickstart size_1 1
statement ok
DROP CLUSTER REPLICA IF EXISTS quickstart.bar
statement ok
DROP CLUSTER REPLICA IF EXISTS bar.foo
statement ok
DROP CLUSTER REPLICA IF EXISTS quickstart.foo
query error CLUSTER foo has no CLUSTER REPLICA named "foo"
DROP CLUSTER REPLICA quickstart.size_1, foo.foo
statement ok
DROP CLUSTER REPLICA quickstart.size_1
statement ok
DROP CLUSTER REPLICA foo.size_1, foo.size_2
query TTT
SELECT cluster, replica, size FROM (SHOW CLUSTER REPLICAS) ORDER BY 1, 2, 3
----
mz_catalog_server r1 2
mz_probe r1 2
mz_system r1 2
quickstart r1 2
statement ok
CREATE CLUSTER REPLICA quickstart.foo_bar SIZE '1'
statement error db error: ERROR: Expected dot, found RENAME
ALTER CLUSTER REPLICA quickstart RENAME TO bar_foo
statement ok
ALTER CLUSTER REPLICA quickstart.foo_bar RENAME TO bar_foo
statement error CLUSTER quickstart has no CLUSTER REPLICA named "foo_bar"
ALTER CLUSTER REPLICA quickstart.foo_bar RENAME TO bar_foo
statement ok
ALTER CLUSTER REPLICA IF EXISTS quickstart.bar_foo RENAME TO foo_bar
statement ok
ALTER CLUSTER REPLICA IF EXISTS quickstart.bar_foo RENAME TO foo_bar
statement ok
CREATE CLUSTER REPLICA quickstart.bar_foo SIZE '1'
statement error uniqueness violation
ALTER CLUSTER REPLICA quickstart.bar_foo RENAME TO foo_bar
statement ok
DROP CLUSTER REPLICA quickstart.foo_bar
statement ok
DROP CLUSTER REPLICA quickstart.bar_foo
statement ok
CREATE CLUSTER REPLICA quickstart."foo-bar" SIZE '1'
statement ok
DROP CLUSTER REPLICA quickstart."foo-bar"
statement ok
CREATE CLUSTER "foo-bar" REPLICAS ()
statement ok
CREATE CLUSTER REPLICA "foo-bar"."foo-bar" SIZE '1'
statement ok
DROP CLUSTER REPLICA "foo-bar"."foo-bar"
statement ok
DROP CLUSTER "foo-bar"
statement ok
CREATE CLUSTER REPLICA quickstart."好-好" SIZE '1'
statement ok
DROP CLUSTER REPLICA quickstart."好-好"
statement ok
CREATE CLUSTER REPLICA quickstart."好_好" SIZE '1'
statement ok
DROP CLUSTER REPLICA quickstart."好_好"
# clusters wo replicas cannot service selects
statement ok
CREATE CLUSTER empty REPLICAS ()
statement ok
SET cluster = empty
simple
SELECT generate_series(1, 1)
----
db error: ERROR: CLUSTER "empty" has no replicas available to service request
HINT: Use CREATE CLUSTER REPLICA to attach cluster replicas to the cluster
statement ok
DROP CLUSTER empty
statement ok
CREATE CLUSTER empty (SIZE '1', REPLICATION FACTOR 0)
simple
SELECT generate_series(1, 1)
----
db error: ERROR: CLUSTER "empty" has no replicas available to service request
HINT: Use ALTER CLUSTER to adjust the replication factor of the cluster. Example:`ALTER CLUSTER <cluster-name> SET (REPLICATION FACTOR 1)`
simple
SUBSCRIBE (SELECT generate_series(1, 1))
----
db error: ERROR: CLUSTER "empty" has no replicas available to service request
HINT: Use ALTER CLUSTER to adjust the replication factor of the cluster. Example:`ALTER CLUSTER <cluster-name> SET (REPLICATION FACTOR 1)`
# Phillip's tests
statement error zero-length delimited identifier
CREATE CLUSTER REPLICA quickstart."" SIZE '1';
statement error unknown cluster
CREATE CLUSTER REPLICA no_such_cluster.size_1 SIZE '1';
statement error invalid SIZE
CREATE CLUSTER bad REPLICAS (size_2 (SIZE NULL));
statement error unknown cluster replica size
CREATE CLUSTER bad REPLICAS (size_2 (SIZE ''));
statement error unknown cluster replica size
CREATE CLUSTER bad REPLICAS (size_2 (SIZE 'no_such_size'));
statement error invalid SIZE
CREATE CLUSTER bad REPLICAS (size_2 (SIZE 1));
statement error unknown cluster replica size a
CREATE CLUSTER bad REPLICAS (size_2 (SIZE a));
statement ok
DROP CLUSTER foo CASCADE;
statement ok
CREATE CLUSTER foo REPLICAS (size_2 (SIZE '1'));
statement ok
SET cluster=foo
statement ok
CREATE TABLE t1 (f1 INTEGER);
statement ok
INSERT INTO t1 VALUES (1);
query I
SELECT * FROM t1;
----
1
statement error unknown cluster
DROP CLUSTER REPLICA no_such_cluster.bar
statement ok
RESET cluster
statement ok
DROP CLUSTER foo CASCADE
# Availability zones
# Note that we don't support availability zones configured with slt, so they
# can't be meaningfully specified
statement error unknown cluster replica availability zone a
CREATE CLUSTER REPLICA quickstart.replica SIZE '1', AVAILABILITY ZONE 'a'
statement error AVAILABILITY ZONE specified more than once
CREATE CLUSTER REPLICA quickstart.replica AVAILABILITY ZONE 'a', AVAILABILITY ZONE 'b'
statement error invalid mixture of orchestrated and unorchestrated replica options
CREATE CLUSTER REPLICA quickstart.replica STORAGECTL ADDRESSES ['host'], AVAILABILITY ZONE 'a'
statement error invalid mixture of orchestrated and unorchestrated replica options
CREATE CLUSTER REPLICA quickstart.replica STORAGECTL ADDRESSES ['host'], AVAILABILITY ZONE 'a'
statement error invalid mixture of orchestrated and unorchestrated replica options
CREATE CLUSTER REPLICA quickstart.replica AVAILABILITY ZONE 'a', STORAGECTL ADDRESSES ['host']
# Test that the contents of mz_cluster_replicas look sensible
statement ok
CREATE CLUSTER foo REPLICAS (size_1 (SIZE '1'), size_32 (SIZE '32'), size_2_2 (SIZE '2-2'), size_1_8g (SIZE '1-8G'))
query TTTTTTT
SELECT r.name, r.size, s.processes, s.cpu_nano_cores, s.memory_bytes, s.workers, s.credits_per_hour FROM mz_cluster_replicas r JOIN mz_catalog.mz_cluster_replica_sizes s ON r.size = s.size ORDER BY r.name
----
r1 2 1 18446744073709000000 18446744073709551615 2 1
r1 2 1 18446744073709000000 18446744073709551615 2 1
r1 2 1 18446744073709000000 18446744073709551615 2 1
r1 2 1 18446744073709000000 18446744073709551615 2 1
size_1 1 1 18446744073709000000 18446744073709551615 1 1
size_1_8g 1-8G 1 18446744073709000000 8589934592 1 1
size_2_2 2-2 2 18446744073709000000 18446744073709551615 2 2
size_32 32 1 18446744073709000000 18446744073709551615 32 1
statement ok
DROP CLUSTER foo CASCADE
# Restore pristine server state
reset-server
# Tests for BILLED AS replicas
statement ok
CREATE CLUSTER t1 SIZE '1'
simple conn=mz_system,user=mz_system
CREATE CLUSTER REPLICA t1.free SIZE '2', BILLED AS 'free'
----
db error: ERROR: cannot modify managed cluster t1
simple conn=mz_system,user=mz_system
CREATE CLUSTER REPLICA t1.r1234 SIZE '2', INTERNAL, BILLED AS 'free'
----
db error: ERROR: r1234 is reserved for replicas of managed clusters
simple conn=mz_system,user=mz_system
CREATE CLUSTER REPLICA t1.billed SIZE '2', INTERNAL
----
COMPLETE 0
simple conn=mz_system,user=mz_system
CREATE CLUSTER REPLICA t1.free SIZE '2', INTERNAL, BILLED AS 'free'
----
COMPLETE 0
statement error db error: ERROR: cannot modify managed cluster t1
CREATE CLUSTER REPLICA t1.free2 SIZE '2', BILLED AS 'free'
statement error db error: ERROR: cannot specify INTERNAL or BILLED AS as non\-internal user
CREATE CLUSTER REPLICA t1.free2 SIZE '2', INTERNAL
simple conn=mz_system,user=mz_system
CREATE CLUSTER REPLICA t1.invalid SIZE '2'
----
db error: ERROR: cannot modify managed cluster t1
query TTTT
SELECT event_type, object_type, details, user FROM mz_audit_events ORDER BY occurred_at DESC LIMIT 1;
----
create cluster-replica {"billed_as":"free","cluster_id":"u2","cluster_name":"t1","disk":true,"internal":true,"logical_size":"2","reason":"manual","replica_id":"u4","replica_name":"free"} mz_system
simple conn=mz_system,user=mz_system
CREATE CLUSTER REPLICA t1.r123 SIZE '2', BILLED AS 'free'
----
db error: ERROR: cannot modify managed cluster t1
query TTTTT
SELECT id, name, cluster_id, size, owner_id FROM mz_cluster_replicas WHERE cluster_id LIKE 'u%'
----
u1 r1 u1 2 s1
u2 r1 u2 1 u1
u4 free u2 2 u1
u3 billed u2 2 u1
query T
SELECT id FROM mz_internal.mz_internal_cluster_replicas WHERE id LIKE 'u%'
----
u3
u4
statement error db error: ERROR: cannot modify managed cluster t1
CREATE CLUSTER REPLICA t1.free2 SIZE '2', BILLED AS 'free'
statement ok
ALTER CLUSTER t1 SET (MANAGED false);
statement ok
ALTER CLUSTER t1 SET (MANAGED);
statement ok
DROP CLUSTER REPLICA t1.free;
statement error db error: ERROR: cannot drop replica of managed cluster
DROP CLUSTER REPLICA t1.r1;
statement ok
DROP CLUSTER t1
statement ok
CREATE CLUSTER t1 SIZE '1'
simple conn=mz_system,user=mz_system
CREATE CLUSTER REPLICA t1.free SIZE '2', INTERNAL, BILLED AS 'free'
----
COMPLETE 0
statement ok
DROP CLUSTER t1
statement ok
CREATE CLUSTER t1 REPLICAS (r1 (SIZE '1'))
simple conn=mz_system,user=mz_system
CREATE CLUSTER REPLICA t1.free SIZE '2', BILLED AS 'free', INTERNAL
----
COMPLETE 0
query TTTT
SELECT event_type, object_type, details, user FROM mz_audit_events ORDER BY occurred_at DESC LIMIT 1;
----
create cluster-replica {"billed_as":"free","cluster_id":"u4","cluster_name":"t1","disk":true,"internal":true,"logical_size":"2","reason":"manual","replica_id":"u8","replica_name":"free"} mz_system
simple conn=mz_system,user=mz_system
CREATE CLUSTER REPLICA t1.internal_r2 SIZE '2', INTERNAL
----
COMPLETE 0
statement ok
DROP CLUSTER REPLICA t1.internal_r2
simple conn=mz_system,user=mz_system
CREATE CLUSTER REPLICA t1.r2 SIZE '2'
----
COMPLETE 0
statement ok
DROP CLUSTER REPLICA t1.r2
query TTTTT
SELECT id, name, cluster_id, size, owner_id FROM mz_cluster_replicas WHERE cluster_id LIKE 'u%'
----
u1 r1 u1 2 s1
u7 r1 u4 1 u1
u8 free u4 2 u1
simple conn=mz_system,user=mz_system
CREATE CLUSTER REPLICA t1.r3 SIZE '2', BILLED AS 'free'
----
db error: ERROR: must specify INTERNAL when specifying BILLED AS
statement error db error: ERROR: cannot specify INTERNAL or BILLED AS as non\-internal user
CREATE CLUSTER REPLICA t1.free2 SIZE '2', BILLED AS 'free'
statement error db error: ERROR: cannot specify INTERNAL or BILLED AS as non\-internal user
CREATE CLUSTER REPLICA t1.free2 SIZE '2', INTERNAL
statement ok
ALTER CLUSTER t1 SET (MANAGED);
statement ok
ALTER CLUSTER t1 SET (MANAGED false);
statement ok
DROP CLUSTER REPLICA t1.free;
statement ok
DROP CLUSTER REPLICA t1.r1;
statement ok
DROP CLUSTER t1
# Test unmanaged clusters with internal/billed as.
statement error db error: ERROR: cannot specify INTERNAL or BILLED AS as non\-internal user
CREATE CLUSTER t1 (REPLICAS (r1 (SIZE '1', INTERNAL, BILLED AS 'free')));
statement error db error: ERROR: cannot specify INTERNAL or BILLED AS as non\-internal user
CREATE CLUSTER t1 (REPLICAS (internal_r1 (SIZE '1', INTERNAL, BILLED AS 'free')));
statement error db error: ERROR: cannot specify INTERNAL or BILLED AS as non\-internal user
CREATE CLUSTER t1 (REPLICAS (internal_r1 (SIZE '1', BILLED AS 'free')));
statement error db error: ERROR: cannot specify INTERNAL or BILLED AS as non\-internal user
CREATE CLUSTER t1 (REPLICAS (internal_r1 (SIZE '1', INTERNAL)));
simple conn=mz_system,user=mz_system
CREATE CLUSTER t1 (REPLICAS (internal_r1 (SIZE '1', BILLED AS 'free')));
----
db error: ERROR: must specify INTERNAL when specifying BILLED AS
simple conn=mz_system,user=mz_system
CREATE CLUSTER t1 (REPLICAS (internal_r1 (SIZE '1', INTERNAL, BILLED AS 'free')));
----
COMPLETE 0
simple conn=mz_system,user=mz_system
DROP CLUSTER t1
----
COMPLETE 0
# Test SHOW CREATE
mode standard
statement ok
CREATE CLUSTER c1 (SIZE '1', REPLICATION FACTOR 2)
query TT
SHOW CREATE CLUSTER c1
----
c1
CREATE CLUSTER "c1" (DISK = true, INTROSPECTION DEBUGGING = false, INTROSPECTION INTERVAL = INTERVAL '00:00:01', MANAGED = true, REPLICATION FACTOR = 2, SIZE = '1', SCHEDULE = MANUAL)
statement ok
ALTER CLUSTER c1 SET (SIZE = '2');
query TT
SHOW CREATE CLUSTER c1
----
c1
CREATE CLUSTER "c1" (DISK = true, INTROSPECTION DEBUGGING = false, INTROSPECTION INTERVAL = INTERVAL '00:00:01', MANAGED = true, REPLICATION FACTOR = 2, SIZE = '2', SCHEDULE = MANUAL)
statement ok
DROP CLUSTER c1
simple conn=mz_system,user=mz_system
CREATE CLUSTER c1 SIZE = '1' FEATURES (ENABLE EAGER DELTA JOINS = TRUE);
----
COMPLETE 0
query TT
SHOW CREATE CLUSTER c1
----
c1
CREATE CLUSTER "c1" (DISK = true, INTROSPECTION DEBUGGING = false, INTROSPECTION INTERVAL = INTERVAL '00:00:01', MANAGED = true, REPLICATION FACTOR = 1, SIZE = '1', SCHEDULE = MANUAL) FEATURES (ENABLE EAGER DELTA JOINS = true)
simple conn=mz_system,user=mz_system
DROP CLUSTER c1;
----
COMPLETE 0
statement ok
CREATE CLUSTER c1 REPLICAS ()
query error SHOW CREATE for unmanaged clusters not yet supported
SHOW CREATE CLUSTER c1
statement ok
DROP CLUSTER c1
mode cockroach
reset-server
# Test setting and altering WORKLOAD CLASS.
query TT colnames
SELECT * FROM mz_internal.mz_cluster_workload_classes
----
id workload_class
s1 NULL
s2 NULL
s3 NULL
s4 NULL
s5 NULL
u1 NULL
statement error WORKLOAD CLASS not supported for non-system users
CREATE CLUSTER c1 SIZE '1', WORKLOAD CLASS 'production'
simple conn=mz_system,user=mz_system
CREATE CLUSTER c1 SIZE '1', WORKLOAD CLASS 'production'
----
COMPLETE 0
query TT colnames
SELECT * FROM mz_internal.mz_cluster_workload_classes
----
id workload_class
s1 NULL
s2 NULL
s3 NULL
s4 NULL
s5 NULL
u1 NULL
u2 production
simple conn=mz_system,user=mz_system
DROP CLUSTER c1
----
COMPLETE 0
query TT colnames
SELECT * FROM mz_internal.mz_cluster_workload_classes
----
id workload_class
s1 NULL
s2 NULL
s3 NULL
s4 NULL
s5 NULL
u1 NULL
statement ok
CREATE CLUSTER c1 SIZE '1'
query TT colnames
SELECT * FROM mz_internal.mz_cluster_workload_classes
----
id workload_class
s1 NULL
s2 NULL
s3 NULL
s4 NULL
s5 NULL
u1 NULL
u3 NULL
statement error WORKLOAD CLASS not supported for non-system users
ALTER CLUSTER c1 RESET (WORKLOAD CLASS)
statement error WORKLOAD CLASS not supported for non-system users
ALTER CLUSTER c1 SET (WORKLOAD CLASS 'qa')
statement error WORKLOAD CLASS not supported for non-system users
ALTER CLUSTER c1 SET (WORKLOAD CLASS NULL)
simple conn=mz_system,user=mz_system
ALTER CLUSTER c1 RESET (WORKLOAD CLASS)
----
COMPLETE 0