actordb_protocol/version.rs
1//! Portable physical/logical record timestamps.
2
3/// A totally ordered hybrid-clock timestamp.
4///
5/// `timestamp_ms` is physical Unix time; `logical_counter` distinguishes events
6/// at that time without making a busy node's physical clock run ahead. Record
7/// ordering additionally uses writer identity and the tombstone tie-break bit.
8#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
9pub struct RecordVersion {
10 pub timestamp_ms: u64,
11 pub logical_counter: u64,
12}
13
14impl RecordVersion {
15 /// Construct a timestamp from its physical and logical components.
16 pub const fn new(timestamp_ms: u64, logical_counter: u64) -> Self {
17 Self {
18 timestamp_ms,
19 logical_counter,
20 }
21 }
22}
23
24impl From<u64> for RecordVersion {
25 /// Legacy timestamps have a zero logical component.
26 fn from(timestamp_ms: u64) -> Self {
27 Self::new(timestamp_ms, 0)
28 }
29}