Struct openraft::Membership

source ·
pub struct Membership<NID, N>
where N: Node, NID: NodeId,
{ /* private fields */ }
Expand description

The membership configuration of the cluster.

It could be a joint of one, two or more configs, i.e., a quorum is a node set that is superset of a majority of every config.

Implementations§

source§

impl<NID, N> Membership<NID, N>
where N: Node, NID: NodeId,

source

pub fn new<T>(config: Vec<BTreeSet<NID>>, nodes: T) -> Self
where T: IntoNodes<NID, N>,

Create a new Membership from a joint config of voter-ids and a collection of all Node(voter nodes and learner nodes).

A node id that is in nodes but is not in config is a learner.

A node presents in config but not in nodes is filled with default value.

The nodes can be:

  • a simple (), if there are no learner nodes,
  • BTreeSet<NodeId> provides learner node ids whose Node data are Node::default(),
  • BTreeMap<NodeId, Node> provides nodes for every node id. Node ids that are not in configs are learners.
source

pub fn is_in_joint_consensus(&self) -> bool

👎Deprecated since 0.8.4: use get_joint_config().len() > 1 instead

Check to see if the config is currently in joint consensus.

source

pub fn get_joint_config(&self) -> &Vec<BTreeSet<NID>>

Returns reference to the joint config.

Membership is defined by a joint of multiple configs. Each config is a vec of node-id.

The returned Vec contains one or more configs(currently it is two). If there is only one config, it is in a uniform config, otherwise, it is in a joint consensus.

source

pub fn nodes(&self) -> impl Iterator<Item = (&NID, &N)>

Returns an Iterator of all nodes(voters and learners).

source

pub fn get_node(&self, node_id: &NID) -> Option<&N>

Get a the node(either voter or learner) by node id.

source

pub fn voter_ids(&self) -> impl Iterator<Item = NID>

Returns an Iterator of all voter node ids. Learners are not included.

source

pub fn learner_ids(&self) -> impl Iterator<Item = NID> + '_

Returns an Iterator of all learner node ids. Voters are not included.

Trait Implementations§

source§

impl<NID, N> Clone for Membership<NID, N>
where N: Node + Clone, NID: NodeId + Clone,

source§

fn clone(&self) -> Membership<NID, N>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<NID, N> Debug for Membership<NID, N>
where N: Node + Debug, NID: NodeId + Debug,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<NID, N> Default for Membership<NID, N>
where N: Node + Default, NID: NodeId + Default,

source§

fn default() -> Membership<NID, N>

Returns the “default value” for a type. Read more
source§

impl<'de, NID, N> Deserialize<'de> for Membership<NID, N>
where N: Node, NID: NodeId,

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<NID, N> Display for Membership<NID, N>
where N: Node, NID: NodeId,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<NID, N> From<BTreeMap<NID, N>> for Membership<NID, N>
where N: Node, NID: NodeId,

source§

fn from(b: BTreeMap<NID, N>) -> Self

Converts to this type from the input type.
source§

impl<NID, N> MessageSummary<Membership<NID, N>> for Membership<NID, N>
where N: Node, NID: NodeId,

source§

fn summary(&self) -> String

Return a string of a big message
source§

impl<NID, N> PartialEq for Membership<NID, N>
where N: Node + PartialEq, NID: NodeId + PartialEq,

source§

fn eq(&self, other: &Membership<NID, N>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<NID, N> Serialize for Membership<NID, N>
where N: Node, NID: NodeId,

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<NID, N> Eq for Membership<NID, N>
where N: Node + Eq, NID: NodeId + Eq,

source§

impl<NID, N> StructuralPartialEq for Membership<NID, N>
where N: Node, NID: NodeId,

Auto Trait Implementations§

§

impl<NID, N> Freeze for Membership<NID, N>

§

impl<NID, N> RefUnwindSafe for Membership<NID, N>

§

impl<NID, N> Send for Membership<NID, N>

§

impl<NID, N> Sync for Membership<NID, N>

§

impl<NID, N> Unpin for Membership<NID, N>

§

impl<NID, N> UnwindSafe for Membership<NID, N>

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> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

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>,

§

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.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T> AppData for T
where T: OptionalSend + OptionalSync + 'static + OptionalSerde,

source§

impl<T> AppDataResponse for T
where T: OptionalSend + OptionalSync + 'static + OptionalSerde,

source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

source§

impl<T> Node for T
where T: NodeEssential + Serialize + for<'a> Deserialize<'a>,

source§

impl<T> OptionalSend for T
where T: Send + ?Sized,

source§

impl<T> OptionalSync for T
where T: Sync + ?Sized,