pub struct RaftNode {
pub id: NodeId,
pub role: RaftRole,
pub current_term: RaftTerm,
pub voted_for: Option<NodeId>,
pub log: RaftLog,
pub commit_index: u64,
pub last_applied: u64,
}Expand description
A Raft consensus node.
Fields§
§id: NodeIdThis node’s ID.
role: RaftRoleCurrent role.
current_term: RaftTermLatest term this node has seen.
voted_for: Option<NodeId>NodeId this node voted for in the current term.
log: RaftLogThe replicated log.
commit_index: u64Index of highest log entry known to be committed.
last_applied: u64Index of highest log entry applied to state machine.
Implementations§
Source§impl RaftNode
impl RaftNode
Sourcepub fn process_vote_request(&mut self, req: &VoteRequest) -> VoteResponse
pub fn process_vote_request(&mut self, req: &VoteRequest) -> VoteResponse
Process an incoming vote request and return a response.
Grant vote if:
- Candidate’s term >= our current term.
- We haven’t voted for anyone else this term.
- Candidate’s log is at least as up-to-date as ours.
Sourcepub fn become_candidate(&mut self)
pub fn become_candidate(&mut self)
Transition this node to Candidate and start a new election.
Sourcepub fn become_leader(&mut self)
pub fn become_leader(&mut self)
Transition this node to Leader.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for RaftNode
impl RefUnwindSafe for RaftNode
impl Send for RaftNode
impl Sync for RaftNode
impl Unpin for RaftNode
impl UnsafeUnpin 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
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>
Wrap the input message
T in a tonic::Request