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 Versionstamps 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

Creates a complete Versionstamp instance with the given transaction and user versions.

Panic

Panics if the length of the transaction version is incorrect.

Creates a value of Versionstamp type based on the given byte array.

Panic

Panics if the length of the byte array is incorrect.

Creates an incomplete Versionstamp instance with the given user version.

Retrieve a byte representation of this Versionstamp.

Retrieve the portion of this Versionstamp that is set by the database.

Retrieve the portion of this Versionstamp that is set by the user.

Whether this Versionstamp’s transaction version is meaningful.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

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

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

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

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

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.