FabricBarrier

Struct FabricBarrier 

Source
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

Source

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.

Source

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.

Source

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.

Source

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]).

Source

pub fn expires_at_unix_secs(&self) -> u64

Returns the expiry time (unix seconds) of the underlying memory lease for external renewal management.

Source

pub fn count(&self) -> Result<u64>

Read the current arrival count.

Returns the number of parties that have called wait in the current generation. Resets to 0 when the last party arrives and the generation advances.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.