# 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; ---- 288 statement ok DROP CLUSTER test CASCADE query T SELECT COUNT(name) FROM mz_indexes; ---- 257 simple conn=mz_system,user=mz_system ALTER CLUSTER quickstart OWNER TO materialize ---- COMPLETE 0 statement ok DROP CLUSTER quickstart; statement ok CREATE CLUSTER quickstart REPLICAS (r1 (SIZE '2')), 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 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 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', REPLICATION FACTOR 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, regexp_replace(details::text, '"replica_id":"u[^"]*"', '"replica_id":"u%"'), 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":"u%","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 TTTT rowsort SELECT name, cluster_id, size, owner_id FROM mz_cluster_replicas WHERE cluster_id = 'u2' ---- free u2 2 u1 billed u2 2 u1 r1 u2 1 u1 query T SELECT regexp_replace(id::text, 'u.*', 'u%') FROM mz_internal.mz_internal_cluster_replicas WHERE id LIKE 'u%' ---- u% u% 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, regexp_replace(details::text, '"replica_id":"u[^"]*"', '"replica_id":"u%"'), 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":"u%","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 TTTT rowsort SELECT name, cluster_id, size, owner_id FROM mz_cluster_replicas WHERE cluster_id = 'u4' ---- r1 u4 1 u1 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 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 simple conn=mz_system,user=mz_system ALTER CLUSTER c1 SET (WORKLOAD CLASS 'qa') ---- 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 u3 qa simple conn=mz_system,user=mz_system ALTER CLUSTER c1 SET (WORKLOAD CLASS NULL) ---- 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 u3 NULL statement ok DROP CLUSTER c1