[−][src]Struct raft::prelude::Raft
A struct that represents the raft consensus itself. Stores details concerning the current and possible state the system can take.
Fields
term: u64
The current election term.
vote: u64
Which peer this raft is voting for.
id: u64
The ID of this node.
read_states: Vec<ReadState>
The current read states.
raft_log: RaftLog<T>
The persistent log.
max_inflight: usize
The maximum number of messages that can be inflight.
max_msg_size: u64
The maximum length (in bytes) of all the entries.
state: StateRole
The current role of this node.
is_learner: bool
Whether this is a learner node.
Learners are not permitted to vote in elections, and are not counted for commit quorums. They do replicate data from the leader.
votes: FxHashMap<u64, bool>
The current votes for this node in an election.
Reset when changing role.
msgs: Vec<Message>
The list of messages.
leader_id: u64
The leader id
lead_transferee: Option<u64>
ID of the leader transfer target when its value is not None.
If this is Some(id), we follow the procedure defined in raft thesis 3.10.
pending_conf_index: u64
Only one conf change may be pending (in the log, but not yet applied) at a time. This is enforced via pending_conf_index, which is set to a value >= the log index of the latest pending configuration change (if any). Config changes are only allowed to be proposed if the leader's applied index is greater than this value.
read_only: ReadOnly
The queue of read-only requests.
election_elapsed: usize
Ticks since it reached last electionTimeout when it is leader or candidate. Number of ticks since it reached last electionTimeout or received a valid message from current leader when it is a follower.
check_quorum: bool
Whether to check the quorum
pre_vote: bool
Enable the prevote algorithm.
This enables a pre-election vote round on Candidates prior to disrupting the cluster.
Enable this if greater cluster stability is preferred over faster elections.
Methods
impl<T: Storage> Raft<T>
[src]
pub fn new(c: &Config, store: T) -> Raft<T>
[src]
Creates a new raft for use on the node.
pub fn get_store(&self) -> &T
[src]
Grabs an immutable reference to the store.
pub fn mut_store(&mut self) -> &mut T
[src]
Grabs a mutable reference to the store.
pub fn get_snap(&self) -> Option<&Snapshot>
[src]
Grabs a reference to the snapshot
pub fn pending_read_count(&self) -> usize
[src]
Returns the number of pending read-only messages.
pub fn ready_read_count(&self) -> usize
[src]
Returns how many read states exist.
pub fn soft_state(&self) -> SoftState
[src]
Returns a value representing the softstate at the time of calling.
pub fn hard_state(&self) -> HardState
[src]
Returns a value representing the hardstate at the time of calling.
pub fn in_lease(&self) -> bool
[src]
Returns whether the current raft is in lease.
pub fn set_randomized_election_timeout(&mut self, t: usize)
[src]
For testing leader lease
pub fn get_election_timeout(&self) -> usize
[src]
Fetch the length of the election timeout.
pub fn get_heartbeat_timeout(&self) -> usize
[src]
Fetch the length of the heartbeat timeout
pub fn get_randomized_election_timeout(&self) -> usize
[src]
Return the length of the current randomized election timeout.
pub fn skip_bcast_commit(&mut self, skip: bool)
[src]
Set whether skip broadcast empty commit messages at runtime.
pub fn send_append(&mut self, to: u64, pr: &mut Progress)
[src]
Sends RPC, with entries to the given peer.
pub fn bcast_append(&mut self)
[src]
Sends RPC, with entries to all peers that are not up-to-date according to the progress recorded in r.prs().
pub fn bcast_heartbeat(&mut self)
[src]
Sends RPC, without entries to all the peers.
pub fn maybe_commit(&mut self) -> bool
[src]
Attempts to advance the commit index. Returns true if the commit index
changed (in which case the caller should call r.bcast_append
).
pub fn reset(&mut self, term: u64)
[src]
Resets the current node to a given term.
pub fn append_entry(&mut self, es: &mut [Entry])
[src]
Appends a slice of entries to the log. The entries are updated to match the current index and term.
pub fn tick(&mut self) -> bool
[src]
Returns true to indicate that there will probably be some readiness need to be handled.
pub fn tick_election(&mut self) -> bool
[src]
Run by followers and candidates after self.election_timeout.
Returns true to indicate that there will probably be some readiness need to be handled.
pub fn become_follower(&mut self, term: u64, leader_id: u64)
[src]
Converts this node to a follower.
pub fn become_candidate(&mut self)
[src]
pub fn become_pre_candidate(&mut self)
[src]
pub fn become_leader(&mut self)
[src]
pub fn campaign(&mut self, campaign_type: &[u8])
[src]
Campaign to attempt to become a leader.
If prevote is enabled, this is handled as well.
pub fn step(&mut self, m: Message) -> Result<()>
[src]
Steps the raft along via a message. This should be called everytime your raft receives a message from a peer.
pub fn handle_append_entries(&mut self, m: &Message)
[src]
For a given message, append the entries to the log.
pub fn handle_heartbeat(&mut self, m: Message)
[src]
For a message, commit and send out heartbeat.
pub fn restore(&mut self, snap: Snapshot) -> bool
[src]
Recovers the state machine from a snapshot. It restores the log and the configuration of state machine.
pub fn has_pending_conf(&self) -> bool
[src]
Check if there is any pending confchange.
This method can be false positive.
pub fn should_bcast_commit(&self) -> bool
[src]
Specifies if the commit should be broadcast.
pub fn promotable(&self) -> bool
[src]
Indicates whether state machine can be promoted to leader, which is true when its own id is in progress list.
pub fn add_node(&mut self, id: u64)
[src]
Adds a new node to the cluster.
pub fn add_learner(&mut self, id: u64)
[src]
Adds a learner node.
pub fn remove_node(&mut self, id: u64)
[src]
Removes a node from the raft.
pub fn set_progress(
&mut self,
id: u64,
matched: u64,
next_idx: u64,
is_learner: bool
)
[src]
&mut self,
id: u64,
matched: u64,
next_idx: u64,
is_learner: bool
)
Updates the progress of the learner or voter.
pub fn take_prs(&mut self) -> ProgressSet
[src]
Takes the progress set (destructively turns to None
).
pub fn set_prs(&mut self, prs: ProgressSet)
[src]
Sets the progress set.
pub fn prs(&self) -> &ProgressSet
[src]
Returns a read-only reference to the progress set.
pub fn mut_prs(&mut self) -> &mut ProgressSet
[src]
Returns a mutable reference to the progress set.
pub fn load_state(&mut self, hs: &HardState)
[src]
For a given hardstate, load the state into self.
pub fn pass_election_timeout(&self) -> bool
[src]
pass_election_timeout
returns true iff election_elapsed
is greater
than or equal to the randomized election timeout in
[election_timeout
, 2 * election_timeout
- 1].
pub fn reset_randomized_election_timeout(&mut self)
[src]
Regenerates and stores the election timeout.
pub fn send_timeout_now(&mut self, to: u64)
[src]
Issues a message to timeout immediately.
pub fn abort_leader_transfer(&mut self)
[src]
Stops the tranfer of a leader.
Trait Implementations
Auto Trait Implementations
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From for T
[src]
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,