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 [u32-LE length][payload] frames to and from a file and handles the durability concerns — append, fsync, 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.

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