pub struct InMemoryGroup { /* private fields */ }Expand description
An n-node fully-connected in-memory replication mesh.
InMemoryGroup owns one InMemoryEndpoint per ordered
(from, to) peer pair (with from != to). The endpoint at
(from, to) is from’s view of its socket to to; sending on
that endpoint is observed by the endpoint at (to, from).
Higher layers typically consume the group by handing each node
the row of channels [group.channel(my_id, peer)] for peer in 0..n.
§Crash and recovery
InMemoryGroup::simulate_crash closes every channel touching a
node, modelling a hard crash or partition. After a crash,
InMemoryGroup::reconnect rewires that node’s row of channels
(paired against the other live nodes) to model a node restart or
healed partition. A crashed node may be reconnected at most once
per crash; the implementation tolerates repeated calls.
Implementations§
Source§impl InMemoryGroup
impl InMemoryGroup
Sourcepub fn channel(&self, from: usize, to: usize) -> Arc<dyn Channel> ⓘ
pub fn channel(&self, from: usize, to: usize) -> Arc<dyn Channel> ⓘ
Return a cheap Arc<dyn Channel> handle to the directed
channel from from to to.
§Panics
Panics if from or to is out of range, if from == to, or
if the channel has been removed by Self::simulate_crash
without a subsequent Self::reconnect.
Sourcepub fn try_channel(&self, from: usize, to: usize) -> Option<Arc<dyn Channel>>
pub fn try_channel(&self, from: usize, to: usize) -> Option<Arc<dyn Channel>>
Try to acquire the directed channel from from to to,
returning None if the channel has been crashed.
§Panics
Panics on out-of-range indices or from == to.
Sourcepub fn simulate_crash(&self, node: usize)
pub fn simulate_crash(&self, node: usize)
Simulate a hard crash of node: every channel originating
from or terminating at node is closed and dropped from the
mesh. Subsequent send / receive on any handle that was
previously cloned out of those channels returns
crate::error::RepError::ChannelClosed, matching a real
socket disconnect.
Idempotent: calling simulate_crash on an already-crashed
node is a no-op.
§Panics
Panics if node is out of range.
Sourcepub fn reconnect(&self, node: usize)
pub fn reconnect(&self, node: usize)
Rewire node’s row of channels against every peer that is
still live (i.e., still has a channel slot to node). Models
a node restart or a healed partition.
Channels whose remote end is itself currently crashed are left disconnected; the caller should reconnect them in a separate pass once the remote node has come back.
§Panics
Panics if node is out of range.
Sourcepub fn is_node_live(&self, node: usize) -> bool
pub fn is_node_live(&self, node: usize) -> bool
Return true iff every directed channel touching node is
currently open.
Auto Trait Implementations§
impl !RefUnwindSafe for InMemoryGroup
impl !UnwindSafe for InMemoryGroup
impl Freeze for InMemoryGroup
impl Send for InMemoryGroup
impl Sync for InMemoryGroup
impl Unpin for InMemoryGroup
impl UnsafeUnpin for InMemoryGroup
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more