brazier/store/hlc
Hybrid logical clock (Kulkarni, Demirbas et al., “Logical Physical Clocks and Consistent Snapshots in Globally Distributed Databases”, 2014), used to order writes to a replicated store.
A timestamp is the wall clock in milliseconds, a logical counter that orders events within the same millisecond (or while the wall clock lags a timestamp already seen), and the writing node’s name. Timestamps compare by wall time, then logical counter, then node name, so every two timestamps from different nodes are ordered the same way on every node.
The clock never goes backwards: tick (a local write) and observe (a
remote write merged here) both return a timestamp strictly greater than
every timestamp this node has produced or seen, even if the wall clock
stepped back.
Types
Values
pub fn compare(a: Timestamp, b: Timestamp) -> order.Order
Total order: wall time, then logical counter, then node name.
pub fn drift_ms(remote: Timestamp, now_ms: Int) -> Int
How far remote is ahead of the wall clock, in milliseconds (0 if it is
not ahead). The replica logs a warning above its drift threshold.
pub fn observe(
last: Timestamp,
remote: Timestamp,
now_ms: Int,
) -> Timestamp
The clock after merging a remote timestamp: greater than both last and
remote. Keeps this node’s name.