Skip to main content

nodedb_wal/segment/
mod.rs

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