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
impl SegmentedWal
Sourcepub fn open(config: SegmentedWalConfig) -> Result<Self>
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.
Sourcepub fn set_encryption_ring(&mut self, ring: KeyRing) -> Result<()>
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.
Sourcepub fn configure_encryption_ring(&mut self, ring: KeyRing) -> Result<()>
pub fn configure_encryption_ring(&mut self, ring: KeyRing) -> Result<()>
Configure encryption for a newly created WAL or roll an already-open active segment before switching keys on restart.
Sourcepub fn encryption_ring(&self) -> Option<&KeyRing>
pub fn encryption_ring(&self) -> Option<&KeyRing>
Get the encryption key ring (for replay decryption).
Sourcepub fn rotate_encryption_ring(&mut self, ring: KeyRing) -> Result<()>
pub fn rotate_encryption_ring(&mut self, ring: KeyRing) -> Result<()>
Seal the active segment and start a new segment under ring.
This is the only safe runtime key-rotation boundary because a segment’s
encryption epoch and key are fixed by its preamble.
Sourcepub fn append(
&mut self,
record_type: u32,
tenant_id: u64,
vshard_id: u32,
database_id: u64,
payload: &[u8],
) -> Result<u64>
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).
Sourcepub fn append_keyed(
&mut self,
target: RecordTarget,
payload: &[u8],
apply_key: u64,
) -> Result<u64>
pub fn append_keyed( &mut self, target: RecordTarget, payload: &[u8], apply_key: u64, ) -> Result<u64>
Self::append for a record appended by the apply of the replicated
proposal apply_key, carrying the event source in target (see
crate::WalRecord::new_stamped).
Sourcepub fn seal_active_segment(&mut self) -> Result<()>
pub fn seal_active_segment(&mut self) -> Result<()>
Seal the active segment and start the next one, so every record appended so far sits in a sealed segment. A no-op when the active segment holds no record.
Sourcepub fn max_payload(&self) -> usize
pub fn max_payload(&self) -> usize
The largest payload one record takes (see WalWriter::max_payload).
Sourcepub fn active_segment_first_lsn(&self) -> u64
pub fn active_segment_first_lsn(&self) -> u64
First LSN of the active (currently written) segment.
Sourcepub fn truncate_before(&self, checkpoint_lsn: u64) -> Result<TruncateResult>
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.
Sourcepub fn replay(&self) -> Result<Vec<WalRecord>>
pub fn replay(&self) -> Result<Vec<WalRecord>>
Replay all committed records across all segments, in LSN order.
Used for crash recovery on startup. Payloads are returned as plaintext: this WAL’s own key ring is applied to every encrypted record.
Sourcepub fn replay_from(&self, from_lsn: u64) -> Result<Vec<WalRecord>>
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.
Fails with WalError::ReplayBelowRetainedFloor when from_lsn names
an LSN truncation has already deleted, rather than returning the shorter
suffix that survives. Delegating to replay_from_limit_dir keeps that
check — and the per-segment continuity and torn-tail checks — in one
place instead of replaying everything and filtering afterwards.
Sourcepub fn replay_from_limit(
&self,
from_lsn: u64,
max_records: usize,
) -> Result<(Vec<WalRecord>, bool)>
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).
Sourcepub fn list_segments(&self) -> Result<Vec<SegmentMeta>>
pub fn list_segments(&self) -> Result<Vec<SegmentMeta>>
List all segment metadata (for monitoring / operational tooling).
Sourcepub fn total_size_bytes(&self) -> Result<u64>
pub fn total_size_bytes(&self) -> Result<u64>
Total WAL size on disk across all segments.
Auto Trait Implementations§
impl !Freeze for SegmentedWal
impl !Sync for SegmentedWal
impl RefUnwindSafe for SegmentedWal
impl Send for SegmentedWal
impl Unpin for SegmentedWal
impl UnsafeUnpin for SegmentedWal
impl UnwindSafe for SegmentedWal
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.