Skip to main content

Module hlc

Module hlc 

Source
Expand description

Hybrid-logical-clock timestamps: the total order behind last-writer-wins registers. The value model lives here; crate::hlc::Hlc is the clock-retaining service that mints and advances them.

Structs§

Hlc
Timestamp
A parsed HLC timestamp.
UpdatedAtStamper
The database-owned _updated_at stamping capability over its shared Hlc.

Constants§

HIGHWATER_STATE_KEY
protocol_state key under which the clock’s high-water mark is persisted, so it cannot regress across restarts (see Hlc::seed). Written whenever the clock advances (host stamp flushed at cycle end, and on apply-merge).
MAX_FUTURE_SKEW_MS
How far ahead of the receiver’s wall clock an incoming _updated_at’s physical (millis) component may sit and still be treated as honest. A device can legitimately be offline for a long stretch and cross-device wall clocks drift, so the window is generous — 30 days. A stamp beyond receiver wall + this has no honest explanation (a broken clock or buggy client), so the receiver refuses to let it win last-writer-wins or ratchet the local clock. The bound is one-sided: only grossly-future stamps are rejected; a stamp in the past is always honest (an offline device’s older edits) and is never bounded.

Functions§

now_wall_ms
The OS wall clock in epoch milliseconds — the same physical source Hlc stamps from. Production reads “now” through an injected clock (Hlc::wall_now_ms); this is for callers that apply a trusted, already- captured changeset against a raw connection with no injected clock (snapshot round-trips, gate/FK mechanics tests), where the honest receiver-now is real wall time and the future-skew bound is incidental, not under test.