pub struct PortableWalWriter { /* private fields */ }Expand description
Optimized WAL writer using io_uring or fallback
This writer supports both direct writes and batched operations. Batched writes can improve throughput by reducing syscall overhead.
§Batching Mode
When using batched mode:
- Writes are queued in a batch
- When batch reaches max_batch_bytes or flush_batch() is called, all writes execute
- Sync is deferred until batch execution
§Example
ⓘ
let wal = PortableWalWriter::new("wal.log", IoUringConfig::default())?;
// Direct write (immediate)
wal.append(b"entry1")?;
// Batched write (queued)
wal.append_batched(b"entry2")?;
wal.append_batched(b"entry3")?;
wal.flush_batch()?; // Execute all batched writesImplementations§
Source§impl PortableWalWriter
impl PortableWalWriter
Sourcepub fn new(path: impl AsRef<Path>, config: IoUringConfig) -> Result<Self>
pub fn new(path: impl AsRef<Path>, config: IoUringConfig) -> Result<Self>
Create a new WAL writer
Sourcepub fn append(&self, data: &[u8]) -> Result<u64>
pub fn append(&self, data: &[u8]) -> Result<u64>
Append data to the WAL (direct write, immediate)
Sourcepub fn append_batched(&self, data: &[u8]) -> Result<u64>
pub fn append_batched(&self, data: &[u8]) -> Result<u64>
Append data to the WAL in batched mode
The write is queued and executed when:
flush_batch()is called- The batch exceeds
max_batch_bytes
Returns the number of pending bytes in the batch
Sourcepub fn flush_batch(&self) -> Result<()>
pub fn flush_batch(&self) -> Result<()>
Flush all batched writes to disk
Executes all pending write operations in the batch and syncs to disk.
Sourcepub fn pending_batch_bytes(&self) -> u64
pub fn pending_batch_bytes(&self) -> u64
Get the number of pending bytes in the batch
Sourcepub fn pending_batch_ops(&self) -> usize
pub fn pending_batch_ops(&self) -> usize
Get the number of pending operations in the batch
Sourcepub fn has_pending_batch(&self) -> bool
pub fn has_pending_batch(&self) -> bool
Check if there are pending batched writes
Sourcepub fn append_with_checksum(&self, data: &[u8]) -> Result<u64>
pub fn append_with_checksum(&self, data: &[u8]) -> Result<u64>
Append with CRC32 checksum
Sourcepub fn append_with_checksum_batched(&self, data: &[u8]) -> Result<u64>
pub fn append_with_checksum_batched(&self, data: &[u8]) -> Result<u64>
Append with CRC32 checksum in batched mode
Sourcepub fn max_batch_bytes(&self) -> u64
pub fn max_batch_bytes(&self) -> u64
Get max batch bytes threshold
Sourcepub fn stats(&self) -> IoUringStatsSnapshot
pub fn stats(&self) -> IoUringStatsSnapshot
Get statistics
Auto Trait Implementations§
impl !Freeze for PortableWalWriter
impl !RefUnwindSafe for PortableWalWriter
impl Send for PortableWalWriter
impl Sync for PortableWalWriter
impl Unpin for PortableWalWriter
impl UnsafeUnpin for PortableWalWriter
impl UnwindSafe for PortableWalWriter
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more