pub struct StorageEngine { /* private fields */ }Expand description
Single-writer durable KV storage composed from the log and rebuildable redb index.
Implementations§
Source§impl StorageEngine
impl StorageEngine
Sourcepub fn open(path: impl AsRef<Path>) -> Result<OpenedStorage, StorageError>
pub fn open(path: impl AsRef<Path>) -> Result<OpenedStorage, StorageError>
Opens a data directory, verifies its log, and catches the index up before use.
§Errors
Returns an error for directory contention, log corruption, invalid committed mutations, a divergent index checkpoint, or filesystem failures.
Sourcepub fn backup(
&self,
destination: impl AsRef<Path>,
) -> Result<BackupInfo, BackupError>
pub fn backup( &self, destination: impl AsRef<Path>, ) -> Result<BackupInfo, BackupError>
Creates an atomic, independently verifiable backup at the current checkpoint.
§Errors
Returns an error when the snapshot cannot be created, the destination exists or is inside the live data directory, or synchronized promotion of the complete backup fails.
Sourcepub fn write(
&mut self,
transaction_id: Uuid,
mutations: &[Mutation],
) -> Result<AppendOutcome, StorageError>
pub fn write( &mut self, transaction_id: Uuid, mutations: &[Mutation], ) -> Result<AppendOutcome, StorageError>
Durably commits an atomic batch and then materializes it.
The log is synchronized before redb is updated. If redb fails, the error includes the durable commit receipt and this handle blocks reads and writes until reopen replays the log.
§Errors
Returns an error for invalid mutations, idempotency conflicts, log I/O, or materialized-index failures.
Sourcepub fn get(&self, key: &[u8]) -> Result<Option<Vec<u8>>, StorageError>
pub fn get(&self, key: &[u8]) -> Result<Option<Vec<u8>>, StorageError>
Reads a binary value from the caught-up materialized index.
§Errors
Returns an error for an empty or oversized key, an index read failure, or a handle made stale by a prior post-commit index failure.
Sourcepub fn scan_page(
&self,
after: Option<&[u8]>,
limit: usize,
) -> Result<KvPage, StorageError>
pub fn scan_page( &self, after: Option<&[u8]>, limit: usize, ) -> Result<KvPage, StorageError>
Scans one bounded page in strict binary-key order.
after is exclusive. A returned next_after is present only when at
least one additional entry exists.
§Errors
Returns an error for a stale handle, invalid cursor key, invalid page size, or materialized-index failure.
Sourcepub fn index_path(&self) -> PathBuf
pub fn index_path(&self) -> PathBuf
Returns the internal materialized-index path for diagnostics.
Sourcepub fn snapshot(&self) -> Result<SnapshotInfo, StorageError>
pub fn snapshot(&self) -> Result<SnapshotInfo, StorageError>
Creates or reuses a verified logical snapshot at the current index checkpoint.
§Errors
Returns an error when the live index is stale, cannot be streamed, or the snapshot cannot be synchronized, verified, and atomically promoted.
Sourcepub fn compact(&mut self) -> Result<CompactionOutcome, StorageError>
pub fn compact(&mut self) -> Result<CompactionOutcome, StorageError>
Retires the active log prefix behind a verified logical snapshot.
The new empty segment is synchronized before an immutable manifest generation selects it. Physical deletion of the retired segment happens only after that commit and is reported independently.
§Errors
Returns an error while preparing the snapshot, segment, or manifest. A poisoned or stale handle must be reopened before compaction.