Skip to content

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).

  1. List segments in id order. For each, read blocks in order and decode.
  2. The first accepted block of the stream may start mid-record. Skip to first_record, or skip the block if it is 0xFFFF.
  3. Accept a following block if stream_offset equals the expected value (the previous stream_offset + used) and generation is at least the previous one. Alternatively, if its generation is newer and stream_offset equals 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.
  4. Complete records are CRC-checked. A mismatch is Corrupt, not a silent stop. Records are delivered with their LSN. Commit records with end > replay_from are applied to the memtable. Intents are tracked until resolved or cancelled, see Auxiliary record.
  5. 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.
  6. 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).