Crate grafos_fence

Crate grafos_fence 

Source
Expand description

Typed epoch/fencing helpers for stale-write rejection and leader fencing.

This crate provides lightweight primitives for tracking monotonic epochs and rejecting operations that carry a stale generation number. No I/O, no_std compatible.

§Core types

TypePurpose
FenceEpochMonotonic epoch counter
Fenced<T>A value tagged with the epoch it was produced in
FenceGuardStateful checker that rejects stale epochs
StaleEpochErrorError returned when an epoch is behind the current one

§Quick start

use grafos_fence::{FenceEpoch, Fenced, FenceGuard};

let mut guard = FenceGuard::new(FenceEpoch::zero());

// First write at epoch 0 — accepted
let msg = Fenced::at_zero("hello");
assert!(guard.check(msg.epoch()).is_ok());

// Leader failover bumps the epoch
let new_epoch = guard.advance();

// Old-epoch write is now rejected
assert!(guard.check(msg.epoch()).is_err());

// New-epoch write succeeds
let msg2 = Fenced::new(new_epoch, "world");
assert!(guard.check(msg2.epoch()).is_ok());

Structs§

FenceEpoch
A monotonic epoch counter used for fencing stale operations.
FenceGuard
A stateful epoch checker that rejects operations with stale epochs.
Fenced
A value tagged with the epoch in which it was produced.
StaleEpochError
Error returned when an incoming epoch is behind the expected epoch.

Functions§

bump_epoch
Free function: returns an epoch one greater than old.