pub struct WalSegment { /* private fields */ }Expand description
Fixed-size memory-mapped WAL segment
WalSegment provides atomic write operations with thread-safe write pointer management and integrity validation through checksums.
Implementations§
Source§impl WalSegment
impl WalSegment
Sourcepub fn create(
segment_id: u64,
file_path: PathBuf,
capacity: usize,
) -> Result<Self, ShardexError>
pub fn create( segment_id: u64, file_path: PathBuf, capacity: usize, ) -> Result<Self, ShardexError>
Create a new WAL segment with the specified ID and capacity
Sourcepub fn open(file_path: PathBuf) -> Result<Self, ShardexError>
pub fn open(file_path: PathBuf) -> Result<Self, ShardexError>
Open an existing WAL segment
Sourcepub fn write_pointer(&self) -> usize
pub fn write_pointer(&self) -> usize
Get current write pointer position
Sourcepub fn remaining_space(&self) -> usize
pub fn remaining_space(&self) -> usize
Get remaining space in bytes
Sourcepub fn append(&self, data: &[u8]) -> Result<usize, ShardexError>
pub fn append(&self, data: &[u8]) -> Result<usize, ShardexError>
Append data to the segment atomically with record header
Sourcepub fn append_transaction(
&self,
transaction: &WalTransaction,
) -> Result<usize, ShardexError>
pub fn append_transaction( &self, transaction: &WalTransaction, ) -> Result<usize, ShardexError>
Append a WAL transaction to the segment
Sourcepub fn sync(&self) -> Result<(), ShardexError>
pub fn sync(&self) -> Result<(), ShardexError>
Sync segment to disk
Sourcepub fn read_segment_data(&self) -> Result<Vec<u8>, ShardexError>
pub fn read_segment_data(&self) -> Result<Vec<u8>, ShardexError>
Get a copy of the segment data for reading (used during replay)
Sourcepub fn read_range(
&self,
start: usize,
length: usize,
) -> Result<Vec<u8>, ShardexError>
pub fn read_range( &self, start: usize, length: usize, ) -> Result<Vec<u8>, ShardexError>
Read a specific range of data from the segment
Sourcepub fn validate_integrity(&self) -> Result<(), ShardexError>
pub fn validate_integrity(&self) -> Result<(), ShardexError>
Validate segment integrity
Auto Trait Implementations§
impl !Freeze for WalSegment
impl RefUnwindSafe for WalSegment
impl Send for WalSegment
impl Sync for WalSegment
impl Unpin for WalSegment
impl UnsafeUnpin for WalSegment
impl UnwindSafe for WalSegment
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
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