pub struct Clock(/* private fields */);Expand description
A hybrid logical clock (HLC) timestamp, consisting of a modified NTP timestamp rounded to 48 bits and a 16 bit counter value. Instead of the NTP epoch (1900-01-01), this uses the Unix epoch (1970-01-01).
The NTP timestamp is an unsigned 64b fixed point number
- upper 32b are seconds since 1900 (here: 1970)
- lower 32b are fractional seconds
The HLC Timestamp is the same as an NTP timestamp, except for the 16 least significant bits. These represent the “counter” value for correctly ordering events where the system clock has not increased since the last timestamp (this includes “simultaneous” events and events occuring after the system clock is set backwards).
To illustrate:
0000000000000000000000000000000000000000000000000000000000000000 | bits
[------------seconds-----------][-----fractional seconds-------] | NTP
[--------------rounded timestamp---------------][---counter----] | HLCTaken from “Logical Physical Clocks and Consistent Snapshots in Globally Distributed Databases” by Kulkarni, Demirbas, Madeppa, Avva, and Leone. However, unlike the implementation described there, this one is not backwards compatible with NTP because it uses the Unix epoch instead of the NTP epoch.
Implementations§
Source§impl Clock
impl Clock
Sourcepub fn null_clock() -> Self
pub fn null_clock() -> Self
Generate the first ever HLC
Sourcepub fn get_time(self) -> SystemTime
pub fn get_time(self) -> SystemTime
Convert the time component to a SystemTime
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Clock
impl<'de> Deserialize<'de> for Clock
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Ord for Clock
impl Ord for Clock
Source§impl PartialOrd for Clock
impl PartialOrd for Clock
Source§impl Value for Clock
impl Value for Clock
const DEFINITION: ValueDef
type References = <(<u64 as Value>::References,) as Filter>::F
const COLUMN_COUNT: usize = _
impl Copy for Clock
impl Eq for Clock
impl StructuralPartialEq for Clock
Auto Trait Implementations§
impl Freeze for Clock
impl RefUnwindSafe for Clock
impl Send for Clock
impl Sync for Clock
impl Unpin for Clock
impl UnwindSafe for Clock
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Source§impl<T> CloneFromRef<One> for T
impl<T> CloneFromRef<One> for T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.