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 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
Updates max_read_rank if the given rank is higher, installing a fence
that prevents lower-ranked writes. Returns the current write rank and value.
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.
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