pub struct Hlc { /* private fields */ }Expand description
Hybrid Logical Clock.
Thread-safe via interior Mutex. Create one per application lifetime,
pass by reference to write methods.
Implementations§
Source§impl Hlc
impl Hlc
pub fn try_new(device_id: String) -> Result<Self, PathTokenError>
Sourcepub fn seed(&self, high_water: &Timestamp)
pub fn seed(&self, high_water: &Timestamp)
Seed the clock’s monotonic state from a persisted high-water mark so it cannot mint a stamp behind a value it minted (or saw) before a restart.
Idempotent and monotonic: a seed below the current state is ignored, so
re-seeding can only push the clock forward. The seeded device_id is
irrelevant — only millis/counter gate future stamps.
Sourcepub fn high_water(&self) -> Timestamp
pub fn high_water(&self) -> Timestamp
Sourcepub fn wall_now_ms(&self) -> u64
pub fn wall_now_ms(&self) -> u64
The receiver’s current wall-clock millis, read from the same injected
source the clock stamps from. This is the reference the pull bounds an
incoming _updated_at against (see Timestamp::is_within_future_bound):
it is the receiver’s view of “now”, in the same millis unit as a stamp’s
physical component — never an author-supplied value. Read once per pull and
passed down, not sampled in a loop.
Sourcepub fn now(&self) -> Timestamp
pub fn now(&self) -> Timestamp
Generate a new timestamp. Guaranteed to be greater than any previous timestamp returned by this clock.
Sourcepub fn advance_past(&self, remote: &Timestamp)
pub fn advance_past(&self, remote: &Timestamp)
Record an applied row’s _updated_at as the clock floor, so the next local
stamp sorts causally after it. remote is an authoritative register
value the LWW layer already accepted and wrote to disk — never an
untrusted peer wall clock — so recording it is unconditional: no skew
cap. Capping here would let the next local edit mint a stamp below an
already-stored applied row and lose LWW to it.
Monotonic: a remote ahead of the current state becomes the state floor;
one behind it is ignored. Either way the next [now] outranks remote.