Expand description
WAL segment management.
The WAL is split into fixed-size segment files for efficient truncation. Each segment is a standalone WAL file containing records within an LSN range.
§Naming convention
Segments are named wal-{first_lsn:020}.seg — zero-padded for lexicographic
ordering. This guarantees ls and readdir return segments in LSN order.
§Lifecycle
- Writer creates a new segment when the current segment exceeds
target_size. - The active segment is the one being appended to.
truncate_before(lsn)deletes all sealed segments whosemax_lsn < lsn.- The active segment is NEVER deleted — only sealed (closed) segments are eligible.
§Recovery
On startup, all segment files in the WAL directory are discovered via readdir,
sorted by first_lsn, and replayed in order. The last segment is the active one.
Re-exports§
pub use atomic_io::atomic_swap_dirs_fsync;pub use atomic_io::atomic_write_fsync;pub use atomic_io::fsync_directory;pub use atomic_io::read_checkpoint_dontneed;pub use checkpoint_frame::read_checkpoint_framed;pub use checkpoint_frame::write_checkpoint_framed;pub use continuity::SegmentContinuity;pub use decrypt::SegmentDecryptor;pub use discovery::discover_segments;pub use meta::DEFAULT_SEGMENT_TARGET_SIZE;pub use meta::SegmentMeta;pub use meta::parse_segment_filename;pub use meta::segment_filename;pub use meta::segment_path;pub use orphan::check_resume_above_previous;pub use retained::check_retained_floor;pub use truncate::TruncateResult;pub use truncate::truncate_segments;
Modules§
- atomic_
io - Durable atomic file / directory operations for checkpoint-class writes.
- checkpoint_
frame - CRC-framed checkpoint envelope.
- continuity
- Cross-segment LSN continuity for multi-segment replay.
- decrypt
- Segment-scoped payload decryption.
- discovery
- Discovery of WAL segment files in a directory.
- meta
- Segment filename conventions and on-disk metadata.
- orphan
- Segment files a roll created but never installed.
- retained
- The retained-suffix invariant for replays that start mid-log.
- truncate
- Sealed segment truncation after checkpoint LSN advances.