pub struct FencingToken(pub u64);Expand description
A packed monotonically increasing fencing token that uniquely identifies a write epoch.
Encoded as a single u64:
- High 32 bits = Raft term (capped at
u32::MAXfor compactness; terms exceedingu32::MAXare exceedingly unlikely in any realistic deployment). - Low 32 bits = per-term monotonic sequence number.
Each time a node becomes leader it resets the sequence to zero and bumps the term
component via FencingToken::new_leader_term. Storage backends and followers use
the token to reject stale writes from former leaders: a write is stale when its
token’s term is less than the current term, or the term matches but the sequence
has been superseded by a higher-sequence write in the same term.
§Format
[term: 32 bits][seq: 32 bits]Tuple Fields§
§0: u64Implementations§
Source§impl FencingToken
impl FencingToken
Sourcepub fn bump_seq(self) -> Self
pub fn bump_seq(self) -> Self
Return a new token with the sequence number incremented by one, keeping the term unchanged.
Wraps on u32 overflow (extremely unlikely in practice).
Sourcepub fn new_leader_term(term: u32) -> Self
pub fn new_leader_term(term: u32) -> Self
Return a fresh token for a new leader term; the sequence number resets to 0.
Trait Implementations§
Source§impl Clone for FencingToken
impl Clone for FencingToken
Source§fn clone(&self) -> FencingToken
fn clone(&self) -> FencingToken
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for FencingToken
impl Debug for FencingToken
Source§impl Default for FencingToken
impl Default for FencingToken
Source§fn default() -> FencingToken
fn default() -> FencingToken
Returns the “default value” for a type. Read more
Source§impl Hash for FencingToken
impl Hash for FencingToken
Source§impl Ord for FencingToken
impl Ord for FencingToken
Source§fn cmp(&self, other: &FencingToken) -> Ordering
fn cmp(&self, other: &FencingToken) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl PartialEq for FencingToken
impl PartialEq for FencingToken
Source§impl PartialOrd for FencingToken
impl PartialOrd for FencingToken
impl Copy for FencingToken
impl Eq for FencingToken
impl StructuralPartialEq for FencingToken
Auto Trait Implementations§
impl Freeze for FencingToken
impl RefUnwindSafe for FencingToken
impl Send for FencingToken
impl Sync for FencingToken
impl Unpin for FencingToken
impl UnsafeUnpin for FencingToken
impl UnwindSafe for FencingToken
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more