Skip to content

Commit 6737635

Browse files
jubradclaude
andcommitted
catalog: add mz_internal.mz_cluster_replica_size_details
Add a new internal system table that exposes the full cluster replica size configuration, including fields not shown in the public mz_catalog.mz_cluster_replica_sizes table: - node_selectors (JSONB): Kubernetes node selectors for scheduling - is_cc (bool): whether this is a modern cc-style size - swap_enabled (bool): whether swap is the spill-to-disk mechanism - cpu_exclusive (bool): exclusive CPU access per process - disabled (bool): whether the size is blocked from new replicas - builtin (bool): whether from env var or user-defined via SQL The table is in mz_internal with access restricted to mz_support (and mz_system as superuser), keeping internal scheduling details out of the public catalog. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 7d80262 commit 6737635

10 files changed

Lines changed: 257 additions & 61 deletions

File tree

doc/user/content/reference/system-catalog/mz_internal.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ At this time, we do not make any guarantees about the exactness or freshness of
183183
| `heap_bytes` | [`uint8`] | Approximate heap (RAM + swap) usage, in bytes.
184184
| `heap_limit` | [`uint8`] | Available heap (RAM + swap) space, in bytes.
185185

186+
<!-- RELATION_SPEC_UNDOCUMENTED mz_internal.mz_cluster_replica_size_details -->
187+
186188
## `mz_cluster_replica_metrics_history`
187189

188190
{{< warn-if-unreleased v0.116 >}}

src/adapter/src/coord.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2391,12 +2391,8 @@ impl Coordinator {
23912391
self.initialize_read_policies(&policies, cw).await;
23922392
}
23932393

2394-
// Expose mapping from T-shirt sizes to actual sizes
2395-
builtin_table_updates.extend(
2396-
self.catalog().state().resolve_builtin_table_updates(
2397-
self.catalog().state().pack_all_replica_size_updates(),
2398-
),
2399-
);
2394+
// Cluster replica sizes are now durable objects; their builtin table updates
2395+
// are generated via state updates in apply.rs, so no manual packing needed here.
24002396

24012397
debug!("startup: coordinator init: bootstrap: initializing migrated builtin tables");
24022398
// When 0dt is enabled, we create new shards for any migrated builtin storage collections.

src/catalog/src/builtin.rs

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3957,6 +3957,75 @@ pub static MZ_CLUSTER_REPLICA_SIZES: LazyLock<BuiltinTable> = LazyLock::new(|| B
39573957
access: vec![PUBLIC_SELECT],
39583958
});
39593959

3960+
pub static MZ_CLUSTER_REPLICA_SIZE_DETAILS: LazyLock<BuiltinTable> =
3961+
LazyLock::new(|| BuiltinTable {
3962+
name: "mz_cluster_replica_size_details",
3963+
schema: MZ_INTERNAL_SCHEMA,
3964+
oid: oid::TABLE_MZ_CLUSTER_REPLICA_SIZE_DETAILS_OID,
3965+
desc: RelationDesc::builder()
3966+
.with_column("size", SqlScalarType::String.nullable(false))
3967+
.with_column("processes", SqlScalarType::UInt64.nullable(false))
3968+
.with_column("workers", SqlScalarType::UInt64.nullable(false))
3969+
.with_column("cpu_nano_cores", SqlScalarType::UInt64.nullable(false))
3970+
.with_column("memory_bytes", SqlScalarType::UInt64.nullable(false))
3971+
.with_column("disk_bytes", SqlScalarType::UInt64.nullable(true))
3972+
.with_column(
3973+
"credits_per_hour",
3974+
SqlScalarType::Numeric { max_scale: None }.nullable(false),
3975+
)
3976+
.with_column("cpu_exclusive", SqlScalarType::Bool.nullable(false))
3977+
.with_column("is_cc", SqlScalarType::Bool.nullable(false))
3978+
.with_column("swap_enabled", SqlScalarType::Bool.nullable(false))
3979+
.with_column("disabled", SqlScalarType::Bool.nullable(false))
3980+
.with_column("builtin", SqlScalarType::Bool.nullable(false))
3981+
.with_column("node_selectors", SqlScalarType::Jsonb.nullable(false))
3982+
.finish(),
3983+
column_comments: BTreeMap::from_iter([
3984+
("size", "The human-readable replica size name."),
3985+
(
3986+
"processes",
3987+
"The number of processes (scale) in the replica.",
3988+
),
3989+
(
3990+
"workers",
3991+
"The number of Timely Dataflow workers per process.",
3992+
),
3993+
(
3994+
"cpu_nano_cores",
3995+
"The CPU allocation per process, in billionths of a vCPU core.",
3996+
),
3997+
("memory_bytes", "The RAM allocation per process, in bytes."),
3998+
("disk_bytes", "The disk allocation per process, in bytes."),
3999+
(
4000+
"credits_per_hour",
4001+
"The number of compute credits consumed per hour.",
4002+
),
4003+
(
4004+
"cpu_exclusive",
4005+
"Whether each process has exclusive access to its CPU cores.",
4006+
),
4007+
("is_cc", "Whether this is a modern cc-style size."),
4008+
(
4009+
"swap_enabled",
4010+
"Whether swap is used as the spill-to-disk mechanism.",
4011+
),
4012+
(
4013+
"disabled",
4014+
"Whether this size is disabled and cannot be used for new replicas.",
4015+
),
4016+
(
4017+
"builtin",
4018+
"Whether this size is a builtin (from env var) or user-defined.",
4019+
),
4020+
(
4021+
"node_selectors",
4022+
"Kubernetes node selectors for scheduling, as a JSON object.",
4023+
),
4024+
]),
4025+
is_retained_metrics_object: false,
4026+
access: vec![PUBLIC_SELECT],
4027+
});
4028+
39604029
pub static MZ_AUDIT_EVENTS: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
39614030
name: "mz_audit_events",
39624031
schema: MZ_CATALOG_SCHEMA,
@@ -14333,6 +14402,7 @@ pub static BUILTINS_STATIC: LazyLock<Vec<Builtin<NameReference>>> = LazyLock::ne
1433314402
Builtin::Source(&MZ_CLUSTER_REPLICA_METRICS_HISTORY),
1433414403
Builtin::View(&MZ_CLUSTER_REPLICA_METRICS),
1433514404
Builtin::Table(&MZ_CLUSTER_REPLICA_SIZES),
14405+
Builtin::Table(&MZ_CLUSTER_REPLICA_SIZE_DETAILS),
1433614406
Builtin::Source(&MZ_CLUSTER_REPLICA_STATUS_HISTORY),
1433714407
Builtin::View(&MZ_CLUSTER_REPLICA_STATUSES),
1433814408
Builtin::MaterializedView(&MZ_INTERNAL_CLUSTER_REPLICAS),

src/pgrepr-consts/src/oid.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,3 +792,4 @@ pub const VIEW_MZ_MCP_DATA_PRODUCT_DETAILS_OID: u32 = 17071;
792792
pub const VIEW_MZ_BUILTIN_MATERIALIZED_VIEWS_OID: u32 = 17072;
793793
pub const FUNC_PARSE_CATALOG_CREATE_SQL_OID: u32 = 17073;
794794
pub const FUNC_REDACT_SQL_OID: u32 = 17074;
795+
pub const TABLE_MZ_CLUSTER_REPLICA_SIZE_DETAILS_OID: u32 = 17075;

test/sqllogictest/autogenerated/mz_internal.slt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,7 @@ mz_cluster_replica_history
747747
mz_cluster_replica_metrics
748748
mz_cluster_replica_metrics_history
749749
mz_cluster_replica_name_history
750+
mz_cluster_replica_size_details
750751
mz_cluster_replica_status_history
751752
mz_cluster_replica_statuses
752753
mz_cluster_replica_utilization
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
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

test/sqllogictest/information_schema_tables.slt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,10 @@ mz_cluster_replica_name_history
317317
VIEW
318318
materialize
319319
mz_internal
320+
mz_cluster_replica_size_details
321+
BASE TABLE
322+
materialize
323+
mz_internal
320324
mz_cluster_replica_status_history
321325
SOURCE
322326
materialize

0 commit comments

Comments
 (0)