pub struct TableRegistry { /* private fields */ }Expand description
The table registry takes care of storing the records for each table,
using the [FreeSegmentsLedger] and [PageLedger] to derive exactly where to read/write.
A registry is generic over a record, which must implement Encode.
The CRUD operations provided by the table registry do NOT perform any logical checks, but just allow to read/write records from/to memory. So CRUD checks must be performed by a higher layer, prior to calling these methods.
Implementations§
Source§impl TableRegistry
impl TableRegistry
Sourcepub fn load(
table_pages: TableRegistryPage,
mm: &mut impl MemoryAccess,
) -> MemoryResult<Self>
pub fn load( table_pages: TableRegistryPage, mm: &mut impl MemoryAccess, ) -> MemoryResult<Self>
Loads the table registry from memory.
Sourcepub fn insert<E>(
&mut self,
record: E,
mm: &mut impl MemoryAccess,
) -> MemoryResult<RecordAddress>where
E: Encode,
pub fn insert<E>(
&mut self,
record: E,
mm: &mut impl MemoryAccess,
) -> MemoryResult<RecordAddress>where
E: Encode,
Inserts a new record into the table registry.
Returns the address where the record was inserted, which can be used to read it back or to update/delete it.
NOTE: this function does NOT make any logical checks on the record being inserted.
Sourcepub fn read<'a, E, MA>(&'a self, mm: &'a mut MA) -> TableReader<'a, E, MA>where
E: Encode,
MA: MemoryAccess,
pub fn read<'a, E, MA>(&'a self, mm: &'a mut MA) -> TableReader<'a, E, MA>where
E: Encode,
MA: MemoryAccess,
Creates a TableReader to read records from the table registry.
Use TableReader::try_next to read records one by one.
Sourcepub fn read_at<E, MA>(
&self,
address: RecordAddress,
mm: &mut MA,
) -> MemoryResult<E>where
E: Encode,
MA: MemoryAccess,
pub fn read_at<E, MA>(
&self,
address: RecordAddress,
mm: &mut MA,
) -> MemoryResult<E>where
E: Encode,
MA: MemoryAccess,
Reads a single record at the given address.
Sourcepub fn delete(
&mut self,
record: impl Encode,
address: RecordAddress,
mm: &mut impl MemoryAccess,
) -> MemoryResult<()>
pub fn delete( &mut self, record: impl Encode, address: RecordAddress, mm: &mut impl MemoryAccess, ) -> MemoryResult<()>
Deletes a record at the given page and offset.
The space occupied by the record is marked as free and zeroed.
Sourcepub fn update(
&mut self,
new_record: impl Encode,
old_record: impl Encode,
old_address: RecordAddress,
mm: &mut impl MemoryAccess,
) -> MemoryResult<RecordAddress>
pub fn update( &mut self, new_record: impl Encode, old_record: impl Encode, old_address: RecordAddress, mm: &mut impl MemoryAccess, ) -> MemoryResult<RecordAddress>
Updates a record at the given page and offset.
The RecordAddress of the new record is returned, which can be different from the old one if the record was reallocated.
The logic is the following:
- If the new record has exactly the same size of the old record, overwrite it in place.
- If the new record does not fit, delete the old record and insert the new record.
Sourcepub fn iter_raw<'a, MA>(
&'a self,
alignment: PageOffset,
mm: &'a mut MA,
) -> RawTableReader<'a, MA>where
MA: MemoryAccess,
pub fn iter_raw<'a, MA>(
&'a self,
alignment: PageOffset,
mm: &'a mut MA,
) -> RawTableReader<'a, MA>where
MA: MemoryAccess,
Iterate the table’s records as raw bytes under the given alignment.
Used by the migration apply pipeline to read records under the stored
snapshot. alignment must match the on-disk layout (i.e. the
TableSchemaSnapshot::alignment of the snapshot the records were
inserted under).
Sourcepub fn insert_raw(
&mut self,
bytes: &[u8],
alignment: PageOffset,
mm: &mut impl MemoryAccess,
) -> MemoryResult<RecordAddress>
pub fn insert_raw( &mut self, bytes: &[u8], alignment: PageOffset, mm: &mut impl MemoryAccess, ) -> MemoryResult<RecordAddress>
Insert pre-encoded record bytes under the given alignment.
Used by the migration apply pipeline. bytes is the body of the
record (without the 2-byte length header — the registry writes the
header). alignment comes from the target snapshot.
Sourcepub fn read_raw_at(
&self,
address: RecordAddress,
mm: &mut impl MemoryAccess,
) -> MemoryResult<Vec<u8>>
pub fn read_raw_at( &self, address: RecordAddress, mm: &mut impl MemoryAccess, ) -> MemoryResult<Vec<u8>>
Read raw record bytes at the given address (header stripped).
Sourcepub fn delete_raw(
&mut self,
address: RecordAddress,
body_len: MSize,
alignment: PageOffset,
mm: &mut impl MemoryAccess,
) -> MemoryResult<()>
pub fn delete_raw( &mut self, address: RecordAddress, body_len: MSize, alignment: PageOffset, mm: &mut impl MemoryAccess, ) -> MemoryResult<()>
Delete a raw record at the given address. Mirrors Self::delete
but parameterises size + alignment rather than reading them from a
compile-time Encode impl.
Sourcepub fn release_pages(
self,
table_pages: TableRegistryPage,
mm: &mut impl MemoryAccess,
) -> MemoryResult<()>
pub fn release_pages( self, table_pages: TableRegistryPage, mm: &mut impl MemoryAccess, ) -> MemoryResult<()>
Releases every page owned by this table back to the unclaimed-pages ledger.
Walks the page ledger, free-segments ledger, every B-tree in the
index ledger, plus the dedicated schema-snapshot and
autoincrement-registry pages, and hands each one to
MemoryAccess::unclaim_page. Used by MigrationOp::DropTable.
table_pages must be the TableRegistryPage this registry was
loaded from — the schema-snapshot and autoincrement pages are not
stored inside the registry itself.
After this call the table’s pages are reclaimable by future
MemoryAccess::claim_page calls. The caller is responsible for
removing the table’s entry from the schema registry.
§Errors
Propagates any wasm_dbms_api::prelude::MemoryError surfaced
while walking ledgers or releasing pages.
Sourcepub fn releasable_pages_count(
&self,
table_pages: TableRegistryPage,
mm: &mut impl MemoryAccess,
) -> MemoryResult<usize>
pub fn releasable_pages_count( &self, table_pages: TableRegistryPage, mm: &mut impl MemoryAccess, ) -> MemoryResult<usize>
Returns how many pages dropping this table would release.
Sourcepub fn index_ledger(&self) -> &IndexLedger
pub fn index_ledger(&self) -> &IndexLedger
Get a reference to the index ledger, allowing to read the indexes.
Sourcepub fn index_ledger_mut(&mut self) -> &mut IndexLedger
pub fn index_ledger_mut(&mut self) -> &mut IndexLedger
Get a mutable reference to the index ledger, allowing to modify the indexes.
Sourcepub fn schema_snapshot_ledger(&self) -> &SchemaSnapshotLedger
pub fn schema_snapshot_ledger(&self) -> &SchemaSnapshotLedger
Get a reference to the SchemaSnapshotLedger, allowing to read the schema snapshot.
Sourcepub fn schema_snapshot_ledger_mut(&mut self) -> &mut SchemaSnapshotLedger
pub fn schema_snapshot_ledger_mut(&mut self) -> &mut SchemaSnapshotLedger
Get a mutable reference to the SchemaSnapshotLedger, allowing to modify the schema snapshot.
Sourcepub fn next_autoincrement(
&mut self,
column_name: &str,
mm: &mut impl MemoryAccess,
) -> MemoryResult<Option<Value>>
pub fn next_autoincrement( &mut self, column_name: &str, mm: &mut impl MemoryAccess, ) -> MemoryResult<Option<Value>>
Get next value for an autoincrement column of the given type, and increment it in the ledger.