pub struct FabricBarrier { /* private fields */ }Expand description
Distributed barrier backed by a fabric memory lease.
All num_parties participants must call wait
before any of them proceed. After all parties arrive, the generation
counter increments and the barrier resets for reuse across successive
synchronization rounds.
If a party crashes, the lease eventually expires and remaining parties
will observe a timeout (FabricError::LeaseExpired).
§Example
use grafos_sync::FabricBarrier;
use grafos_std::mem::MemBuilder;
let lease = MemBuilder::new().acquire().unwrap();
let barrier = FabricBarrier::new(lease, 0, 1).unwrap();
// With 1 party, wait() completes immediately
let gen = barrier.wait(10).unwrap();
assert_eq!(gen, 1);Implementations§
Source§impl FabricBarrier
impl FabricBarrier
Sourcepub fn new(lease: MemLease, base_offset: u64, num_parties: u32) -> Result<Self>
pub fn new(lease: MemLease, base_offset: u64, num_parties: u32) -> Result<Self>
Create a new barrier for num_parties participants.
Initializes the barrier state in leased memory at base_offset.
Sourcepub fn wait(&self, max_polls: u32) -> Result<u64>
pub fn wait(&self, max_polls: u32) -> Result<u64>
Wait at the barrier.
Increments the arrival count. If this is the last party to arrive, the generation is incremented and the count is reset to zero. Otherwise, polls until the generation changes, indicating all parties have arrived.
Returns the new generation number on success.
max_polls limits how many polling iterations before returning
FabricError::LeaseExpired.
Sourcepub fn generation(&self) -> Result<u64>
pub fn generation(&self) -> Result<u64>
Read the current generation counter.
The generation starts at 0 and increments by one each time all
num_parties have arrived and the barrier completes a round.
Sourcepub fn lease_id(&self) -> u128
pub fn lease_id(&self) -> u128
Returns the lease ID of the underlying memory lease for external
renewal management (e.g. via [grafos_leasekit::RenewalManager]).
Sourcepub fn expires_at_unix_secs(&self) -> u64
pub fn expires_at_unix_secs(&self) -> u64
Returns the expiry time (unix seconds) of the underlying memory lease for external renewal management.