Skip to main content

DeviceLog

Struct DeviceLog 

Source
pub struct DeviceLog { /* private fields */ }
Expand description

The per-device append discipline: maintains the seq/prev chain and stamps Hlc values from an HlcClock over an injected WallClock — B3’s real hybrid clock, replacing B1’s pure-Lamport stamp source behind the same wire shape.

DeviceLog::new defaults the wall source to logical_clock (always 0), under which the HLC is a Lamport clock (every tick is a counter increment) — B1 semantics as the degenerate case of one code path. Real deployments pass system_clock (or a test-controlled closure) via DeviceLog::with_wall_clock / DeviceLog::set_wall_clock.

Implementations§

Source§

impl DeviceLog

Source

pub fn new(device_id: impl Into<String>) -> Self

Source

pub fn with_wall_clock(device_id: impl Into<String>, wall: WallClock) -> Self

A device log stamping the real HLC over the given wall source (pass system_clock in production, a controlled closure in tests).

Source

pub fn set_wall_clock(&mut self, wall: WallClock)

Swap the wall source on a live log (e.g. after a DeviceLog::resume, which has no wall parameter). Monotonicity is unaffected: the HlcClock never regresses below what it has witnessed, whatever the new source reads.

Source

pub fn resume( device_id: impl Into<String>, ops: &[OpRecord], ) -> Result<Self, ChainError>

Resume a device’s chain from previously persisted ops (e.g. after crate::journal::OplogJournal::load): verifies the log, adopts this device’s chain tail, and advances the clock past every op present (local and remote), so new appends stamp above all of them. The resumed log defaults to the logical_clock wall source — call DeviceLog::set_wall_clock to attach the real one.

MUST: an op is journal-durable before it is transmitted. Resume derives next_seq from the journal; if a crash lands between “op sent to a peer/relay” and “op durably journaled”, the resumed device re-mints that seq for a different op, and the union of the two logs is a permanent DuplicateSeq/PrevMismatch — an unrecoverable fork of the device’s chain. Always OplogJournal::append (which flushes) before handing an op to any transport (B3 must preserve this ordering).

Fenced against truncated tails (B4). If the resuming device’s own chain doesn’t start at seq 0, the ops are a truncated tail and resume refuses (ChainError::TruncatedChain) — the anchored sibling checkpoint::resume_anchored is the correct path. (The case this check can’t see — a device whose ops were ALL truncated away — is fenced one layer down: OplogJournal::load refuses a journal carrying a truncation marker.)

Source

pub fn observe(&mut self, hlc: &Hlc)

HLC receive rule: fold a received op’s stamp into the local clock, so a write that causally follows received ops stamps above them.

Source

pub fn append( &mut self, scope: Scope, surface: Surface, payload: Value, ) -> OpRecord

Append a new op: read the wall, tick the hybrid clock, stamp, link the chain.

Source

pub fn device_id(&self) -> &str

Trait Implementations§

Source§

impl Clone for DeviceLog

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DeviceLog

Source§

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

Formats the value using the given formatter. 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more