Skip to main content

TransactionBuilder

Struct TransactionBuilder 

Source
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

Source

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.

Source

pub fn is_empty(&self) -> bool

Source

pub fn block_count(&self) -> usize

Source

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.

Source

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.

Source

pub fn summary(&self, sequence_num: u32) -> TransactionSummary

A preview of the blocks this builder would write, for the GUI.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Debug for TransactionBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for TransactionBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.