Struct raft::Raft [−][src]
A struct that represents the raft consensus itself. Stores details concerning the current and possible state the system can take.
Fields
msgs: Vec<Message>
The list of messages.
r: RaftCore<T>
Internal raftCore.
Implementations
impl<T: Storage> Raft<T>
[src]
pub fn new(c: &Config, store: T, logger: &Logger) -> Result<Self>
[src]
Creates a new raft for use on the node.
pub fn set_priority(&mut self, priority: u64)
[src]
Sets priority of node.
pub fn 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 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 election_timeout(&self) -> usize
[src]
Fetch the length of the election timeout.
pub fn heartbeat_timeout(&self) -> usize
[src]
Fetch the length of the heartbeat timeout
pub fn heartbeat_elapsed(&self) -> usize
[src]
Fetch the number of ticks elapsed since last heartbeat.
pub fn 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 set_batch_append(&mut self, batch_append: bool)
[src]
Set whether batch append msg at runtime.
pub fn enable_group_commit(&mut self, enable: bool)
[src]
Configures group commit.
If group commit is enabled, only logs replicated to at least two different groups are committed.
You should use assign_commit_groups
to configure peer groups.
pub fn group_commit(&self) -> bool
[src]
Whether enable group commit.
pub fn assign_commit_groups(&mut self, ids: &[(u64, u64)])
[src]
Assigns groups to peers.
The tuple is (peer_id
, group_id
). group_id
should be larger than 0.
The group information is only stored in memory. So you need to configure it every time a raft state machine is initialized or a snapshot is applied.
pub fn clear_commit_group(&mut self)
[src]
Removes all commit group configurations.
pub fn check_group_commit_consistent(&mut self) -> Option<bool>
[src]
Checks whether the raft group is using group commit and consistent over group.
If it can’t get a correct answer, None
is returned.
pub fn commit_to_current_term(&self) -> bool
[src]
Checks if logs are committed to its term.
The check is useful usually when raft is leader.
pub fn apply_to_current_term(&self) -> bool
[src]
Checks if logs are applied to current term.
impl<T: Storage> Raft<T>
[src]
pub fn send_append(&mut self, to: u64)
[src]
Sends an append RPC with new entries (if any) and the current commit index 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 ping(&mut self)
[src]
Broadcasts heartbeats to all the followers if it’s leader.
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 commit_apply(&mut self, applied: u64)
[src]
Commit that the Raft peer has applied up to the given index.
Registers the new applied index to the Raft log.
Hooks
- Post: Checks to see if it’s time to finalize a Joint Consensus state.
pub fn reset(&mut self, term: u64)
[src]
Resets the current node to a given term.
#[must_use]pub fn append_entry(&mut self, es: &mut [Entry]) -> bool
[src]
Appends a slice of entries to the log. The entries are updated to match the current index and term. Only called by leader currently
pub fn on_persist_entries(&mut self, index: u64, term: u64)
[src]
Notifies that these raft logs have been persisted.
pub fn on_persist_snap(&mut self, index: u64)
[src]
Notifies that the snapshot have been persisted.
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 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 request_snapshot(&mut self, request_index: u64) -> Result<()>
[src]
Request a snapshot from a leader.
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 post_conf_change(&mut self) -> ConfState
[src]
Updates the in-memory state and, when necessary, carries out additional actions such as reacting to the removal of nodes or changed quorum requirements.
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 it’s a voter and its own id is in progress list.
pub fn prs(&self) -> &ProgressTracker
[src]
Returns a read-only reference to the progress set.
pub fn mut_prs(&mut self) -> &mut ProgressTracker
[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 transfer of a leader.
pub fn reduce_uncommitted_size(&mut self, ents: &[Entry])
[src]
Reduce size of ‘ents’ from uncommitted size.
pub fn maybe_increase_uncommitted_size(&mut self, ents: &[Entry]) -> bool
[src]
Increase size of ‘ents’ to uncommitted size. Return true when size limit is satisfied. Otherwise return false and uncommitted size remains unchanged. For raft with no limit(or non-leader raft), it always return true.
pub fn uncommitted_size(&self) -> usize
[src]
Return current uncommitted size recorded by uncommitted_state
Trait Implementations
impl<T: Storage> Deref for Raft<T>
[src]
type Target = RaftCore<T>
The resulting type after dereferencing.
fn deref(&self) -> &RaftCore<T>
[src]
impl<T: Storage> DerefMut for Raft<T>
[src]
Auto Trait Implementations
impl<T> RefUnwindSafe for Raft<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> Send for Raft<T> where
T: Send,
T: Send,
impl<T> Sync for Raft<T> where
T: Sync,
T: Sync,
impl<T> Unpin for Raft<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for Raft<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> SendSyncUnwindSafe for T where
T: Send + Sync + UnwindSafe + ?Sized,
[src]
T: Send + Sync + UnwindSafe + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
[src]
V: MultiLane<T>,