Struct tarantool::vclock::Vclock

source ·
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

source

pub fn current() -> Self

Obtains current vclock from Tarantool box.info.vclock API.

Example
dbg!(Vclock::current());

Example output:

Vclock({0: 2, 1: 101})
Panics

If box.cfg{ .. } was not called yet.

source

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.

source

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]));
source

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)]))
source

pub fn get(&self, index: usize) -> Lsn

Returns an Lsn at index or zero if it is not present.

Example
let vc = Vclock::from([0, 10]);
assert_eq!(vc.get(0), 0);
assert_eq!(vc.get(1), 10);
assert_eq!(vc.get(2), 0);
source

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.

source

pub fn cmp_ignore_zero(&self, other: &Self) -> Option<Ordering>

Does a component-wise comparison of self against other.

Ignores the components at index 0.

See also Self::cmp.

Trait Implementations§

source§

impl Clone for Vclock

source§

fn clone(&self) -> Vclock

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Vclock

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'de> Deserialize<'de> for Vclock

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<const N: usize> From<[u64; N]> for Vclock

source§

fn from(from: [Lsn; N]) -> Self

Converts an array [Lsn; N] into a Vclock, skipping components with LSN equal to 0.

Primarily used for testing. It has no meaningful application in the real world.

source§

impl<L> LuaRead<L> for Vclock
where L: AsLua,

source§

fn lua_read_at_position(lua: L, index: NonZeroI32) -> ReadResult<Self, L>

Reads the data from Lua at a given position.
source§

fn n_values_expected() -> i32

source§

fn lua_read(lua: L) -> Result<Self, (L, WrongType)>

Reads the data from Lua.
source§

fn lua_read_at_maybe_zero_position( lua: L, index: i32 ) -> Result<Self, (L, WrongType)>
where L: AsLua,

source§

impl PartialEq for Vclock

source§

fn eq(&self, other: &Vclock) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for Vclock

source§

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 lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<L: AsLua> Push<L> for Vclock

§

type Err = Void

Error that can happen when pushing a value.
source§

fn push_to_lua(&self, lua: L) -> Result<PushGuard<L>, (Self::Err, L)>

Pushes the value on the top of the stack. Read more
source§

fn push_no_err(&self, lua: L) -> PushGuard<L>
where Self::Err: Into<Void>,

Same as push_to_lua but can only succeed and is only available if Err implements Into<Void>.
source§

impl<L: AsLua> PushInto<L> for Vclock

§

type Err = Void

source§

fn push_into_lua(self, lua: L) -> Result<PushGuard<L>, (Self::Err, L)>

Push the value into lua by value
source§

fn push_into_no_err(self, lua: L) -> PushGuard<L>
where Self: Sized, Self::Err: Into<Void>,

Same as push_into_lua but can only succeed and is only available if Err implements Into<Void>.
source§

impl Serialize for Vclock

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Eq for Vclock

source§

impl<L: AsLua> PushOne<L> for Vclock

source§

impl<L: AsLua> PushOneInto<L> for Vclock

source§

impl StructuralEq for Vclock

source§

impl StructuralPartialEq for Vclock

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<'de, T> Decode<'de> for T
where T: Deserialize<'de>,

source§

fn decode(data: &'de [u8]) -> Result<T, Error>

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoClones<(T,)> for T
where T: Clone,

source§

impl<T> IntoClones<(T, T)> for T
where T: Clone,

source§

impl<T> IntoClones<(T, T, T)> for T
where T: Clone,

source§

impl<T> IntoClones<(T, T, T, T)> for T
where T: Clone,

source§

impl<T> IntoClones<(T, T, T, T, T)> for T
where T: Clone,

source§

impl<T> IntoClones<(T, T, T, T, T, T)> for T
where T: Clone,

source§

impl<T> IntoClones<(T, T, T, T, T, T, T)> for T
where T: Clone,

source§

impl<T> IntoClones<(T, T, T, T, T, T, T, T)> for T
where T: Clone,

source§

impl<T> IntoClones<(T, T, T, T, T, T, T, T, T)> for T
where T: Clone,

source§

impl<T> IntoClones<(T, T, T, T, T, T, T, T, T, T)> for T
where T: Clone,

source§

impl<T> IntoClones<(T, T, T, T, T, T, T, T, T, T, T)> for T
where T: Clone,

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DecodeOwned for T
where T: for<'de> Decode<'de>,

source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,