pub struct SchemaRegistry { /* private fields */ }Expand description
The schema registry takes care of storing and retrieving table schemas from memory.
Implementations§
Source§impl SchemaRegistry
impl SchemaRegistry
Sourcepub fn load(mm: &mut impl MemoryAccess) -> MemoryResult<Self>
pub fn load(mm: &mut impl MemoryAccess) -> MemoryResult<Self>
Load the schema registry from memory.
Sourcepub const fn schema_hash(&self) -> u64
pub const fn schema_hash(&self) -> u64
Returns the cached hash of every persisted schema snapshot.
Sourcepub fn register_table<TS>(
&mut self,
mm: &mut impl MemoryAccess,
) -> MemoryResult<TableRegistryPage>where
TS: TableSchema,
pub fn register_table<TS>(
&mut self,
mm: &mut impl MemoryAccess,
) -> MemoryResult<TableRegistryPage>where
TS: TableSchema,
Registers a table and allocates it registry page.
The TableSchema type parameter is used to get the TableSchema::fingerprint of the
table schema. The fingerprint is derived from the table name, so two distinct names that
hash to the same value are detected eagerly: when the slot is already occupied by a table
with a different name, MemoryError::NameCollision is returned and no allocation is
performed.
§Errors
MemoryError::NameCollisionwhen the fingerprint slot is occupied by a table whose persisted snapshot carries a different name.- Any
MemoryErrorpropagated from page allocation, snapshot init, or the registry write-back.
Sourcepub fn save(&self, mm: &mut impl MemoryAccess) -> MemoryResult<()>
pub fn save(&self, mm: &mut impl MemoryAccess) -> MemoryResult<()>
Save the schema registry to memory.
Sourcepub fn table_registry_page<TS>(&self) -> Option<TableRegistryPage>where
TS: TableSchema,
pub fn table_registry_page<TS>(&self) -> Option<TableRegistryPage>where
TS: TableSchema,
Returns the table registry page for a given table schema.
Sourcepub fn table_registry_page_by_name(
&self,
name: &str,
) -> Option<TableRegistryPage>
pub fn table_registry_page_by_name( &self, name: &str, ) -> Option<TableRegistryPage>
Returns the table registry page for the table with the given name.
Used by the migration engine, which knows tables only by name when applying ops decoded from snapshots.
Sourcepub fn register_table_from_snapshot(
&mut self,
snapshot: &TableSchemaSnapshot,
mm: &mut impl MemoryAccess,
) -> MemoryResult<TableRegistryPage>
pub fn register_table_from_snapshot( &mut self, snapshot: &TableSchemaSnapshot, mm: &mut impl MemoryAccess, ) -> MemoryResult<TableRegistryPage>
Registers a table from a snapshot, allocating its registry pages.
The migration engine uses this entry point when applying a
MigrationOp::CreateTable: the source of truth is a
TableSchemaSnapshot, not a TableSchema type.
§Errors
MemoryError::NameCollisionwhen the fingerprint slot is occupied by a table with a different name.- Any
MemoryErrorpropagated from page allocation, snapshot init, index init, or registry persistence.
Sourcepub fn unregister_table(
&mut self,
name: &str,
mm: &mut impl MemoryAccess,
) -> MemoryResult<Option<TableRegistryPage>>
pub fn unregister_table( &mut self, name: &str, mm: &mut impl MemoryAccess, ) -> MemoryResult<Option<TableRegistryPage>>
Removes the table identified by name from the registry, releases
every page it owned back to the unclaimed-pages ledger, and persists
the updated registry.
Used by the migration engine when applying a MigrationOp::DropTable.
Returns the TableRegistryPage previously associated with the table,
or None if no such table was registered.
§Errors
Returns a MemoryError if loading the table registry, releasing
its pages, or persisting the updated schema registry fails.
Sourcepub fn stored_snapshots(
&self,
mm: &mut impl MemoryAccess,
) -> MemoryResult<Vec<TableSchemaSnapshot>>
pub fn stored_snapshots( &self, mm: &mut impl MemoryAccess, ) -> MemoryResult<Vec<TableSchemaSnapshot>>
Returns the persisted TableSchemaSnapshot for every registered table.
The order is unspecified. Callers that need a stable order (e.g. for
drift hashing) must sort by TableSchemaSnapshot::name.
§Errors
Returns the first MemoryError encountered while loading any
snapshot page.
Sourcepub fn refresh_schema_hash(
&mut self,
mm: &mut impl MemoryAccess,
) -> MemoryResult<()>
pub fn refresh_schema_hash( &mut self, mm: &mut impl MemoryAccess, ) -> MemoryResult<()>
Recomputes the cached schema hash from the currently registered tables.
Trait Implementations§
Source§impl Clone for SchemaRegistry
impl Clone for SchemaRegistry
Source§fn clone(&self) -> SchemaRegistry
fn clone(&self) -> SchemaRegistry
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more