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
// SPDX-License-Identifier: BUSL-1.1
//! Canonical registry of `_system.*` redb tables created at bootstrap.
//!
//! `SystemCatalog::open` iterates [`BOOTSTRAP_TABLES`] and opens each
//! entry inside the init write transaction — opening a table in redb
//! creates it if absent. Holding the list here, instead of an inline
//! sequence of `open_table` calls in `open`, makes it structurally
//! impossible to declare a table and read it in production code without
//! also creating it at startup: a table that is consulted on a fresh
//! catalog but missing from this list would fail the first reader with
//! `Table '…' does not exist`. The `bootstrap_creates_every_registered_table`
//! unit test re-opens every entry read-only against a freshly-bootstrapped
//! catalog to keep the registry and the init path in lockstep.
//!
//! Migration-only tables (`_system.collections`, `_system.surrogate_pk`,
//! `_system.surrogate_pk_rev`, `_system.surrogate_pk_v2`,
//! `_system.surrogate_pk_rev_v2` — superseded key layouts) are intentionally
//! absent: they are read only by the idempotent migration path, which already
//! tolerates their absence, and materialising empty copies on every fresh
//! server would misrepresent the catalog state.
use redb::{ReadTransaction, TableError, WriteTransaction};
use super::tables::*;
/// One bootstrap table: a short label for diagnostics plus thunks that
/// open the table in a write transaction (creating it) or a read
/// transaction (probing its existence). The thunks erase the table's
/// concrete `TableDefinition<K, V>` key/value types so tables with
/// different shapes share one homogeneous slice.
pub(super) struct BootstrapTable {
/// Short, stable identifier used in error messages and test output.
pub(super) label: &'static str,
/// Open — and therefore create — the table in a write transaction.
pub(super) create: fn(&WriteTransaction) -> Result<(), TableError>,
/// Open the table read-only; fails with `TableDoesNotExist` if it was
/// never created. Used by `SystemCatalog::open` to decide whether the
/// catalog needs bootstrapping, and by the bootstrap-completeness test.
pub(super) probe: fn(&ReadTransaction) -> Result<(), TableError>,
}
macro_rules! bootstrap_tables {
($($label:literal => $def:expr),+ $(,)?) => {
&[$(
BootstrapTable {
label: $label,
create: |txn| txn.open_table($def).map(|_| ()),
probe: |txn| txn.open_table($def).map(|_| ()),
}
),+]
};
}
/// Every `_system.*` table created unconditionally on `SystemCatalog::open`.
pub(super) const BOOTSTRAP_TABLES: &[BootstrapTable] = bootstrap_tables![
// ── Auth / tenancy ──
"users" => USERS,
"api_keys" => API_KEYS,
"roles" => ROLES,
"permissions" => PERMISSIONS,
"owners" => OWNERS,
"tenants" => TENANTS,
"audit_log" => AUDIT_LOG,
"blacklist" => BLACKLIST,
"auth_users" => AUTH_USERS,
"lockout_state" => super::lockout::LOCKOUT_STATE_TABLE,
"orgs" => ORGS,
"org_members" => ORG_MEMBERS,
"scopes" => SCOPES,
"scope_grants" => SCOPE_GRANTS,
"oidc_providers" => OIDC_PROVIDERS,
// ── Collections + storage bookkeeping ──
"collections" => COLLECTIONS,
"metadata" => METADATA,
"wal_tombstones" => WAL_TOMBSTONES,
"l2_cleanup_queue" => L2_CLEANUP_QUEUE,
"pending_reclaim" => PENDING_RECLAIM,
"column_stats" => COLUMN_STATS,
"vector_model_metadata" => VECTOR_MODEL_METADATA,
"vector_index_params" => VECTOR_INDEX_PARAMS,
"checkpoints" => CHECKPOINTS,
// ── Surrogate identity map ──
"surrogate_pk_v3" => SURROGATE_PK_V3,
"surrogate_pk_rev_v3" => SURROGATE_PK_REV_V3,
"surrogate_hwm" => super::surrogate_hwm::SURROGATE_HWM,
"surrogate_reserve_index" => super::surrogate_hwm::SURROGATE_RESERVE_INDEX,
// ── Sync producer registry ──
"sync_producer_hwm" => super::sync_producer::SYNC_PRODUCER_HWM,
"sync_producers" => super::sync_producer::SYNC_PRODUCERS,
// ── DDL objects ──
"materialized_views" => MATERIALIZED_VIEWS,
"continuous_aggregates" => CONTINUOUS_AGGREGATES,
"functions" => FUNCTIONS,
"procedures" => PROCEDURES,
"triggers" => TRIGGERS,
"arrays" => ARRAYS,
"dependencies" => DEPENDENCIES,
"sequences" => SEQUENCES,
"sequence_state" => SEQUENCE_STATE,
"synonym_groups" => SYNONYM_GROUPS,
"custom_types" => CUSTOM_TYPES,
"wasm_modules" => WASM_MODULES,
"rls_policies" => super::rls::RLS_POLICIES,
// ── Event Plane ──
"change_streams" => CHANGE_STREAMS,
"consumer_groups" => CONSUMER_GROUPS,
"schedules" => SCHEDULES,
"retention_policies" => RETENTION_POLICIES,
"alert_rules" => ALERT_RULES,
"topics_ep" => TOPICS_EP,
"streaming_mvs" => STREAMING_MVS,
// ── Database catalog + quotas ──
"databases" => DATABASES,
"databases_by_name" => DATABASES_BY_NAME,
"database_hwm" => DATABASE_HWM,
"database_grants" => DATABASE_GRANTS,
"database_quotas" => DATABASE_QUOTAS,
"tenant_quotas" => TENANT_QUOTAS,
// ── Clone CoW + mirror ──
"clone_copyups" => CLONE_COPYUPS,
"clone_tombstones" => CLONE_TOMBSTONES,
"clone_kv_tombstones" => CLONE_KV_TOMBSTONES,
"clone_lineage" => CLONE_LINEAGE,
"mirror_collection_map" => MIRROR_COLLECTION_MAP,
"mirror_lag" => MIRROR_LAG,
// ── Tenant relocation ──
"move_tenant_journal" =>
crate::control::server::shared::ddl::neutral::tenant::move_tenant::journal::MOVE_TENANT_JOURNAL,
];