pub struct CoreWalWriter { /* private fields */ }Expand description
Per-core WAL writer.
Each core owns its own writer, eliminating cross-core synchronization on the write path.
Record format is compatible with [length: 4][crc32: 4][data: length]
Implementations§
Source§impl CoreWalWriter
impl CoreWalWriter
Sourcepub fn open_at(
core_id: usize,
path: &Path,
position: u64,
) -> Result<Self, PerCoreWalError>
pub fn open_at( core_id: usize, path: &Path, position: u64, ) -> Result<Self, PerCoreWalError>
Opens an existing segment file at a specific position.
Used during recovery to resume writing.
§Errors
Returns an error if the file cannot be opened or truncated.
Sourcepub fn position(&self) -> u64
pub fn position(&self) -> u64
Returns the current write position in bytes (includes un-synced data).
Sourcepub fn synced_position(&self) -> u64
pub fn synced_position(&self) -> u64
Returns the last synced position (durable after fdatasync).
Only data up to this position is guaranteed to survive a crash.
Use this for checkpoint manifests instead of position().
Sourcepub fn entries_since_sync(&self) -> u64
pub fn entries_since_sync(&self) -> u64
Returns the number of entries since last sync.
Sourcepub fn set_epoch(&mut self, epoch: u64)
pub fn set_epoch(&mut self, epoch: u64)
Sets the current epoch (called by manager during checkpoint).
Sourcepub fn append_put(
&mut self,
key: &[u8],
value: &[u8],
) -> Result<u64, PerCoreWalError>
pub fn append_put( &mut self, key: &[u8], value: &[u8], ) -> Result<u64, PerCoreWalError>
Sourcepub fn append_delete(&mut self, key: &[u8]) -> Result<u64, PerCoreWalError>
pub fn append_delete(&mut self, key: &[u8]) -> Result<u64, PerCoreWalError>
Sourcepub fn append_put_via_storage_io(
&mut self,
key: &[u8],
value: &[u8],
sio: &mut dyn StorageIo,
fd: IoFd,
) -> Result<u64, PerCoreWalError>
pub fn append_put_via_storage_io( &mut self, key: &[u8], value: &[u8], sio: &mut dyn StorageIo, fd: IoFd, ) -> Result<u64, PerCoreWalError>
Appends a Put operation via [StorageIo].
§Errors
Returns an error if serialization or I/O submission fails.
Sourcepub fn append_delete_via_storage_io(
&mut self,
key: &[u8],
sio: &mut dyn StorageIo,
fd: IoFd,
) -> Result<u64, PerCoreWalError>
pub fn append_delete_via_storage_io( &mut self, key: &[u8], sio: &mut dyn StorageIo, fd: IoFd, ) -> Result<u64, PerCoreWalError>
Appends a Delete operation via [StorageIo].
§Errors
Returns an error if serialization or I/O submission fails.
Sourcepub fn append(
&mut self,
entry: &PerCoreWalEntry,
) -> Result<u64, PerCoreWalError>
pub fn append( &mut self, entry: &PerCoreWalEntry, ) -> Result<u64, PerCoreWalError>
Appends a raw entry to the WAL.
Record format: [length: 4 bytes][crc32: 4 bytes][data: length bytes]
§Errors
Returns an error if serialization or I/O fails.
Sourcepub fn append_via_storage_io(
&mut self,
entry: &PerCoreWalEntry,
sio: &mut dyn StorageIo,
fd: IoFd,
) -> Result<u64, PerCoreWalError>
pub fn append_via_storage_io( &mut self, entry: &PerCoreWalEntry, sio: &mut dyn StorageIo, fd: IoFd, ) -> Result<u64, PerCoreWalError>
Sourcepub fn sync_via_storage_io(
&mut self,
sio: &mut dyn StorageIo,
fd: IoFd,
) -> Result<u64, PerCoreWalError>
pub fn sync_via_storage_io( &mut self, sio: &mut dyn StorageIo, fd: IoFd, ) -> Result<u64, PerCoreWalError>
Syncs the WAL segment via a [StorageIo] backend.
Submits an fdatasync through the I/O backend. Non-blocking — the
caller must poll for the completion token.
§Errors
Returns an error if the submission fails.
Sourcepub fn check_completions(
&mut self,
completions: &[IoCompletion],
) -> Result<bool, PerCoreWalError>
pub fn check_completions( &mut self, completions: &[IoCompletion], ) -> Result<bool, PerCoreWalError>
Check I/O completions and update sync state.
Scans completions for the pending sync token. If found and
successful, calls mark_synced. If found
and failed (negative result = errno), returns an error.
Returns Ok(true) if the sync completed successfully,
Ok(false) if no matching completion was found,
or Err if the sync failed.
Call this after every StorageIo::poll_completions round.
§Errors
Returns PerCoreWalError::Io if the kernel reported a sync failure.
Sourcepub fn is_sync_pending(&self) -> bool
pub fn is_sync_pending(&self) -> bool
Returns true if a sync is pending (submitted but not yet completed).
Sourcepub fn mark_synced(&mut self)
pub fn mark_synced(&mut self)
Mark the current write position as synced (durable).
Used by the direct (non-StorageIo) sync path after a blocking
fdatasync where all data up to position is guaranteed durable.
The StorageIo path uses Self::check_completions instead, which
advances only to the boundary recorded at submission time.
Sourcepub fn append_checkpoint(
&mut self,
checkpoint_id: u64,
) -> Result<u64, PerCoreWalError>
pub fn append_checkpoint( &mut self, checkpoint_id: u64, ) -> Result<u64, PerCoreWalError>
Sourcepub fn append_epoch_barrier(&mut self) -> Result<u64, PerCoreWalError>
pub fn append_epoch_barrier(&mut self) -> Result<u64, PerCoreWalError>
Sourcepub fn append_commit(
&mut self,
offsets: HashMap<String, u64>,
watermark: Option<i64>,
) -> Result<u64, PerCoreWalError>
pub fn append_commit( &mut self, offsets: HashMap<String, u64>, watermark: Option<i64>, ) -> Result<u64, PerCoreWalError>
Sourcepub fn sync(&mut self) -> Result<(), PerCoreWalError>
pub fn sync(&mut self) -> Result<(), PerCoreWalError>
Syncs the WAL segment to disk using fdatasync.
Uses sync_data() instead of sync_all() for better performance.
§Errors
Returns an error if the sync fails.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for CoreWalWriter
impl RefUnwindSafe for CoreWalWriter
impl Send for CoreWalWriter
impl Sync for CoreWalWriter
impl Unpin for CoreWalWriter
impl UnsafeUnpin for CoreWalWriter
impl UnwindSafe for CoreWalWriter
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