pub struct ChainAssembler { /* private fields */ }Expand description
Reconstructs a (possibly chained) commit from consecutive framed WAL
records, fed one at a time in physical log order. The overwhelmingly
common case — a BARE/WITH_COMMAND record — reconstructs immediately.
A chained commit’s CHAIN_CONTINUE fragments are buffered until the
matching CHAIN_FINAL is fed, at which point the whole op-set is
returned — in full, exactly once, never partially. This is the one
reconstruction implementation crash recovery and replication apply both
use, so there is never a second, potentially drifting copy of this logic.
Implementations§
Source§impl ChainAssembler
impl ChainAssembler
Sourcepub fn feed(&mut self, raw: &[u8], offset: u64) -> Result<ChainFeed, String>
pub fn feed(&mut self, raw: &[u8], offset: u64) -> Result<ChainFeed, String>
Feed one decoded, checksum-verified framed record, at offset in
whatever byte stream the caller is scanning (the segment file for
recovery, the replication page stream for a follower). Purely
structural: never decodes the op-set or command (see
ChainFeed::Complete’s doc for why).
§Errors
Returns an error if a CHAIN_CONTINUE/CHAIN_FINAL arrives for a
different LSN than the currently-open chain, if a BARE/
WITH_COMMAND record arrives while a chain is open, or if the frame
itself fails to decode (bad magic/version/checksum) — all of which
indicate a corrupt or reordered log, never a legitimate write
pattern.
Sourcepub fn is_open(&self) -> bool
pub fn is_open(&self) -> bool
True while a chain is open (fragments buffered, final not yet seen).
Sourcepub fn open_start_offset(&self) -> Option<u64>
pub fn open_start_offset(&self) -> Option<u64>
The byte offset where the currently-open chain’s first fragment began, if any — what a caller reaching end-of-stream with an open chain must truncate back to (discarding the whole incomplete chain, never partially applying it).