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
| Type | Purpose |
|---|---|
FenceEpoch | Monotonic epoch counter |
Fenced<T> | A value tagged with the epoch it was produced in |
FenceGuard | Stateful checker that rejects stale epochs |
StaleEpochError | Error 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§
- Fence
Epoch - A monotonic epoch counter used for fencing stale operations.
- Fence
Guard - A stateful epoch checker that rejects operations with stale epochs.
- Fenced
- A value tagged with the epoch in which it was produced.
- Stale
Epoch Error - Error returned when an incoming epoch is behind the expected epoch.
Functions§
- bump_
epoch - Free function: returns an epoch one greater than
old.