Skip to main content

nodedb_wal/segment/
mod.rs

1//! WAL segment management.
2//!
3//! The WAL is split into fixed-size segment files for efficient truncation.
4//! Each segment is a standalone WAL file containing records within an LSN range.
5//!
6//! ## Naming convention
7//!
8//! Segments are named `wal-{first_lsn:020}.seg` — zero-padded for lexicographic
9//! ordering. This guarantees `ls` and `readdir` return segments in LSN order.
10//!
11//! ## Lifecycle
12//!
13//! 1. Writer creates a new segment when the current segment exceeds `target_size`.
14//! 2. The active segment is the one being appended to.
15//! 3. `truncate_before(lsn)` deletes all sealed segments whose `max_lsn < lsn`.
16//! 4. The active segment is NEVER deleted — only sealed (closed) segments are eligible.
17//!
18//! ## Recovery
19//!
20//! On startup, all segment files in the WAL directory are discovered via `readdir`,
21//! sorted by first_lsn, and replayed in order. The last segment is the active one.
22
23pub mod atomic_io;
24pub mod discovery;
25pub mod meta;
26pub mod migration;
27pub mod truncate;
28
29pub use atomic_io::{
30    atomic_swap_dirs_fsync, atomic_write_fsync, fsync_directory, read_checkpoint_dontneed,
31};
32pub use discovery::discover_segments;
33pub use meta::{DEFAULT_SEGMENT_TARGET_SIZE, SegmentMeta, segment_filename, segment_path};
34pub use migration::migrate_legacy_wal;
35pub use truncate::{TruncateResult, truncate_segments};