pub struct TransactionBuilder { /* private fields */ }Expand description
Buffers dirty 512-byte-aligned blocks during one high-level mutation and
emits them as a single journal transaction at commit time. Mirrors the
idempotent last-write-wins semantics of xnu’s
journal_modify_block_start/end.
Implementations§
Source§impl TransactionBuilder
impl TransactionBuilder
Sourcepub fn new(block_size: u32) -> Self
pub fn new(block_size: u32) -> Self
block_size is the journal’s jhdr_size — the unit bnum is scaled by
and the granularity at which blocks are recorded.
pub fn is_empty(&self) -> bool
pub fn block_count(&self) -> usize
Sourcepub fn record_block(&mut self, offset: u64, bytes: &[u8])
pub fn record_block(&mut self, offset: u64, bytes: &[u8])
Record one block_size-aligned block. offset must be a multiple of
block_size; bytes must be exactly block_size long.
Sourcepub fn record_range(&mut self, offset: u64, bytes: &[u8])
pub fn record_range(&mut self, offset: u64, bytes: &[u8])
Record an arbitrary byte range, splitting it into block_size chunks.
The range must be block-aligned in both offset and length.
Sourcepub fn summary(&self, sequence_num: u32) -> TransactionSummary
pub fn summary(&self, sequence_num: u32) -> TransactionSummary
A preview of the blocks this builder would write, for the GUI.
Sourcepub fn commit<RW: Read + Write + Seek>(
self,
disk: &mut RW,
jib: &JournalInfoBlock,
jh: &mut JournalHeader,
partition_offset: u64,
) -> Result<(), JournalError>
pub fn commit<RW: Read + Write + Seek>( self, disk: &mut RW, jib: &JournalInfoBlock, jh: &mut JournalHeader, partition_offset: u64, ) -> Result<(), JournalError>
Commit the buffered blocks as one transaction. The six-phase ordering
matches xnu (TN1150): write the transaction body at jh.end, advance
jh.end/sequence_num and persist the header, apply the blocks to
their real locations, then advance jh.start = jh.end and persist
again. A crash between header writes is recoverable by replay_journal.
Sourcepub fn write_to_journal<RW: Read + Write + Seek>(
&self,
disk: &mut RW,
jib: &JournalInfoBlock,
jh: &mut JournalHeader,
partition_offset: u64,
) -> Result<(), JournalError>
pub fn write_to_journal<RW: Read + Write + Seek>( &self, disk: &mut RW, jib: &JournalInfoBlock, jh: &mut JournalHeader, partition_offset: u64, ) -> Result<(), JournalError>
Phases 1-4 of [commit]: build the transaction body, write it at
jh.end (wrapping), advance jh.end/sequence_num, and persist the
header. Leaves the journal dirty (start != end) — the blocks have
not yet been applied to their real locations. replay_journal (or
the rest of [commit]) finishes the job. Exposed for tests that need a
dirty journal and for callers that batch the checkpoint separately.