Skip to main content

Module segment

Module segment 

Source
Expand description

Writing the archive in segments.

A segment nominally covers segment_ledgers consecutive ledgers. Validations for one ledger arrive over several seconds and some are late, so a segment is not closed exactly at the range boundary but once a validation arrives grace_ledgers past it. Anything later than that goes into the next segment; every record carries its own ledger index, so readers are not affected.

Data directory layout:

current.xwvj        journal of the open segment
current.json        what this segment is: nominal start, open time
segments/           closed segments: *.xwv.zst and seals *.seal.json

The closing order is chosen so that a crash at any moment loses nothing: the compressed segment and the seal are written first (via temporary files and rename), and only then is the journal deleted. If the process dies between these steps, the seal already exists at startup, so the journal is treated as a duplicate and deleted.

Structs§

Sealed
Result of closing a segment, for the archiver’s event log.
SegmentConfig
SegmentWriter

Functions§

latest_seal
The most recently sealed seal in the segments directory.
read_segment
Reads a closed segment in full.
read_segment_raw
Decompressed content of a closed segment: what the seal commits to.
verify_segment
The segment matches its seal: the seal is intact and the content is the same.