pub struct WriteAheadLog { /* private fields */ }Expand description
Write-Ahead Log implementation.
Implementations§
Source§impl WriteAheadLog
impl WriteAheadLog
Sourcepub fn set_sync_on_write(&mut self, enabled: bool)
pub fn set_sync_on_write(&mut self, enabled: bool)
Enable sync on every write for stronger durability.
When enabled, every append() call triggers an immediate sync(),
providing per-write durability at the cost of throughput (~10x lower).
Without this, up to sync_interval of data may be lost on crash.
Sourcepub fn sync(&mut self) -> Result<(), WalError>
pub fn sync(&mut self) -> Result<(), WalError>
Force sync to disk using fdatasync.
Uses sync_data() instead of sync_all() for better performance.
This syncs file data without updating metadata, saving 50-100μs per sync.
§Errors
Returns WalError::Io if the sync fails.
Sourcepub fn truncate(&mut self, position: u64) -> Result<(), WalError>
pub fn truncate(&mut self, position: u64) -> Result<(), WalError>
Truncate the log at the specified position.
Used after successful checkpointing to remove old entries.
§Errors
Returns WalError::Io if the truncation or file operations fail.
Sourcepub fn repair(&mut self) -> Result<u64, WalError>
pub fn repair(&mut self) -> Result<u64, WalError>
Repair the WAL by truncating to the last valid record.
This should be called during recovery to handle torn writes from crashes. It reads through the WAL, validates each record, and truncates at the first invalid record (torn write or corruption).
§Returns
Returns Ok(valid_position) where valid_position is the end of the
last valid record (and the new WAL length).
§Errors
Returns WalError::Io if file operations fail.
Auto Trait Implementations§
impl Freeze for WriteAheadLog
impl RefUnwindSafe for WriteAheadLog
impl Send for WriteAheadLog
impl Sync for WriteAheadLog
impl Unpin for WriteAheadLog
impl UnsafeUnpin for WriteAheadLog
impl UnwindSafe for WriteAheadLog
Blanket Implementations§
§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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>
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>
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