pub struct RepGroup { /* private fields */ }Expand description
A replication group consisting of named nodes.
The group tracks its members and provides queries for electable nodes, monitors, quorum size, etc. Each node in the group has a unique name.
Implementations§
Source§impl RepGroup
impl RepGroup
Sourcepub fn new(name: String, group_id: u64) -> Self
pub fn new(name: String, group_id: u64) -> Self
Creates a new replication group with the given name and ID.
Defaults to QuorumPolicy::SimpleMajority. Use
RepGroup::with_policy to specify a Flexible or Expression policy.
Sourcepub fn with_policy(name: String, group_id: u64, policy: QuorumPolicy) -> Self
pub fn with_policy(name: String, group_id: u64, policy: QuorumPolicy) -> Self
Creates a new replication group with an explicit quorum policy.
Sourcepub fn set_quorum_policy(&mut self, policy: QuorumPolicy)
pub fn set_quorum_policy(&mut self, policy: QuorumPolicy)
Replace the quorum policy for this group.
Sourcepub fn quorum_policy(&self) -> &QuorumPolicy
pub fn quorum_policy(&self) -> &QuorumPolicy
Returns a reference to the current quorum policy.
Sourcepub fn add_node(&mut self, node: RepNode) -> Option<RepNode>
pub fn add_node(&mut self, node: RepNode) -> Option<RepNode>
Adds a node to the group. Returns the previous node with the same name, if any.
Sourcepub fn remove_node(&mut self, name: &str) -> Option<RepNode>
pub fn remove_node(&mut self, name: &str) -> Option<RepNode>
Removes a node from the group by name. Returns the removed node, if it existed.
Sourcepub fn get_node(&self, name: &str) -> Option<&RepNode>
pub fn get_node(&self, name: &str) -> Option<&RepNode>
Returns a reference to the node with the given name, if present.
Sourcepub fn get_electable_nodes(&self) -> Vec<&RepNode>
pub fn get_electable_nodes(&self) -> Vec<&RepNode>
Returns all electable nodes (those that participate in elections).
Sourcepub fn get_monitors(&self) -> Vec<&RepNode>
pub fn get_monitors(&self) -> Vec<&RepNode>
Returns all monitor nodes.
Sourcepub fn electable_count(&self) -> u32
pub fn electable_count(&self) -> u32
Returns the number of electable nodes in the group.
Sourcepub fn phase1_quorum(&self) -> usize
pub fn phase1_quorum(&self) -> usize
Returns the Phase 1 (Prepare/Promise) quorum size under the current policy.
Sourcepub fn phase2_quorum(&self) -> usize
pub fn phase2_quorum(&self) -> usize
Returns the Phase 2 (Accept/Commit) quorum size under the current policy.
Sourcepub fn is_valid_phase2_quorum(&self, voters: &HashSet<&str>) -> bool
pub fn is_valid_phase2_quorum(&self, voters: &HashSet<&str>) -> bool
Returns true if voters satisfies the Phase 2 quorum requirement.
Sourcepub fn rebuild_quorum_system(&self) -> Result<(), String>
pub fn rebuild_quorum_system(&self) -> Result<(), String>
Validate and optionally rebuild the quorum system after a membership
change. For SimpleMajority and Expression policies this is always
valid; for Flexible it checks phase1 + phase2 > n.
Returns Err if the current policy is unsafe for the new group size.
Sourcepub fn quorum_size(&self) -> u32
pub fn quorum_size(&self) -> u32
Returns the phase-2 quorum size for the configured quorum policy.
This is a compatibility shim that returns
phase2_quorum cast to u32. The result is
policy-dependent: under the default Majority policy this is a
simple majority of electable nodes, but under Flexible or
Expression policies it may be larger or smaller than a simple
majority. New code should call phase2_quorum
directly.
Sourcepub fn contains_node(&self, name: &str) -> bool
pub fn contains_node(&self, name: &str) -> bool
Returns true if the group contains a node with the given name.
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Returns the total number of nodes in the group.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for RepGroup
impl RefUnwindSafe for RepGroup
impl Send for RepGroup
impl Sync for RepGroup
impl Unpin for RepGroup
impl UnsafeUnpin for RepGroup
impl UnwindSafe for RepGroup
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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