pub struct LamportClock { /* private fields */ }Expand description
Lamport Clock for happens-before ordering
Implements Lamport’s logical clocks for establishing causal relationships between events in a distributed tracing system.
Reference: “Time, Clocks, and the Ordering of Events in a Distributed System” Lamport, L. Communications of the ACM, 21(7), 558-565 (1978)
§Properties
- Transitivity: a → b ∧ b → c ⇒ a → c
- Irreflexivity: ¬(a → a)
- Timestamp consistency: a → b ⇒ timestamp(a) < timestamp(b)
Implementations§
Source§impl LamportClock
impl LamportClock
Sourcepub fn with_initial_value(initial: u64) -> Self
pub fn with_initial_value(initial: u64) -> Self
Create a Lamport clock with a specific starting value
Sourcepub fn tick(&self) -> u64
pub fn tick(&self) -> u64
Increment clock on local event
Returns the new timestamp after increment.
Uses SeqCst ordering to ensure happens-before consistency.
Sourcepub fn sync(&self, remote_timestamp: u64) -> u64
pub fn sync(&self, remote_timestamp: u64) -> u64
Synchronize clock on message receive
Updates local clock to max(local, remote) + 1. Ensures received messages have higher timestamps than their causally preceding events.
Sourcepub fn happens_before(a: u64, b: u64) -> bool
pub fn happens_before(a: u64, b: u64) -> bool
Check if timestamp a happens-before timestamp b
Returns true if a < b (strict temporal ordering).
Note: This is a simple timestamp comparison. Full happens-before
semantics require checking causal chains (see UnifiedTrace).