foundationdb::recipes::ranked_register

Struct RankedRegister

Source
pub struct RankedRegister { /* private fields */ }
Expand description

A ranked register backed by FoundationDB

Provides a mutable register with conflict detection via ranks. No initialization is needed — an absent key represents the bottom state (zero ranks, no value).

§Thread Safety

RankedRegister is Clone, Send, and Sync. It holds only a Subspace and can be safely shared across tasks.

Implementations§

Source§

impl RankedRegister

Source

pub fn new(subspace: Subspace) -> Self

Create a new ranked register instance

The subspace isolates this register from other data in the database. No initialization step is required — the register starts in the bottom state (zero ranks, no value) until the first write.

Source

pub fn with_max_value_bytes(subspace: Subspace, limit: usize) -> Self

Create a ranked register with a local aggregate value-size limit.

The limit applies only to writes through this handle. It is not durable state, so use compatible limits for all writers of the same subspace.

Source

pub fn subspace(&self) -> &Subspace

Returns a reference to the underlying subspace

Source

pub async fn read<T>(&self, txn: &T, rank: Rank) -> Result<ReadResult>
where T: Deref<Target = Transaction>,

Perform a ranked read

Raises max_read_rank only when the given rank is higher, installing a fence that prevents lower-ranked writes. A superseded rank returns the current write rank and value without changing the installed fence.

Used by the leader before writing to ensure consistency.

Source

pub async fn write<T>( &self, txn: &T, rank: Rank, value: &[u8], ) -> Result<WriteResult>
where T: Deref<Target = Transaction>,

Perform a ranked write

Commits the value only if:

  • rank >= max_read_rank (no higher fence)
  • rank > max_write_rank (no equal-or-higher write)

Returns WriteResult::Committed or WriteResult::Aborted. Returns RankedRegisterError::ValueTooLarge when this handle has a configured limit and value exceeds it.

Source

pub async fn value<T>(&self, txn: &T) -> Result<Option<Vec<u8>>>
where T: Deref<Target = Transaction>,

Read the current value without updating ranks

Safe for followers and observers: it installs no durable fence. Its normal non-snapshot FoundationDB read still adds a conflict range for this register key, so it can conflict with a concurrent leader write.

Trait Implementations§

Source§

impl Clone for RankedRegister

Source§

fn clone(&self) -> RankedRegister

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 RankedRegister

Source§

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

Formats the value using the given formatter. Read more

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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
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> ToOwned for T
where T: Clone,

Source§

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

Source§

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

Source§

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.