Skip to main content

HlcService

Struct HlcService 

Source
pub struct HlcService<S: HlcStorage> { /* private fields */ }
Expand description

Shared HLC service: one lock-protected clock plus its persistence. Serializes now()/observe() across subsystems so they share a single causal clock domain in memory and on disk.

Implementations§

Source§

impl<S: HlcStorage> HlcService<S>

Source

pub fn open(storage: S) -> Result<Self, S::Error>

Seed the in-memory clock from the persisted state (0 if none) and return the service. The persisted state is the last-observed clock position, so causal monotonicity survives crashes.

Source

pub fn now(&self, sink: &mut S::Sink) -> Result<Timestamp, S::Error>

Generate a fresh timestamp for a local write and enqueue the new state into sink. Always advances; always writes — the state must reach the committing batch, or a crash could reissue it.

Source

pub fn observe( &self, received: Timestamp, local_wall_ms: u64, sink: &mut S::Sink, ) -> Result<(), HlcError<S::Error>>

Absorb a remote timestamp, enforcing the skew bound (see Hlc::observe). Saves into sink only when the in-memory state actually advances — observe is a no-op for stale receipts and we don’t want to spam the register.

local_wall_ms is supplied by the caller — typically a single wall_ms reading taken once when a received batch starts replaying — rather than read here per call. This judges a whole batch against one reference instant, so entries don’t drift in and out of the skew window depending on where they fall in the loop, and it keeps the skew tests deterministic. The wall clock only moves forward across a batch, so a shared start-of-batch reading is at worst conservative (it may reject a borderline entry that a fresher reading would admit) — never unsound, since it can’t widen the window.

Source

pub fn state(&self) -> Timestamp

Current clock state without advancing it. Cheap snapshot for callers that only need to peek (e.g. tests, diagnostics).

Auto Trait Implementations§

§

impl<S> !Freeze for HlcService<S>

§

impl<S> RefUnwindSafe for HlcService<S>
where S: RefUnwindSafe,

§

impl<S> Send for HlcService<S>
where S: Send,

§

impl<S> Sync for HlcService<S>
where S: Sync,

§

impl<S> Unpin for HlcService<S>
where S: Unpin,

§

impl<S> UnsafeUnpin for HlcService<S>
where S: UnsafeUnpin,

§

impl<S> UnwindSafe for HlcService<S>
where S: UnwindSafe,

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.