Struct raft::Raft[][src]

pub struct Raft<T: Storage> {
    pub msgs: Vec<Message>,
    pub r: RaftCore<T>,
    // some fields omitted
}
Expand description

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

Creates a new raft for use on the node.

Sets priority of node.

Creates a new raft for use on the node with the default logger.

The default logger is an slog to log adapter.

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.

Fetch the length of the election timeout.

Fetch the length of the heartbeat timeout

Fetch the number of ticks elapsed since last heartbeat.

Return the length of the current randomized election timeout.

Set whether skip broadcast empty commit messages at runtime.

Set whether batch append msg at runtime.

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.

Whether enable group commit.

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.

Removes all commit group configurations.

Checks whether the raft group is using group commit and consistent over group.

If it can’t get a correct answer, None is returned.

Checks if logs are committed to its term.

The check is useful usually when raft is leader.

Checks if logs are applied to current term.

Set max_committed_size_per_ready to size.

Sends an append RPC with new entries (if any) and the current commit index 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().

Broadcasts heartbeats to all the followers if it’s leader.

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

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.

Resets the current node to a given term.

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

Notifies that these raft logs have been persisted.

Notifies that the snapshot have been persisted.

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.

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

Request a snapshot from a leader.

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.

Updates the in-memory state and, when necessary, carries out additional actions such as reacting to the removal of nodes or changed quorum requirements.

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 it’s a voter and its own id is in progress list.

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 transfer of a leader.

Reduce size of ‘ents’ from uncommitted size.

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.

Return current uncommitted size recorded by uncommitted_state

Trait Implementations

The resulting type after dereferencing.

Dereferences the value.

Mutably dereferences the value.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.