Recovery
replay (crates/strata-wal/src/replay.rs) rebuilds the memtable from the WAL. It runs as the last step of the open sequence, starting from the MANIFEST’s replay_from (see State and levels).
- List segments in id order. For each, read blocks in order and decode.
- The first accepted block of the stream may start mid-record. Skip to
first_record, or skip the block if it is0xFFFF. - Accept a following block if
stream_offsetequals the expected value (the previousstream_offset + used) andgenerationis at least the previous one. Alternatively, if its generation is newer andstream_offsetequals the start of the incomplete pending record, it replaces that record. That is a torn tail rewritten by a later process. Anything else stops replay. - Complete records are CRC-checked. A mismatch is
Corrupt, not a silent stop. Records are delivered with their LSN. Commit records withend > replay_fromare applied to the memtable. Intents are tracked until resolved or cancelled, see Auxiliary record. - An invalid block ends the segment. If the next segment’s first block is not accepted, replay stops there. After a stop every later segment is deleted.
- The writer resumes at the stream offset of the first incomplete record, in a new block, with the new epoch as generation.
Segments wholly before replay_from are deleted after open and every 512 commits, unless the archive gate holds them for upload (SPEC V60, V68).