pub struct RaftNode { /* private fields */ }Expand description
A Raft consensus node
Implementations§
Source§impl RaftNode
impl RaftNode
Sourcepub fn new(config: RaftConfig) -> RaftResult<Self>
pub fn new(config: RaftConfig) -> RaftResult<Self>
Create a new Raft node
Sourcepub fn current_term(&self) -> Term
pub fn current_term(&self) -> Term
Get the current term
Sourcepub fn commit_index(&self) -> LogIndex
pub fn commit_index(&self) -> LogIndex
Get the commit index
Sourcepub fn last_log_index(&self) -> LogIndex
pub fn last_log_index(&self) -> LogIndex
Get the last log index
Sourcepub fn propose(&self, command: Command) -> RaftResult<LogIndex>
pub fn propose(&self, command: Command) -> RaftResult<LogIndex>
Append a command to the log (leader only)
Sourcepub fn handle_request_vote(
&self,
req: RequestVoteRequest,
) -> RequestVoteResponse
pub fn handle_request_vote( &self, req: RequestVoteRequest, ) -> RequestVoteResponse
Handle a RequestVote RPC
Sourcepub fn handle_append_entries(
&self,
req: AppendEntriesRequest,
) -> AppendEntriesResponse
pub fn handle_append_entries( &self, req: AppendEntriesRequest, ) -> AppendEntriesResponse
Handle an AppendEntries RPC
Sourcepub fn start_election(&self) -> Vec<RequestVoteRequest>
pub fn start_election(&self) -> Vec<RequestVoteRequest>
Start an election (transition to candidate)
Sourcepub fn handle_vote_response(
&self,
from: NodeId,
resp: RequestVoteResponse,
) -> bool
pub fn handle_vote_response( &self, from: NodeId, resp: RequestVoteResponse, ) -> bool
Handle a vote response during election
Sourcepub fn create_heartbeats(&self) -> Vec<(NodeId, AppendEntriesRequest)>
pub fn create_heartbeats(&self) -> Vec<(NodeId, AppendEntriesRequest)>
Create heartbeat messages for all peers
Sourcepub fn create_replication_requests(&self) -> Vec<(NodeId, AppendEntriesRequest)>
pub fn create_replication_requests(&self) -> Vec<(NodeId, AppendEntriesRequest)>
Create replication messages for all peers
Sourcepub fn handle_replication_response(
&self,
from: NodeId,
resp: AppendEntriesResponse,
) -> RaftResult<()>
pub fn handle_replication_response( &self, from: NodeId, resp: AppendEntriesResponse, ) -> RaftResult<()>
Handle a replication response
Sourcepub fn election_timeout_elapsed(&self) -> bool
pub fn election_timeout_elapsed(&self) -> bool
Check if election timeout has elapsed
Sourcepub fn reset_election_timer(&self)
pub fn reset_election_timer(&self)
Reset election timer
Auto Trait Implementations§
impl Freeze for RaftNode
impl !RefUnwindSafe for RaftNode
impl Send for RaftNode
impl Sync for RaftNode
impl Unpin for RaftNode
impl !UnwindSafe for RaftNode
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
Mutably borrows from an owned value. Read more