pub struct HlcTimestamp(/* private fields */);Expand description
Hybrid logical clock (HLC) timestamp.
This is a lock-free implementation of a hybrid logical clock (HLC) timestamp.
The timestamp is represented as a 64-bit unsigned integer. The upper 42 bits represent the physical time in milliseconds since a custom epoch, and the lower 22 bits represent the logical clock count.
Normally, you don’t need to worry about the details of the representation.
Whenever you need to create a new timestamp, use the
new() to create a timestamp with the current time,
or from_parts() to create a timestamp with a
specific Unix timestamp (in ms) and logical clock count.
When you need to update the timestamp, use the update()
method.
Finally, you can use the as_u64() method to get the raw
data, which is guaranteed to be monotonically increasing and capturing the
happens-before relationship.
To get the physical time and logical clock count, use the
timestamp() and count() methods
respectively.
Implementations§
Source§impl HlcTimestamp
impl HlcTimestamp
Sourcepub fn from_parts(pt: i64, lc: u64) -> HlcResult<Self>
pub fn from_parts(pt: i64, lc: u64) -> HlcResult<Self>
Creates a new HLC timestamp from the given physical time and logical clock count.
Sourcepub fn update<F>(&self, new_values: F) -> HlcResult<HlcTimestamp>
pub fn update<F>(&self, new_values: F) -> HlcResult<HlcTimestamp>
Sets the physical time and logical clock count.
Expected closure gets the current physical time and logical clock count at the moment of the call and must return the new values for both.
This is an atomic operation that ensures thread safety in a lock-free fashion. Either both values are updated or none are.