Skip to main content

SegmentedWal

Struct SegmentedWal 

Source
pub struct SegmentedWal { /* private fields */ }
Expand description

A segmented write-ahead log.

Manages a directory of WAL segment files. Records are appended to the active segment. When the active segment exceeds segment_target_size, a new segment is created automatically on the next append.

Implementations§

Source§

impl SegmentedWal

Source

pub fn open(config: SegmentedWalConfig) -> Result<Self>

Open or create a segmented WAL in the given directory.

On first startup, creates the directory and the first segment. On subsequent startups, discovers existing segments and opens the last one for continued appending.

Source

pub fn set_encryption_ring(&mut self, ring: KeyRing) -> Result<()>

Set the encryption key ring. All subsequent records will be encrypted.

Must be called before the first append. Returns an error if records have already been written to the active segment.

Source

pub fn encryption_ring(&self) -> Option<&KeyRing>

Get the encryption key ring (for replay decryption).

Source

pub fn append( &mut self, record_type: u32, tenant_id: u64, vshard_id: u32, database_id: u64, payload: &[u8], ) -> Result<u64>

Append a record to the WAL. Returns the assigned LSN.

If the active segment has exceeded the target size, a new segment is created before appending. The rollover is transparent to the caller.

database_id is stored in header bytes 34-41. Pass 0 for the default database (backward-compatible with pre-existing records).

Source

pub fn sync(&mut self) -> Result<()>

Flush all buffered records and fsync the active segment.

Source

pub fn next_lsn(&self) -> u64

The next LSN that will be assigned.

Source

pub fn active_segment_first_lsn(&self) -> u64

First LSN of the active (currently written) segment.

Source

pub fn wal_dir(&self) -> &Path

The WAL directory path.

Source

pub fn truncate_before(&self, checkpoint_lsn: u64) -> Result<TruncateResult>

Truncate old WAL segments that are fully below the checkpoint LSN.

Only sealed (non-active) segments are eligible for deletion. The active segment is never deleted.

Returns the number of segments deleted and bytes reclaimed.

Source

pub fn replay(&self) -> Result<Vec<WalRecord>>

Replay all committed records across all segments, in LSN order.

Used for crash recovery on startup.

Source

pub fn replay_from(&self, from_lsn: u64) -> Result<Vec<WalRecord>>

Replay only records with LSN >= from_lsn.

Used when recovering from a checkpoint — records before the checkpoint LSN have already been applied from the snapshot.

Source

pub fn replay_from_limit( &self, from_lsn: u64, max_records: usize, ) -> Result<(Vec<WalRecord>, bool)>

Paginated replay (delegates to standalone replay_from_limit_dir).

Source

pub fn list_segments(&self) -> Result<Vec<SegmentMeta>>

List all segment metadata (for monitoring / operational tooling).

Source

pub fn total_size_bytes(&self) -> Result<u64>

Total WAL size on disk across all segments.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more