pub struct AsyncDiskStorage { /* private fields */ }Expand description
High-performance async disk writer.
Writes are sent over an MPSC channel and flushed to disk every 50 ms by a background Tokio task. The write path never blocks the caller.
Implementations§
Trait Implementations§
Source§impl Drop for AsyncDiskStorage
impl Drop for AsyncDiskStorage
Source§impl StorageBackend for AsyncDiskStorage
impl StorageBackend for AsyncDiskStorage
Source§fn write_entry(&self, entry: &LogEntry) -> Result<(), DbError>
fn write_entry(&self, entry: &LogEntry) -> Result<(), DbError>
Serialize entry to a JSON string and send it to the background writer.
This call returns immediately — it never blocks waiting for disk I/O.
Source§fn read_log(&self) -> Result<Vec<LogEntry>, DbError>
fn read_log(&self) -> Result<Vec<LogEntry>, DbError>
Read all entries from the log file into a Vec. Used by EncryptedStorage which needs the full list to decrypt.
Source§fn compact(&self, entries: Vec<LogEntry>) -> Result<(), DbError>
fn compact(&self, entries: Vec<LogEntry>) -> Result<(), DbError>
Compact the log: write a binary snapshot, rewrite the log to be empty, then signal the background task to swap the file.
Source§fn read_at(&self, offset: u64, length: u32) -> Result<Vec<u8>, DbError>
fn read_at(&self, offset: u64, length: u32) -> Result<Vec<u8>, DbError>
Read exactly length bytes from the log at offset.
Source§fn stream_log_into(
&self,
f: &mut dyn FnMut(LogEntry, u32) -> ControlFlow<(), ()>,
) -> Result<u64, DbError>
fn stream_log_into( &self, f: &mut dyn FnMut(LogEntry, u32) -> ControlFlow<(), ()>, ) -> Result<u64, DbError>
Stream log entries into state using snapshot + delta replay.
Fast path (after first compaction):
- Load binary snapshot → apply all entries in it.
- Stream only the log lines written AFTER the snapshot (the “delta”).
Slow path (first run, no snapshot): Stream the entire log file line-by-line. No full Vec in RAM.