pub struct WriteAheadLog {
pub prev_dag_hash: [u8; 32],
/* private fields */
}Expand description
The Write-Ahead Log (WAL) ensures mobile fault tolerance by appending all 48-byte Quin mutations directly to flash memory synchronously before they are packed into the larger 40KB SuperBlock structures.
The WAL also maintains a prev_dag_hash linking each checkpoint into the
git_bridge::DagStore Merkle-DAG so the full write history is content-addressed.
Fields§
§prev_dag_hash: [u8; 32]SHA-256 of the most recent DagNode committed from this WAL.
[0u8; 32] means no prior checkpoint — next call to checkpoint_to_dag triggers genesis_node.
Implementations§
Source§impl WriteAheadLog
impl WriteAheadLog
Sourcepub fn open<P: AsRef<Path>>(path: P) -> Result<Self>
pub fn open<P: AsRef<Path>>(path: P) -> Result<Self>
Opens or creates the append-only WAL file at path.
If the file already has a 32-byte header (prior checkpoint hash), it is read back so the chain is preserved across restarts.
Sourcepub fn append_mutation(&mut self, quin: &NQuin) -> Result<()>
pub fn append_mutation(&mut self, quin: &NQuin) -> Result<()>
Synchronously appends a NQuin to the log and flushes to disk. This prevents data loss if the OS kills the process.
Sourcepub fn append_mutation_volatile(&mut self, quin: &mut NQuin) -> Result<()>
pub fn append_mutation_volatile(&mut self, quin: &mut NQuin) -> Result<()>
Append with volatile field scrub after durable sync (wipes transient reasoning state).
Sourcepub fn recover(&mut self) -> Result<Vec<NQuin>>
pub fn recover(&mut self) -> Result<Vec<NQuin>>
Reconstructs uncommitted NQuins from the WAL (skips the 32-byte header).
Sourcepub fn truncate(&mut self) -> Result<()>
pub fn truncate(&mut self) -> Result<()>
Wipes the NQuin region of the WAL after a SuperBlock commit, preserving the header.
Call checkpoint_to_dag before this so the hash chain is updated first.
Sourcepub fn checkpoint_to_dag(
&mut self,
dag_store: &mut DagStore,
author_did: u64,
timestamp_ms: u64,
) -> Result<[u8; 32]>
pub fn checkpoint_to_dag( &mut self, dag_store: &mut DagStore, author_did: u64, timestamp_ms: u64, ) -> Result<[u8; 32]>
Commit the current WAL contents as a DagNode, updating prev_dag_hash.
If the WAL is empty (no quins since the last checkpoint), this is a no-op and
returns the existing prev_dag_hash.
Typical call sequence:
wal.checkpoint_to_dag(&mut dag_store, author_did, now_ms())?;
wal.truncate()?;Sourcepub fn buffered_count(&mut self) -> Result<usize>
pub fn buffered_count(&mut self) -> Result<usize>
Return the number of NQuin records currently buffered in the WAL.
Auto Trait Implementations§
impl Freeze for WriteAheadLog
impl RefUnwindSafe for WriteAheadLog
impl Send for WriteAheadLog
impl Sync for WriteAheadLog
impl Unpin for WriteAheadLog
impl UnsafeUnpin for WriteAheadLog
impl UnwindSafe for WriteAheadLog
Blanket Implementations§
§impl<S, A> Aggregate<Result<S, Error>> for Awhere
A: Aggregate<S>,
impl<S, A> Aggregate<Result<S, Error>> for Awhere
A: Aggregate<S>,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more