Skip to main content

Module journal

Module journal 

Source
Expand description

Append-only framed journal.

Persistence is kept orthogonal to serialization. The journal moves opaque versioned, checksummed frames to and from a file and handles the durability concerns — append, fsync, bounded recovery, and recovery of a torn trailing frame after a crash. How a record turns into a payload is entirely the FrameCodec’s business, so the Raft log store can frame protobuf while the WAL engine frames JSON over the exact same code.

Structs§

JournalWriter
An append handle over a single journal file.
JsonCodec
JSON frame codec for any owned, serde-serializable record.

Constants§

MAX_FRAME_PAYLOAD_BYTES
Maximum encoded payload accepted from disk or written as one journal frame.

Traits§

FrameCodec
Serialization seam: how one record becomes a frame payload and back.

Functions§

decode_frames
Decode framed records from an in-memory buffer, returning the records and the byte length of the valid (fully-written) prefix. A torn trailing frame ends the scan.
migrate_legacy
Migrate the legacy [length][payload] journal format to the current checksummed format, retaining a hard-linked .v0.bak rollback copy.
replay
Read every record from path, decoding with C. A torn trailing frame left by a crash mid-write is truncated away and ignored, leaving the file at its last clean record boundary.
replay_each
Stream every valid record from path through visit without retaining the entire journal in memory. A torn trailing frame is truncated with the same recovery semantics as replay.
truncate_to
Truncate path to valid_len bytes, dropping a torn trailing frame, then fsync.