Struct raft::Raft[][src]

pub struct Raft<T: Storage> {
    pub term: u64,
    pub vote: u64,
    pub id: u64,
    pub read_states: Vec<ReadState>,
    pub raft_log: RaftLog<T>,
    pub max_inflight: usize,
    pub max_msg_size: u64,
    pub state: StateRole,
    pub is_learner: bool,
    pub votes: FxHashMap<u64, bool>,
    pub msgs: Vec<Message>,
    pub leader_id: u64,
    pub lead_transferee: Option<u64>,
    pub pending_conf_index: u64,
    pub read_only: ReadOnly,
    pub election_elapsed: usize,
    pub check_quorum: bool,
    pub pre_vote: bool,
    // some fields omitted
}

A struct that represents the raft consensus itself. Stores details concerning the current and possible state the system can take.

Fields

The current election term.

Which peer this raft is voting for.

The ID of this node.

The current read states.

The persistent log.

The maximum number of messages that can be inflight.

The maximum length (in bytes) of all the entries.

The current role of this node.

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.

The current votes for this node in an election.

Reset when changing role.

The list of messages.

The leader id

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.

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.

The queue of read-only requests.

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.

Whether to check the quorum

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]

Creates a new raft for use on the node.

Grabs an immutable reference to the store.

Grabs a mutable reference to the store.

Grabs a reference to the snapshot

Returns the number of pending read-only messages.

Returns how many read states exist.

Returns a value representing the softstate at the time of calling.

Returns a value representing the hardstate at the time of calling.

Returns whether the current raft is in lease.

For testing leader lease

Fetch the length of the election timeout.

Fetch the length of the heartbeat timeout

Return the length of the current randomized election timeout.

Set whether skip broadcast empty commit messages at runtime.

Sends RPC, with entries to the given peer.

Sends RPC, with entries to all peers that are not up-to-date according to the progress recorded in r.prs().

Sends RPC, without entries to all the peers.

Attempts to advance the commit index. Returns true if the commit index changed (in which case the caller should call r.bcast_append).

Resets the current node to a given term.

Appends a slice of entries to the log. The entries are updated to match the current index and term.

Returns true to indicate that there will probably be some readiness need to be handled.

Run by followers and candidates after self.election_timeout.

Returns true to indicate that there will probably be some readiness need to be handled.

Converts this node to a follower.

Converts this node to a candidate

Panics

Panics if a leader already exists.

Converts this node to a pre-candidate

Panics

Panics if a leader already exists.

Makes this raft the leader.

Panics

Panics if this is a follower node.

Campaign to attempt to become a leader.

If prevote is enabled, this is handled as well.

Steps the raft along via a message. This should be called everytime your raft receives a message from a peer.

For a given message, append the entries to the log.

For a message, commit and send out heartbeat.

Recovers the state machine from a snapshot. It restores the log and the configuration of state machine.

Check if there is any pending confchange.

This method can be false positive.

Specifies if the commit should be broadcast.

Indicates whether state machine can be promoted to leader, which is true when its own id is in progress list.

Adds a new node to the cluster.

Adds a learner node.

Removes a node from the raft.

Updates the progress of the learner or voter.

Takes the progress set (destructively turns to None).

Sets the progress set.

Returns a read-only reference to the progress set.

Returns a mutable reference to the progress set.

For a given hardstate, load the state into self.

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].

Regenerates and stores the election timeout.

Issues a message to timeout immediately.

Stops the tranfer of a leader.

Trait Implementations

impl<T: Default + Storage> Default for Raft<T>
[src]

Returns the "default value" for a type. Read more

Auto Trait Implementations

impl<T> Send for Raft<T> where
    T: Send

impl<T> Sync for Raft<T> where
    T: Sync