pub struct Wal { /* private fields */ }Expand description
Write-Ahead Log with per-key segment sets.
The Wal struct provides the main interface for WAL operations,
managing segment files and ensuring durability guarantees.
Implementations§
Source§impl Wal
impl Wal
Sourcepub fn new(filepath: &str, options: WalOptions) -> Result<Self>
pub fn new(filepath: &str, options: WalOptions) -> Result<Self>
Creates a new WAL instance.
§Arguments
filepath- Directory path for WAL filesoptions- Configuration options
§Errors
Returns WalError::InvalidConfig if options are invalid.
Returns WalError::Io if directory creation fails.
§Examples
use nano_wal::{Wal, WalOptions};
let wal = Wal::new("./my_wal", WalOptions::default())?;Sourcepub fn append_entry<K: Hash + AsRef<[u8]> + Display>(
&mut self,
key: K,
header: Option<Bytes>,
content: Bytes,
durable: bool,
) -> Result<EntryRef>
pub fn append_entry<K: Hash + AsRef<[u8]> + Display>( &mut self, key: K, header: Option<Bytes>, content: Bytes, durable: bool, ) -> Result<EntryRef>
Appends an entry to the WAL.
§Arguments
key- Entry key for segment selectionheader- Optional metadata header (max 64KB)content- Entry contentdurable- If true, syncs to disk before returning
§Errors
Returns WalError::HeaderTooLarge if header exceeds 64KB.
Returns WalError::Io for I/O failures.
§Examples
let entry_ref = wal.append_entry(
"user_123",
Some(Bytes::from("metadata")),
Bytes::from("data"),
true
)?;Sourcepub fn append_batch<K, I>(
&mut self,
entries: I,
durable: bool,
) -> Result<Vec<EntryRef>>
pub fn append_batch<K, I>( &mut self, entries: I, durable: bool, ) -> Result<Vec<EntryRef>>
Appends multiple entries in a batch.
Batch operations provide better throughput by reducing I/O overhead.
§Arguments
entries- Iterator of (key, header, content) tuplesdurable- If true, syncs after all entries are written
§Errors
Returns first error encountered; partial writes may occur.
§Examples
let entries = vec![
("key1", None, Bytes::from("data1")),
("key2", Some(Bytes::from("meta")), Bytes::from("data2")),
];
let refs = wal.append_batch(entries, true)?;Sourcepub fn log_entry<K: Hash + AsRef<[u8]> + Display>(
&mut self,
key: K,
header: Option<Bytes>,
content: Bytes,
) -> Result<EntryRef>
pub fn log_entry<K: Hash + AsRef<[u8]> + Display>( &mut self, key: K, header: Option<Bytes>, content: Bytes, ) -> Result<EntryRef>
Logs an entry with durability guarantee.
Convenience method equivalent to append_entry(key, header, content, true).
§Examples
wal.log_entry("key", None, Bytes::from("data"))?;Sourcepub fn enumerate_keys(&self) -> Result<impl Iterator<Item = String>>
pub fn enumerate_keys(&self) -> Result<impl Iterator<Item = String>>
Sourcepub fn enumerate_records<K: Hash + AsRef<[u8]> + Display>(
&self,
key: K,
) -> Result<impl Iterator<Item = Bytes>>
pub fn enumerate_records<K: Hash + AsRef<[u8]> + Display>( &self, key: K, ) -> Result<impl Iterator<Item = Bytes>>
Sourcepub fn read_entry_at(&self, entry_ref: EntryRef) -> Result<Bytes>
pub fn read_entry_at(&self, entry_ref: EntryRef) -> Result<Bytes>
Sourcepub fn active_segment_count(&self) -> usize
pub fn active_segment_count(&self) -> usize
Returns count of active segments.
§Examples
println!("Active segments: {}", wal.active_segment_count());Trait Implementations§
Auto Trait Implementations§
impl Freeze for Wal
impl RefUnwindSafe for Wal
impl Send for Wal
impl Sync for Wal
impl Unpin for Wal
impl UnwindSafe for Wal
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more