pub struct PeerDirectory { /* private fields */ }Expand description
The mapped peer directory in any of the three locales.
Implementations§
Source§impl PeerDirectory
impl PeerDirectory
Sourcepub fn create_anon() -> Result<Self, RingError>
pub fn create_anon() -> Result<Self, RingError>
Anonymous in-process directory (the Anon ring locale).
Sourcepub fn create(path: impl AsRef<Path>) -> Result<Self, RingError>
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.
Sourcepub fn reset(path: impl AsRef<Path>) -> Result<Self, RingError>
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.
Sourcepub fn open(path: impl AsRef<Path>) -> Result<Self, RingError>
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).
Sourcepub fn create_or_open_shm(name: &str) -> Result<Self, RingError>
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.
Sourcepub fn epoch(&self) -> u64
pub fn epoch(&self) -> u64
Current topology epoch. Hot paths compare this against a process-local cache; equality means nothing changed.
Sourcepub fn bump_epoch(&self) -> u64
pub fn bump_epoch(&self) -> u64
Bump the topology epoch (any peer / publication change).
Sourcepub fn publish_rings(&self, to: usize)
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.
Sourcepub fn active_producers(&self) -> usize
pub fn active_producers(&self) -> usize
Live producer count across all attached processes.
Sourcepub fn active_consumers(&self) -> usize
pub fn active_consumers(&self) -> usize
Live consumer count across all attached processes.
Sourcepub fn claim_producer_slot(&self) -> Option<usize>
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).
Sourcepub fn release_producer_slot(&self, slot: usize)
pub fn release_producer_slot(&self, slot: usize)
Release a producer slot claimed by
claim_producer_slot.
Sourcepub fn reap_dead_peers(&self)
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.
Sourcepub fn claim_consumer_slot(&self) -> Option<usize>
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.
Sourcepub fn release_consumer_slot(&self, slot: usize)
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.
Sourcepub fn consumer_slot_claimed(&self, slot: usize) -> bool
pub fn consumer_slot_claimed(&self, slot: usize) -> bool
Whether slot currently holds a consumer claim.
Sourcepub fn claimed_consumer_slots(&self) -> Vec<u16>
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.
Sourcepub fn ring_owner(&self, ring: usize) -> (u16, u16)
pub fn ring_owner(&self, ring: usize) -> (u16, u16)
(owner, pending) for one ring’s owner-table entry.
Sourcepub fn try_claim_ring(&self, ring: usize, me: u16) -> bool
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.
Sourcepub fn request_handoff(&self, ring: usize, target: u16)
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.
Sourcepub fn apply_handoff(&self, ring: usize, me: u16) -> Option<u16>
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.
Sourcepub fn transfer_ring(&self, ring: usize, me: u16, to: u16)
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).
Sourcepub fn try_takeover(&self, ring: usize, dead_owner: u16, me: u16) -> bool
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.