pub struct HybridLogicalClock {
pub timestamp: SystemTime,
pub counter: u64,
pub node_id: String,
}Expand description
Hybrid Logical Clock (HLC) generating unique timestamps
Fields§
§timestamp: SystemTimeCurrent timestamp.
counter: u64Counter is used to coordinate ordering of events within a distributed system where each device may have slightly different system clock times.
node_id: StringUnique identifier for this node.
Implementations§
Source§impl HybridLogicalClock
impl HybridLogicalClock
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new HybridLogicalClock with the current timestamp, a counter of 0,
and a unique identifier
Sourcepub fn update(
&mut self,
other: &HybridLogicalClock,
max_clock_drift: Duration,
) -> Result<(), HLCError>
pub fn update( &mut self, other: &HybridLogicalClock, max_clock_drift: Duration, ) -> Result<(), HLCError>
Updates the HybridLogicalClock based on another HybridLogicalClock.
Self will be set to the latest timestamp between itself, other, and the current time, and
its counter will also be updated accordingly.
Note: Update performed against another HybridLogicalClock with the same node_id
is a no-op, and will not result in an error.
§Errors
HLCError of kind OverflowWarning if
the HybridLogicalClock’s counter would be set to a value that would overflow beyond u64::MAX
HLCError of kind ClockDrift if the latest HybridLogicalClock
(of Self or other)’s timestamp is too far in the future (determined by max_clock_drift)
compared to SystemTime::now()
Sourcepub fn update_now(&mut self, max_clock_drift: Duration) -> Result<(), HLCError>
pub fn update_now(&mut self, max_clock_drift: Duration) -> Result<(), HLCError>
Updates the HybridLogicalClock based on the current time
§Errors
HLCError of kind OverflowWarning if
the HybridLogicalClock’s counter would be set to a value that would overflow beyond u64::MAX
HLCError of kind ClockDrift if the HybridLogicalClock
timestamp is too far in the future (determined by max_clock_drift) compared to SystemTime::now()
compared to SystemTime::now()
Trait Implementations§
Source§impl Clone for HybridLogicalClock
impl Clone for HybridLogicalClock
Source§fn clone(&self) -> HybridLogicalClock
fn clone(&self) -> HybridLogicalClock
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more