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
impl RankedRegister
Sourcepub fn new(subspace: Subspace) -> Self
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.
Sourcepub fn with_max_value_bytes(subspace: Subspace, limit: usize) -> Self
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.
Sourcepub async fn read<T>(&self, txn: &T, rank: Rank) -> Result<ReadResult>where
T: Deref<Target = Transaction>,
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.
Sourcepub async fn write<T>(
&self,
txn: &T,
rank: Rank,
value: &[u8],
) -> Result<WriteResult>where
T: Deref<Target = Transaction>,
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.
Sourcepub async fn value<T>(&self, txn: &T) -> Result<Option<Vec<u8>>>where
T: Deref<Target = Transaction>,
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
impl Clone for RankedRegister
Source§fn clone(&self) -> RankedRegister
fn clone(&self) -> RankedRegister
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more