Struct fdb::tuple::Versionstamp
source · [−]pub struct Versionstamp { /* private fields */ }
Expand description
Used to represent values written by versionstamp operations with a
Tuple
.
Versionstamp
contains twelve bytes. The first ten bytes are
the “transaction” version, and they are usually assigned by the
database in such a way that all transactions receive a different
version that is consistent with a serialization order of the
transactions within the database (One can use the
get_versionstamp
method to retrieve this version from a
Transaction
). This also implies that the transaction version
of newly committed transactions will be monotonically increasing
over time. The final two bytes are the “user” version and should
be set by the client. This allows the user to use this type to
impose a total order of items across multiple transactions in the
database in a consistent and conflict-free way.
All Versionstamp
s can exist in one of two states: “incomplete”
and “complete”. An “incomplete” Versionstamp
is a Versionstamp
that has not been initialized with a meaningful transaction
version. For example, this might be used with a Versionstamp
that
one wants to fill in with the current transaction’s version
information. A “complete” Versionstamp
, in contradistinction, is
one that has been assigned a meaningful transaction version. This
is usually the case if one is reading back a Versionstamp from the
database.
Example usage might be to do something like the following:
let tr_version = fdb_database
.run(|tr| async move {
let t = {
let mut tup = Tuple::new();
tup.add_string(String::from("prefix"));
tup.add_versionstamp(Versionstamp::incomplete(0));
tup
};
unsafe {
tr.mutate(
MutationType::SetVersionstampedKey,
t.pack_with_versionstamp(Bytes::new())?,
Bytes::new(),
);
}
Ok(unsafe { tr.get_versionstamp() })
})
.await?
.get()
.await?;
let vs = fdb_database
.run(|tr| async move {
let subspace = Subspace::new(Bytes::new()).subspace(&{
let mut tup = Tuple::new();
tup.add_string("prefix".to_string());
tup
});
let subspace_range = subspace.range(&Tuple::new());
let key = subspace_range
.into_stream(&tr, RangeOptions::default())
.take(1)
.next()
.await
.unwrap()?
.into_key();
Ok(subspace
.unpack(&key.into())?
.get_versionstamp_ref(0)?
.clone())
})
.await?;
assert_eq!(vs, Versionstamp::complete(tr_version, 0));
Here, an incomplete Versionstamp
is packed and written to the
database with SetVersionstampedKey
mutation type.
After committing, we then attempt to read back the same key that
we just wrote. Then we verify the invariant that the deserialized
Versionstamp
is the same as a complete Versionstamp
value
created from the first transaction’s version information.
Implementations
sourceimpl Versionstamp
impl Versionstamp
sourcepub fn complete(tr_version: Bytes, user_version: u16) -> Versionstamp
pub fn complete(tr_version: Bytes, user_version: u16) -> Versionstamp
Creates a complete Versionstamp
instance with the given
transaction and user versions.
Panic
Panics if the length of the transaction version is incorrect.
sourcepub fn from_bytes(version_bytes: Bytes) -> Versionstamp
pub fn from_bytes(version_bytes: Bytes) -> Versionstamp
Creates a value of Versionstamp
type based on the given
byte array.
Panic
Panics if the length of the byte array is incorrect.
sourcepub fn incomplete(user_version: u16) -> Versionstamp
pub fn incomplete(user_version: u16) -> Versionstamp
Creates an incomplete Versionstamp
instance with the given
user version.
sourcepub fn get_bytes(&self) -> Bytes
pub fn get_bytes(&self) -> Bytes
Retrieve a byte representation of this Versionstamp
.
sourcepub fn get_transaction_version(&self) -> Bytes
pub fn get_transaction_version(&self) -> Bytes
Retrieve the portion of this Versionstamp
that is set by
the database.
sourcepub fn get_user_version(&self) -> u16
pub fn get_user_version(&self) -> u16
Retrieve the portion of this Versionstamp
that is set by
the user.
sourcepub fn is_complete(&self) -> bool
pub fn is_complete(&self) -> bool
Whether this Versionstamp
’s transaction version is
meaningful.
Trait Implementations
sourceimpl Clone for Versionstamp
impl Clone for Versionstamp
sourcefn clone(&self) -> Versionstamp
fn clone(&self) -> Versionstamp
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for Versionstamp
impl Debug for Versionstamp
sourceimpl Ord for Versionstamp
impl Ord for Versionstamp
sourceimpl PartialEq<Versionstamp> for Versionstamp
impl PartialEq<Versionstamp> for Versionstamp
sourcefn eq(&self, other: &Versionstamp) -> bool
fn eq(&self, other: &Versionstamp) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &Versionstamp) -> bool
fn ne(&self, other: &Versionstamp) -> bool
This method tests for !=
.
sourceimpl PartialOrd<Versionstamp> for Versionstamp
impl PartialOrd<Versionstamp> for Versionstamp
sourcefn partial_cmp(&self, other: &Versionstamp) -> Option<Ordering>
fn partial_cmp(&self, other: &Versionstamp) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
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 · sourcefn le(&self, other: &Rhs) -> bool
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
impl Eq for Versionstamp
impl StructuralEq for Versionstamp
impl StructuralPartialEq for Versionstamp
Auto Trait Implementations
impl RefUnwindSafe for Versionstamp
impl Send for Versionstamp
impl Sync for Versionstamp
impl Unpin for Versionstamp
impl UnwindSafe for Versionstamp
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more