pub struct PersistenceEngine { /* private fields */ }Expand description
Persistence engine that manages async WAL writing
Implementations§
Source§impl PersistenceEngine
impl PersistenceEngine
Sourcepub fn new<P: AsRef<Path>>(
path: P,
config: PersistenceConfig,
) -> Result<Self, StorageError>
pub fn new<P: AsRef<Path>>( path: P, config: PersistenceConfig, ) -> Result<Self, StorageError>
Create a new persistence engine writing to a file
Sourcepub fn with_writer<W: Write + Seek + Send + 'static>(
writer: W,
config: PersistenceConfig,
) -> Result<Self, StorageError>
pub fn with_writer<W: Write + Seek + Send + 'static>( writer: W, config: PersistenceConfig, ) -> Result<Self, StorageError>
Create a new persistence engine with a custom writer
Sourcepub fn send(&self, op: WalOp) -> Result<Lsn, StorageError>
pub fn send(&self, op: WalOp) -> Result<Lsn, StorageError>
Send a WAL operation to be persisted
This method is non-blocking unless the channel is full (backpressure). Returns the LSN assigned to the entry.
In volatile mode, entries are not sent to the WAL - just an LSN is returned.
Sourcepub fn send_entry(&self, entry: WalEntry) -> Result<Lsn, StorageError>
pub fn send_entry(&self, entry: WalEntry) -> Result<Lsn, StorageError>
Send a pre-built WAL entry to be persisted
In volatile mode, entries are not sent to the WAL.
Sourcepub fn flush(&self) -> Result<(), StorageError>
pub fn flush(&self) -> Result<(), StorageError>
Trigger an immediate flush of pending entries
This is non-blocking - it signals the writer thread to flush but doesn’t wait for completion.
Sourcepub fn sync(&self) -> Result<(), StorageError>
pub fn sync(&self) -> Result<(), StorageError>
Flush pending entries and wait for completion
This blocks until all pending entries have been written to disk.
Sourcepub fn sync_timeout(&self, timeout: Duration) -> Result<bool, StorageError>
pub fn sync_timeout(&self, timeout: Duration) -> Result<bool, StorageError>
Flush pending entries and wait for completion with timeout
Returns true if the flush completed within the timeout, false otherwise.
Sourcepub fn stats(&self) -> PersistenceStats
pub fn stats(&self) -> PersistenceStats
Get current statistics
Sourcepub fn durability_mode(&self) -> DurabilityMode
pub fn durability_mode(&self) -> DurabilityMode
Get the current durability mode
Sourcepub fn config(&self) -> &PersistenceConfig
pub fn config(&self) -> &PersistenceConfig
Get the current configuration
Sourcepub fn shutdown(&mut self) -> Result<(), StorageError>
pub fn shutdown(&mut self) -> Result<(), StorageError>
Shutdown the persistence engine gracefully
This flushes all pending entries and waits for the writer thread to terminate.
Sourcepub fn is_shutdown(&self) -> bool
pub fn is_shutdown(&self) -> bool
Check if the engine has been shut down