Skip to content

Commit b15df99

Browse files
committed
Shift user item id allocation
1 parent 9836575 commit b15df99

File tree

25 files changed

+304
-287
lines changed

25 files changed

+304
-287
lines changed

src/adapter/tests/testdata/sql

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
add-table
1111
foo
1212
----
13-
u1
13+
u2
1414

1515
resolve
1616
SELECT 1 FROM foo
1717
----
18-
SELECT 1 FROM [u1 AS materialize.public.foo]
18+
SELECT 1 FROM [u2 AS materialize.public.foo]
1919

2020
resolve
2121
SELECT 1 FROM bar
@@ -25,7 +25,7 @@ error: unknown catalog item 'bar'
2525
resolve
2626
SELECT 1 FROM materialize.public.foo
2727
----
28-
SELECT 1 FROM [u1 AS materialize.public.foo]
28+
SELECT 1 FROM [u2 AS materialize.public.foo]
2929

3030
resolve
3131
WITH foo AS (SELECT 1)
@@ -43,13 +43,13 @@ resolve
4343
WITH bar AS (SELECT 1)
4444
SELECT 1 FROM foo CROSS JOIN bar
4545
----
46-
WITH bar AS (SELECT 1) SELECT 1 FROM [u1 AS materialize.public.foo] CROSS JOIN bar
46+
WITH bar AS (SELECT 1) SELECT 1 FROM [u2 AS materialize.public.foo] CROSS JOIN bar
4747

4848
resolve
4949
WITH bar AS (SELECT 1), baz AS (SELECT 2)
5050
SELECT 1 FROM foo CROSS JOIN bar CROSS JOIN baz
5151
----
52-
WITH bar AS (SELECT 1), baz AS (SELECT 2) SELECT 1 FROM [u1 AS materialize.public.foo] CROSS JOIN bar CROSS JOIN baz
52+
WITH bar AS (SELECT 1), baz AS (SELECT 2) SELECT 1 FROM [u2 AS materialize.public.foo] CROSS JOIN bar CROSS JOIN baz
5353

5454
resolve
5555
WITH outermost(x) AS (

src/catalog/src/durable.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -355,9 +355,7 @@ pub trait DurableCatalogState: ReadOnlyDurableCatalogState {
355355
amount: u64,
356356
commit_ts: Timestamp,
357357
) -> Result<Vec<(CatalogItemId, GlobalId)>, CatalogError> {
358-
let ids = self
359-
.allocate_id(&[USER_ITEM_ALLOC_KEY], amount, commit_ts)
360-
.await?;
358+
let ids = self.allocate_id(USER_ALLOC_KEYS, amount, commit_ts).await?;
361359
let ids = ids
362360
.iter()
363361
.map(|id| (CatalogItemId::User(*id), GlobalId::User(*id)))
@@ -372,9 +370,7 @@ pub trait DurableCatalogState: ReadOnlyDurableCatalogState {
372370
&mut self,
373371
commit_ts: Timestamp,
374372
) -> Result<(CatalogItemId, GlobalId), CatalogError> {
375-
let id = self
376-
.allocate_id(&[USER_ITEM_ALLOC_KEY], 1, commit_ts)
377-
.await?;
373+
let id = self.allocate_id(USER_ALLOC_KEYS, 1, commit_ts).await?;
378374
let id = id.into_element();
379375
Ok((CatalogItemId::User(id), GlobalId::User(id)))
380376
}

src/catalog/src/durable/transaction.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ use crate::durable::{
6565
DATABASE_ID_ALLOC_KEY, DefaultPrivilege, DurableCatalogError, DurableCatalogState,
6666
EXPRESSION_CACHE_SHARD_KEY, MOCK_AUTHENTICATION_NONCE_KEY, NetworkPolicy, OID_ALLOC_KEY,
6767
SCHEMA_ID_ALLOC_KEY, STORAGE_USAGE_ID_ALLOC_KEY, SYSTEM_ALLOC_KEYS, SYSTEM_ITEM_ALLOC_KEY,
68-
Snapshot, SystemConfiguration, USER_ALLOC_KEYS, USER_ITEM_ALLOC_KEY,
69-
USER_NETWORK_POLICY_ID_ALLOC_KEY, USER_ROLE_ID_ALLOC_KEY,
68+
Snapshot, SystemConfiguration, USER_ALLOC_KEYS, USER_NETWORK_POLICY_ID_ALLOC_KEY,
69+
USER_ROLE_ID_ALLOC_KEY,
7070
};
7171
use crate::memory::objects::{StateDiff, StateUpdate, StateUpdateKind};
7272

@@ -889,7 +889,7 @@ impl<'a> Transaction<'a> {
889889
amount: u64,
890890
) -> Result<Vec<(CatalogItemId, GlobalId)>, CatalogError> {
891891
Ok(self
892-
.get_and_increment_id_by(&[USER_ITEM_ALLOC_KEY], amount)?
892+
.get_and_increment_id_by(USER_ALLOC_KEYS, amount)?
893893
.into_iter()
894894
// TODO(alter_table): Use separate ID allocators.
895895
.map(|x| (CatalogItemId::User(x), GlobalId::User(x)))

src/environmentd/tests/server.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ fn test_persistence() {
161161
.into_iter()
162162
.map(|row| row.get(0))
163163
.collect::<Vec<String>>(),
164-
vec!["u1", "u2", "u3", "u4", "u5", "u6", "u7"]
164+
vec!["u2", "u3", "u4", "u5", "u6", "u7", "u8"]
165165
);
166166
}
167167

src/environmentd/tests/sql.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,13 +1244,13 @@ largest not in advance of upper:<TIMESTAMP>
12441244
timeline: Some(EpochMilliseconds)
12451245
session wall time:<TIMESTAMP>
12461246
1247-
source materialize.public.t1 (u1, storage):
1247+
source materialize.public.t1 (u2, storage):
12481248
read frontier:[<TIMESTAMP>]
12491249
write frontier:[<TIMESTAMP>]
12501250
12511251
binding constraints:
12521252
lower:
1253-
(StorageInput([User(1)])): [<TIMESTAMP>]
1253+
(StorageInput([User(2)])): [<TIMESTAMP>]
12541254
(IsolationLevel(StrictSerializable)): [<TIMESTAMP>]\n";
12551255

12561256
let row = client

test/cluster/mzcompose.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,8 +1461,8 @@ def workflow_test_system_table_indexes(c: Composition) -> None:
14611461
FROM mz_views;
14621462
CREATE DEFAULT INDEX ON v_mz_views;
14631463
1464-
> SELECT id FROM mz_indexes WHERE id like 'u%';
1465-
u2
1464+
> SELECT name FROM mz_indexes WHERE id like 'u%';
1465+
v_mz_views_primary_idx
14661466
"""
14671467
)
14681468
)
@@ -1476,8 +1476,8 @@ def workflow_test_system_table_indexes(c: Composition) -> None:
14761476
c.testdrive(
14771477
input=dedent(
14781478
"""
1479-
> SELECT id FROM mz_indexes WHERE id like 'u%';
1480-
u2
1479+
> SELECT name FROM mz_indexes WHERE id like 'u%';
1480+
v_mz_views_primary_idx
14811481
"""
14821482
)
14831483
)
@@ -4794,7 +4794,7 @@ def workflow_test_adhoc_system_indexes(
47944794
WHERE i.name = 'mz_test_idx1'
47954795
"""
47964796
)
4797-
assert output[0] == ("u1", "mz_tables", "mz_catalog_server"), output
4797+
assert output[0][1:] == ("mz_tables", "mz_catalog_server"), output
47984798
output = c.sql_query("EXPLAIN SELECT * FROM mz_tables WHERE char_length(name) = 9")
47994799
assert "mz_test_idx1" in output[0][0], output
48004800
output = c.sql_query("SELECT * FROM mz_tables WHERE char_length(name) = 9")
@@ -4823,7 +4823,7 @@ def workflow_test_adhoc_system_indexes(
48234823
WHERE i.name = 'mz_test_idx2'
48244824
"""
48254825
)
4826-
assert output[0] == ("u2", "mz_hydration_statuses", "mz_catalog_server"), output
4826+
assert output[0][1:] == ("mz_hydration_statuses", "mz_catalog_server"), output
48274827
output = c.sql_query(
48284828
"EXPLAIN SELECT * FROM mz_internal.mz_hydration_statuses WHERE hydrated"
48294829
)
@@ -4848,8 +4848,8 @@ def workflow_test_adhoc_system_indexes(
48484848
ORDER BY id
48494849
"""
48504850
)
4851-
assert output[0] == ("u1", "mz_tables", "mz_catalog_server"), output
4852-
assert output[1] == ("u2", "mz_hydration_statuses", "mz_catalog_server"), output
4851+
assert output[0][1:] == ("mz_tables", "mz_catalog_server"), output
4852+
assert output[1][1:] == ("mz_hydration_statuses", "mz_catalog_server"), output
48534853

48544854
# Make sure the new indexes can be dropped again.
48554855
c.sql(

test/kafka-auth/mzcompose.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,15 @@ def workflow_default(c: Composition, parser: WorkflowArgumentParser) -> None:
240240
"""
241241
)
242242
public_key = c.sql_query(
243-
"select public_key_1 from mz_ssh_tunnel_connections where id = 'u1';"
243+
"""
244+
SELECT
245+
public_key_1
246+
FROM
247+
mz_connections JOIN
248+
mz_ssh_tunnel_connections USING(id)
249+
WHERE
250+
mz_connections.name = 'ssh';
251+
"""
244252
)[0][0]
245253
c.exec(
246254
"ssh-bastion-host",
@@ -261,7 +269,15 @@ def workflow_default(c: Composition, parser: WorkflowArgumentParser) -> None:
261269
"""
262270
)
263271
public_key = c.sql_query(
264-
"select public_key_1 from mz_ssh_tunnel_connections where id = 'u2';"
272+
"""
273+
SELECT
274+
public_key_1
275+
FROM
276+
mz_connections JOIN
277+
mz_ssh_tunnel_connections USING(id)
278+
WHERE
279+
mz_connections.name = 'ssh_backup';
280+
"""
265281
)[0][0]
266282
c.exec(
267283
"ssh-bastion-host",

test/kafka-auth/test-kafka-ssl.td

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,19 +172,19 @@ running
172172
> SELECT COUNT(*) FROM mz_ssh_tunnel_connections
173173
2
174174

175-
> SELECT COUNT(*) FROM mz_internal.mz_object_dependencies WHERE referenced_object_id = 'u1';
175+
> SELECT COUNT(*) FROM mz_internal.mz_object_dependencies as mzo, mz_objects as mo WHERE mzo.referenced_object_id = mo.id and mo.name = 'ssh';
176176
1
177177

178178
! DROP CONNECTION testdrive_no_reset_connections.public.ssh;
179179
contains:still depended upon by connection "kafka_ssh"
180180

181-
> SELECT COUNT(*) FROM mz_internal.mz_object_dependencies WHERE referenced_object_id = 'u1';
181+
> SELECT COUNT(*) FROM mz_internal.mz_object_dependencies as mzo, mz_objects as mo WHERE mzo.referenced_object_id = mo.id and mo.name = 'ssh';
182182
1
183183

184184
> ALTER CONNECTION kafka_ssh SET (BROKER 'kafka:9093' USING SSH TUNNEL testdrive_no_reset_connections.public.ssh_backup);
185185

186186
# We've removed all dependencies on testdrive_no_reset_connections.public.ssh, so it could be dropped
187-
> SELECT COUNT(*) FROM mz_internal.mz_object_dependencies WHERE referenced_object_id = 'u1';
187+
> SELECT COUNT(*) FROM mz_internal.mz_object_dependencies as mzo, mz_objects as mo WHERE mzo.referenced_object_id = mo.id and mo.name = 'ssh';
188188
0
189189

190190
# Break new SSH tunnel to show that we can fix it

test/persistence/mzcompose.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,12 @@ def workflow_inspect_shard(c: Composition) -> None:
194194
"""
195195
)
196196
)
197-
json_dict = c.sql_query("INSPECT SHARD 'u1'", port=6877, user="mz_system")[0][0]
197+
object_id = c.sql_query(
198+
"SELECT id from mz_objects where name = 'foo'", port=6877, user="mz_system"
199+
)[0][0]
200+
json_dict = c.sql_query(
201+
f"INSPECT SHARD '{object_id}'", port=6877, user="mz_system"
202+
)[0][0]
198203
parts = [
199204
part
200205
for batch in json_dict["batches"]

test/sqllogictest/alter-table.slt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ CREATE TABLE t2 (a int);
1919

2020
# TODO(alter_table): Manually specifying a VERSION when referencing an item (maybe?) shouldn't be allowed.
2121
statement ok
22-
CREATE VIEW v1 AS SELECT * FROM [u1 AS "materialize"."public"."t2" VERSION 0];
22+
CREATE VIEW v1 AS SELECT * FROM [u2 AS "materialize"."public"."t2" VERSION 0];
2323

2424
statement ok
2525
CREATE VIEW v2 AS SELECT * FROM t2;
@@ -57,7 +57,7 @@ statement ok
5757
ALTER TABLE t1 ADD COLUMN IF NOT EXISTS a int;
5858

5959
query error db error: ERROR: invalid version "1000" for "t2"
60-
CREATE VIEW v1 AS SELECT * FROM [u1 AS "materialize"."public"."t2" VERSION 1000];
60+
CREATE VIEW v1 AS SELECT * FROM [u2 AS "materialize"."public"."t2" VERSION 1000];
6161

6262
query TTTT
6363
SHOW COLUMNS FROM t1;
@@ -413,15 +413,15 @@ DROP TABLE t1 CASCADE;
413413
query TT
414414
SELECT id, name FROM mz_tables WHERE id LIKE 'u%';
415415
----
416-
u1 t2
416+
u2 t2
417417

418418
statement ok
419419
COMMENT ON COLUMN t2.a IS 'this column existed originally';
420420

421421
query TTIT
422-
SELECT * FROM mz_internal.mz_comments WHERE id = 'u1';
422+
SELECT * FROM mz_internal.mz_comments WHERE id = 'u2';
423423
----
424-
u1 table 1 this␠column␠existed␠originally
424+
u2 table 1 this␠column␠existed␠originally
425425

426426
statement ok
427427
ALTER TABLE t2 ADD COLUMN c timestamp;
@@ -430,14 +430,14 @@ statement ok
430430
COMMENT ON COLUMN t2.c IS 'added later';
431431

432432
query TTIT rowsort
433-
SELECT * FROM mz_internal.mz_comments WHERE id = 'u1';
433+
SELECT * FROM mz_internal.mz_comments WHERE id = 'u2';
434434
----
435-
u1 table 3 added␠later
436-
u1 table 1 this␠column␠existed␠originally
435+
u2 table 3 added␠later
436+
u2 table 1 this␠column␠existed␠originally
437437

438438
statement ok
439439
DROP TABLE t2 CASCADE;
440440

441441
query TTIT
442-
SELECT * FROM mz_internal.mz_comments WHERE id = 'u1';
442+
SELECT * FROM mz_internal.mz_comments WHERE id = 'u2';
443443
----

0 commit comments

Comments
 (0)