|
| 1 | +# Copyright Materialize, Inc. and contributors. All rights reserved. |
| 2 | +# |
| 3 | +# Use of this software is governed by the Business Source License |
| 4 | +# included in the LICENSE file at the root of this repository. |
| 5 | +# |
| 6 | +# As of the Change Date specified in that file, in accordance with |
| 7 | +# the Business Source License, use of this software will be governed |
| 8 | +# by the Apache License, Version 2.0. |
| 9 | + |
| 10 | +# Tests for CREATE/DROP CLUSTER REPLICA SIZE. |
| 11 | + |
| 12 | +mode standard |
| 13 | + |
| 14 | +reset-server |
| 15 | + |
| 16 | +# Cannot create cluster replica size without feature flag. |
| 17 | +statement error is not available |
| 18 | +CREATE CLUSTER REPLICA SIZE custom1 (CREDITS PER HOUR = '1', WORKERS = 2, SCALE = 1) |
| 19 | + |
| 20 | +# Enable the feature flag. |
| 21 | +simple conn=mz_system,user=mz_system |
| 22 | +ALTER SYSTEM SET enable_custom_cluster_replica_sizes = on |
| 23 | +---- |
| 24 | +COMPLETE 0 |
| 25 | + |
| 26 | +# Create a custom cluster replica size. |
| 27 | +simple conn=mz_system,user=mz_system |
| 28 | +CREATE CLUSTER REPLICA SIZE custom1 (CREDITS PER HOUR = '2', WORKERS = 1, SCALE = 1) |
| 29 | +---- |
| 30 | +COMPLETE 0 |
| 31 | + |
| 32 | +# Verify the new size appears in mz_cluster_replica_sizes. |
| 33 | +query TI |
| 34 | +SELECT size, workers FROM mz_cluster_replica_sizes WHERE size = 'custom1' |
| 35 | +---- |
| 36 | +custom1 |
| 37 | +1 |
| 38 | + |
| 39 | +# Creating a duplicate size should fail. |
| 40 | +simple conn=mz_system,user=mz_system |
| 41 | +CREATE CLUSTER REPLICA SIZE custom1 (CREDITS PER HOUR = '3', WORKERS = 1, SCALE = 1) |
| 42 | +---- |
| 43 | +db error: ERROR: cluster replica size 'custom1' already exists |
| 44 | + |
| 45 | +# Allow the custom size for use. |
| 46 | +simple conn=mz_system,user=mz_system |
| 47 | +ALTER SYSTEM SET allowed_cluster_replica_sizes = 'custom1' |
| 48 | +---- |
| 49 | +COMPLETE 0 |
| 50 | + |
| 51 | +# Create a cluster using the custom size. |
| 52 | +statement ok |
| 53 | +CREATE CLUSTER test_cluster REPLICAS (r1 (SIZE 'custom1')) |
| 54 | + |
| 55 | +# Attempting to drop the in-use size should fail. |
| 56 | +simple conn=mz_system,user=mz_system |
| 57 | +DROP CLUSTER REPLICA SIZE custom1 |
| 58 | +---- |
| 59 | +db error: ERROR: cannot drop cluster replica size 'custom1' because it is in use by an existing replica |
| 60 | + |
| 61 | +# Drop the cluster that uses the size. |
| 62 | +statement ok |
| 63 | +DROP CLUSTER test_cluster |
| 64 | + |
| 65 | +# Now we can drop the size. |
| 66 | +simple conn=mz_system,user=mz_system |
| 67 | +DROP CLUSTER REPLICA SIZE custom1 |
| 68 | +---- |
| 69 | +COMPLETE 0 |
| 70 | + |
| 71 | +# Verify the size is gone. |
| 72 | +query I |
| 73 | +SELECT count(*) FROM mz_cluster_replica_sizes WHERE size = 'custom1' |
| 74 | +---- |
| 75 | +0 |
| 76 | + |
| 77 | +# Dropping a nonexistent size should fail. |
| 78 | +simple conn=mz_system,user=mz_system |
| 79 | +DROP CLUSTER REPLICA SIZE nonexistent |
| 80 | +---- |
| 81 | +db error: ERROR: unknown cluster replica size 'nonexistent' |
| 82 | + |
| 83 | +# Create another custom size with more options. |
| 84 | +simple conn=mz_system,user=mz_system |
| 85 | +CREATE CLUSTER REPLICA SIZE custom2 (CREDITS PER HOUR = '5', WORKERS = 4, SCALE = 2, MEMORY LIMIT = '4GiB', CPU LIMIT = '0.5', DISK LIMIT = '512MiB') |
| 86 | +---- |
| 87 | +COMPLETE 0 |
| 88 | + |
| 89 | +# Verify the size properties (4GiB = 4294967296 bytes, 0.5 cores = 500000000 nanocpus). |
| 90 | +query TIIII |
| 91 | +SELECT size, workers, processes, memory_bytes, cpu_nano_cores FROM mz_cluster_replica_sizes WHERE size = 'custom2' |
| 92 | +---- |
| 93 | +custom2 |
| 94 | +4 |
| 95 | +2 |
| 96 | +4294967296 |
| 97 | +500000000 |
| 98 | + |
| 99 | +# Clean up. |
| 100 | +simple conn=mz_system,user=mz_system |
| 101 | +DROP CLUSTER REPLICA SIZE custom2 |
| 102 | +---- |
| 103 | +COMPLETE 0 |
| 104 | + |
| 105 | +# Test millicpus syntax for CPU. |
| 106 | +simple conn=mz_system,user=mz_system |
| 107 | +CREATE CLUSTER REPLICA SIZE custom3 (CREDITS PER HOUR = '1', CPU LIMIT = '250m', MEMORY LIMIT = '1GB') |
| 108 | +---- |
| 109 | +COMPLETE 0 |
| 110 | + |
| 111 | +query TI |
| 112 | +SELECT size, cpu_nano_cores FROM mz_cluster_replica_sizes WHERE size = 'custom3' |
| 113 | +---- |
| 114 | +custom3 |
| 115 | +250000000 |
| 116 | + |
| 117 | +simple conn=mz_system,user=mz_system |
| 118 | +DROP CLUSTER REPLICA SIZE custom3 |
| 119 | +---- |
| 120 | +COMPLETE 0 |
0 commit comments