pub struct WALRecovery { /* private fields */ }Expand description
WAL recovery engine
Reconstructs database state by replaying WAL records. Uses in-memory page cache during recovery; actual page operations are deferred until BTreeManager integration.
§Recovery Process
- Open WAL file and read header
- Read records sequentially until EOF or unrecoverable error
- For each valid record, update internal state
- Return final header state and statistics
§Note
This is a simplified recovery implementation that works without BTreeManager. Full integration with BTreeManager is deferred to Task 65-04.
Implementations§
Source§impl WALRecovery
impl WALRecovery
Sourcepub fn stats(&self) -> &WALRecoveryStats
pub fn stats(&self) -> &WALRecoveryStats
Get recovery statistics
Sourcepub fn checkpoint_header(&self) -> Option<&PersistentHeaderV3>
pub fn checkpoint_header(&self) -> Option<&PersistentHeaderV3>
Get last checkpoint header (if any)
Sourcepub fn recover(&mut self) -> NativeResult<()>
pub fn recover(&mut self) -> NativeResult<()>
Recover from WAL file
Reads WAL file and applies all records sequentially. Returns Ok(()) on successful recovery, even if some records were skipped.
Sourcepub fn get_header_state(&self) -> Option<&PersistentHeaderV3>
pub fn get_header_state(&self) -> Option<&PersistentHeaderV3>
Get header state from last checkpoint (if available)
Returns the PersistentHeaderV3 that was captured in the most recent checkpoint record. This can be used to restore the database to a consistent state.
Sourcepub fn recover_kv(&mut self, kv_store: &mut KvStore) -> NativeResult<usize>
pub fn recover_kv(&mut self, kv_store: &mut KvStore) -> NativeResult<usize>
Recover KV state from WAL records
Replays only KV-related records (KvSet, KvDelete, KvTombstone) to rebuild an in-memory KvStore. This is called during V3Backend::open() to restore KV durability across close/reopen cycles.
§V3 KV RECOVERY CONTRACT
§Recovery Precedence (in order):
- WAL replay (authoritative): If WAL exists, replay all KV records
- This captures the latest state including mutations after last flush
- Checkpoint fallback: If WAL missing, read checkpoint file
- This captures the last flushed state (before WAL truncation)
- Empty KV: If neither WAL nor checkpoint recoverable
- Returns Ok(0) to indicate no KV records applied
- Caller decides whether to continue with empty KV
§Corruption Handling:
- Corrupt checkpoint files are auto-deleted (see cleanup_corrupt_checkpoint)
- Checkpoint errors do NOT propagate (return Ok(0) instead)
- WAL errors DO propagate (WAL is authoritative, corruption is serious)
§Lifecycle Scenarios:
- After flush(): checkpoint=latest, WAL=empty → checkpoint recovery
- Before flush(): WAL=latest, checkpoint=stale → WAL recovery
- Corrupt checkpoint + valid WAL → WAL recovery (checkpoint never checked)
- Corrupt checkpoint + no WAL → empty KV (checkpoint deleted, logged)
§Arguments
kv_store- Mutable reference to the KvStore to rebuild
§Returns
Ok(kv_records_applied)- Number of KV records successfully appliedErr(NativeBackendError)- If WAL file cannot be read (WAL errors propagate)
Trait Implementations§
Auto Trait Implementations§
impl Freeze for WALRecovery
impl RefUnwindSafe for WALRecovery
impl Send for WALRecovery
impl Sync for WALRecovery
impl Unpin for WALRecovery
impl UnsafeUnpin for WALRecovery
impl UnwindSafe for WALRecovery
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
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