Skip to main content

RaftControlPlane

Struct RaftControlPlane 

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

An openraft-based control plane.

Implementations§

Source§

impl RaftControlPlane

Source

pub async fn start_single_node( node_id: NodeId, dir: impl AsRef<Path>, ) -> Result<Self, ControlError>

Starts a single-node Raft control plane.

Two redb files live under dir: sm.redb (the state machine) and log.redb (the Raft log) — both the state machine and the log are persisted, so the whole control plane is self-contained and recoverable after a crash.

Source

pub async fn start_cluster_node( node_id: NodeId, dir: impl AsRef<Path>, http_addr: impl Into<String>, ) -> Result<Self, ControlError>

Starts a cluster node: the HTTP network plus its own HTTP server (exposing the Raft RPC and /cluster/join).

  • dir: the directory for the redb state machine + log.
  • http_addr: the address this node binds and advertises (e.g. 127.0.0.1:7001), i.e. the address that identifies it within the cluster.
Source

pub async fn start_cluster_node_with( node_id: NodeId, dir: impl AsRef<Path>, http_addr: impl Into<String>, tuning: RaftTuning, ) -> Result<Self, ControlError>

Same as start_cluster_node, but with customizable Raft timing (RaftTuning) for high-latency / wide-area clusters.

Source

pub async fn init_cluster( &self, members: BTreeMap<NodeId, String>, ) -> Result<(), ControlError>

Initializes a new cluster (the given {id: addr} becomes the initial voting set; normally called exactly once, on the first core node).

Source

pub async fn add_learner( &self, node_id: NodeId, addr: impl Into<String>, ) -> Result<(), ControlError>

Adds a node as a learner (plan A: a worker starts out as a learner).

Source

pub async fn change_membership( &self, voters: BTreeSet<NodeId>, ) -> Result<(), ControlError>

Changes the voting membership (plan A: a small voting core of 3~5; learners/workers are unaffected).

Source

pub async fn join_cluster( seed_addr: &str, node_id: NodeId, my_addr: &str, ) -> Result<(), ControlError>

Sends a join request from this node to a seed node (adding itself to the cluster as a learner). “Register against any node to join”: seed_addr is the address of any known node in the cluster (it should be the current leader).

Source

pub fn raft(&self) -> &MocraRaft

The underlying openraft handle (membership changes / status queries).

Source

pub fn members(&self) -> Vec<(NodeId, String)>

All members currently configured in the cluster (voters + learners) and their addresses.

Based on the Raft membership configuration (strongly consistent) rather than live liveness probing — good enough for approximate distributed semantics such as “spread rate limits across the member count” and “partition ownership”.

Source

pub fn member_count(&self) -> usize

Total number of cluster members (voters + learners). At least 1.

Source

pub fn voter_count(&self) -> usize

The number of members in the voting core (plan A’s small voting set, typically 3~5).

Source

pub fn current_leader(&self) -> Option<NodeId>

The currently known leader (returns None when unknown / during a leader election).

Source

pub fn status(&self) -> ClusterStatus

A cluster status snapshot (observability / operational monitoring: leader, term, applied position, member count).

Source

pub fn node_id(&self) -> NodeId

This node’s id.

Source

pub fn owned_partitions(&self) -> Vec<u32>

The partitions this node is responsible for under the current membership view (rendezvous assignment, default partition count).

Source

pub fn owns_key(&self, key: &str) -> bool

Whether a given account / session key is handled by this node (rendezvous assignment, default partition count).

No negotiation needed: membership comes from Raft’s strongly consistent view and the hash is deterministic, so every node reaches the same conclusion.

Source

pub async fn acquire_partition( &self, partition: u32, ttl_ms: u64, ) -> Result<Option<u64>, ControlError>

Claims a partition’s ownership lease and returns a monotonic fencing token.

For situations that need a strong guarantee at the moment membership changes: while two nodes’ views briefly disagree, only the node holding the newest token can safely handle the partition; downstream writes from a stale owner can be rejected on their smaller token. Steady-state ownership is decided by owns_key; this method layers a Raft-backed strong guarantee on top of it.

Source

pub async fn release_partition( &self, partition: u32, ) -> Result<(), ControlError>

Releases the partition ownership lease (only if it is still held by this node).

Source

pub async fn shutdown(&self) -> Result<(), ControlError>

Gracefully shuts down this node’s Raft runtime: stops background tasks and releases storage (including the redb file lock).

Call it before crash recovery / restart to make sure the redb database handle is released, so reopening the same directory no longer reports “Database already open”.

Source

pub async fn wait_leader(&self, timeout: Duration) -> Result<(), ControlError>

Waits for this node to become the leader (near-instant on a single node; a multi-node leader election takes one election-timeout window).

Trait Implementations§

Source§

impl Clone for RaftControlPlane

Source§

fn clone(&self) -> RaftControlPlane

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl ControlPlane for RaftControlPlane

Source§

fn set<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, key: &'life1 [u8], value: &'life2 [u8], ) -> Pin<Box<dyn Future<Output = Result<(), ControlError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Source§

fn get<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 [u8], ) -> Pin<Box<dyn Future<Output = Result<Option<Vec<u8>>, ControlError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

fn delete<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 [u8], ) -> Pin<Box<dyn Future<Output = Result<(), ControlError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

fn cas<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, key: &'life1 [u8], expect: Option<&'life2 [u8]>, value: &'life3 [u8], ) -> Pin<Box<dyn Future<Output = Result<bool, ControlError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Compare-and-swap; returns whether it succeeded.
Source§

fn acquire_lock<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, key: &'life1 str, holder: &'life2 str, ttl_ms: u64, ) -> Pin<Box<dyn Future<Output = Result<Option<u64>, ControlError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Acquire a lock; returns a fencing token on success.
Source§

fn renew_lock<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, key: &'life1 str, holder: &'life2 str, ttl_ms: u64, ) -> Pin<Box<dyn Future<Output = Result<bool, ControlError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Source§

fn release_lock<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, key: &'life1 str, holder: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<(), ControlError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

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> OptionalSend for T
where T: Send + ?Sized,

Source§

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

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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