pub struct Raft<S: Store + 'static> { /* private fields */ }
Implementations§
Source§impl<S: Store + Send + Sync + 'static> Raft<S>
impl<S: Store + Send + Sync + 'static> Raft<S>
Sourcepub fn new<A: ToSocketAddrs>(
laddr: A,
store: S,
logger: Logger,
cfg: Config,
) -> Result<Self>
pub fn new<A: ToSocketAddrs>( laddr: A, store: S, logger: Logger, cfg: Config, ) -> Result<Self>
Creates a new Raft node with the provided address, store, logger, and configuration. The node communicates with other peers using a mailbox.
Sourcepub fn mailbox(&self) -> Mailbox
pub fn mailbox(&self) -> Mailbox
Returns a Mailbox
for the Raft node, which facilitates communication with peers.
Sourcepub async fn find_leader_info(
&self,
peer_addrs: Vec<String>,
) -> Result<Option<(u64, String)>>
pub async fn find_leader_info( &self, peer_addrs: Vec<String>, ) -> Result<Option<(u64, String)>>
Finds leader information by querying a list of peer addresses. Returns the leader ID and its address if found.
Sourcepub async fn lead(self, node_id: u64) -> Result<()>
pub async fn lead(self, node_id: u64) -> Result<()>
The lead
function transitions the current node to the leader role in a Raft cluster.
It initializes the leader node and runs both the Raft server and the node concurrently.
The function will return once the server or node experiences an error, or when the leader
role is relinquished.
§Arguments
node_id
- The unique identifier for the node.
§Returns
A Result<()>
indicating success or failure during the process.
Sourcepub async fn join(
self,
node_id: u64,
node_addr: String,
leader_id: Option<u64>,
leader_addr: String,
) -> Result<()>
pub async fn join( self, node_id: u64, node_addr: String, leader_id: Option<u64>, leader_addr: String, ) -> Result<()>
The join
function is used to make the current node join an existing Raft cluster.
It tries to discover the current leader, communicates with the leader to join the cluster,
and configures the node as a follower.
§Arguments
node_id
- The unique identifier for the current node.node_addr
- The address of the current node.leader_id
- The optional leader node’s identifier (if already known).leader_addr
- The address of the leader node.
§Returns
A Result<()>
indicating success or failure during the joining process.
Auto Trait Implementations§
impl<S> Freeze for Raft<S>where
S: Freeze,
impl<S> !RefUnwindSafe for Raft<S>
impl<S> Send for Raft<S>
impl<S> Sync for Raft<S>
impl<S> Unpin for Raft<S>where
S: Unpin,
impl<S> !UnwindSafe for Raft<S>
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request