pub struct Vclock(/* private fields */);
Expand description
Tarantool vector clock.
Find the explanation of the concept in the module documentation.
Vclock
is a mapping (HashMap
) of
replica id (usize
) to its LSN (u64
).
Unlike in Tarantool, Vclock
doesn’t impose any restrictions on the
replica ids (in Tarantool its valid range is 0..32
).
Vclock
supports equality comparison (Eq
) and
partial ordering (PartialOrd
). Two vclocks
are said to be a => b
if and only if for every component i
it’s
true that a[i] => b[i]
. Missing components are treated as 0
.
use tarantool::vclock::Vclock;
let vc1 = Vclock::from([1, 9, 88]);
let vc2 = Vclock::from([1, 10, 100]);
assert!(vc1 < vc2);
Since vclocks do not form a total order some vclock instances might
be incomparible, leading to both >=
and <=
returning false
.
Such situations can be detected by directly calling partial_cmp
and checking if it returns None
.
use tarantool::vclock::Vclock;
use std::cmp::PartialOrd;
let vc1 = Vclock::from([0, 100]);
let vc2 = Vclock::from([100, 0]);
assert_eq!(vc1 <= vc2, false);
assert_eq!(vc1 >= vc2, false);
assert!(vc1.partial_cmp(&vc2).is_none());
Implementations§
source§impl Vclock
impl Vclock
sourcepub fn try_current() -> Result<Self, LuaError>
pub fn try_current() -> Result<Self, LuaError>
Obtains current vclock from Tarantool box.info.vclock
API.
Returns an error if box.cfg{ .. }
was not called yet.
sourcepub fn ignore_zero(self) -> Self
pub fn ignore_zero(self) -> Self
Sets zero component to 0. It’s used for tracking local updates that aren’t replicated so it should be excluded from comparison of vclocks of different replicas.
Example
let vc = Vclock::from([100, 1]);
assert_eq!(vc.ignore_zero(), Vclock::from([0, 1]));
sourcepub fn into_inner(self) -> HashMap<usize, Lsn>
pub fn into_inner(self) -> HashMap<usize, Lsn>
Consumes the Vclock
, returning underlying HashMap
.
Example
let vc = Vclock::from([0, 0, 200]);
assert_eq!(vc.into_inner(), HashMap::from([(2, 200)]))
sourcepub fn cmp(&self, other: &Self, ignore_zero: bool) -> Option<Ordering>
pub fn cmp(&self, other: &Self, ignore_zero: bool) -> Option<Ordering>
Does a component-wise comparison of self
against other
.
If ignore_zero
is true
, the component at index 0
is ignored. This
is useful for comparing vclocks from different replicas, because the
zeroth component only tracks local updates.
Trait Implementations§
source§impl<'de> Deserialize<'de> for Vclock
impl<'de> Deserialize<'de> for Vclock
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<L> LuaRead<L> for Vclockwhere
L: AsLua,
impl<L> LuaRead<L> for Vclockwhere
L: AsLua,
source§fn lua_read_at_position(lua: L, index: NonZeroI32) -> ReadResult<Self, L>
fn lua_read_at_position(lua: L, index: NonZeroI32) -> ReadResult<Self, L>
fn n_values_expected() -> i32
fn lua_read_at_maybe_zero_position(
lua: L,
index: i32
) -> Result<Self, (L, WrongType)>where
L: AsLua,
source§impl PartialEq for Vclock
impl PartialEq for Vclock
source§impl PartialOrd for Vclock
impl PartialOrd for Vclock
source§fn partial_cmp(&self, other: &Self) -> Option<Ordering>
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
Does a component-wise comparison of self
against other
.
Includes the components at index 0
in the comparison, so it’s probably
not suitable for comparing vclocks from different replicas.
See also Self::cmp_ignore_zero
.
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more