Skip to main content

PeerDirectory

Struct PeerDirectory 

Source
pub struct PeerDirectory { /* private fields */ }
Expand description

The mapped peer directory in any of the three locales.

Implementations§

Source§

impl PeerDirectory

Source

pub fn create_anon() -> Result<Self, RingError>

Anonymous in-process directory (the Anon ring locale).

Source

pub fn create(path: impl AsRef<Path>) -> Result<Self, RingError>

File-backed directory at path, initialized by the creator. Obtain the file-backed directory at path, initializing it only if it does not yet exist. Attaching leaves live claims in place; use reset to deliberately wipe them.

Source

pub fn reset(path: impl AsRef<Path>) -> Result<Self, RingError>

Reinitialise the directory at path, discarding every claim a live peer holds. For a caller that knows it owns the path.

Source

pub fn open(path: impl AsRef<Path>) -> Result<Self, RingError>

Open an existing file-backed directory; validates the magic and never re-initialises (live claims survive the attach).

Source

pub fn create_or_open_shm(name: &str) -> Result<Self, RingError>

Named-shm directory. create_or_open semantics: the region is initialized only when its magic is absent, so racing attachers never wipe live claims.

Source

pub fn epoch(&self) -> u64

Current topology epoch. Hot paths compare this against a process-local cache; equality means nothing changed.

Source

pub fn bump_epoch(&self) -> u64

Bump the topology epoch (any peer / publication change).

Source

pub fn published(&self) -> usize

Ring backings published (files exist + initialized).

Source

pub fn publish_rings(&self, to: usize)

Advance the published-ring count to to after creating the backing files for every slot below it. Monotone max, so concurrent growers publishing different highs converge.

Source

pub fn active_producers(&self) -> usize

Live producer count across all attached processes.

Source

pub fn active_consumers(&self) -> usize

Live consumer count across all attached processes.

Source

pub fn claim_producer_slot(&self) -> Option<usize>

Claim the lowest free producer slot. None only at the substrate ceiling (PRODUCER_SLOT_CEILING CONCURRENT producers).

Source

pub fn release_producer_slot(&self, slot: usize)

Release a producer slot claimed by claim_producer_slot.

Source

pub fn reap_dead_peers(&self)

Release every peer slot whose recorded process is gone (crashed / exited without unregistering). Called from the topology sync SLOW path only - it probes at most one pid per claimed slot. Rings owned by reaped consumer slots become claimable via the normal takeover / claim paths.

Source

pub fn claim_consumer_slot(&self) -> Option<usize>

Claim the lowest free consumer slot, recording the claiming process id for the crash-takeover liveness probe.

Source

pub fn release_consumer_slot(&self, slot: usize)

Release a consumer slot. The caller transfers its ring ownership out FIRST (it is the single owner, so direct owner writes are safe), then releases.

Source

pub fn consumer_slot_claimed(&self, slot: usize) -> bool

Whether slot currently holds a consumer claim.

Source

pub fn claimed_consumer_slots(&self) -> Vec<u16>

Dense list of currently-claimed consumer slots (rebalance input). Snapshot semantics: claims racing the scan are picked up by the next epoch-triggered rebalance.

Source

pub fn ring_owner(&self, ring: usize) -> (u16, u16)

(owner, pending) for one ring’s owner-table entry.

Source

pub fn try_claim_ring(&self, ring: usize, me: u16) -> bool

CAS-claim an unowned ring for me. The only ownership entry point that does not go through the current owner, and it requires owner == OWNER_NONE, so the single-reader invariant holds by construction.

Source

pub fn request_handoff(&self, ring: usize, target: u16)

Request that ring move to target. The CURRENT owner applies the handoff on its next scan (Self::apply_handoff); until then it keeps draining, so no items strand.

Source

pub fn apply_handoff(&self, ring: usize, me: u16) -> Option<u16>

Owner-side handoff: if me owns ring and a handoff is pending, transfer ownership and return the new owner. Called from the owner’s own pop scan - the single-writer transfer.

Source

pub fn transfer_ring(&self, ring: usize, me: u16, to: u16)

Direct ownership transfer by the CURRENT owner (unregister path: the leaving consumer parcels its rings out itself).

Source

pub fn try_takeover(&self, ring: usize, dead_owner: u16, me: u16) -> bool

Crash takeover: steal ring from dead_owner only when that slot is unclaimed OR its recorded process is gone. Both cases preclude a concurrent pop by the old owner, preserving the single-reader invariant. An alive-but-idle owner is never stolen from.

Trait Implementations§

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.