Struct Raft

Source
pub struct Raft<T: Storage> {
Show 25 fields pub id: u64, pub term: u64, pub vote: u64, pub read_states: Vec<ReadState>, pub raft_log: RaftLog<T>, pub max_inflight: u64, pub max_msg_size: u64, pub prs: HashMap<u64, Progress>, pub learner_prs: HashMap<u64, Progress>, pub state: StateType, pub is_learner: bool, pub votes: HashMap<u64, bool>, pub msgs: Vec<Message>, pub lead: u64, pub lead_transferee: u64, pub pending_conf_index: u64, pub read_only: ReadOnly, pub election_elapsed: u64, pub heartbeat_elapsed: u64, pub check_quorum: bool, pub pre_vote: bool, pub heartbeat_timeout: u64, pub election_timeout: u64, pub randomized_election_timeout: u64, pub disable_proposal_forwarding: bool, /* private fields */
}

Fields§

§id: u64§term: u64§vote: u64§read_states: Vec<ReadState>§raft_log: RaftLog<T>§max_inflight: u64§max_msg_size: u64§prs: HashMap<u64, Progress>§learner_prs: HashMap<u64, Progress>§state: StateType§is_learner: bool§votes: HashMap<u64, bool>§msgs: Vec<Message>§lead: u64§lead_transferee: u64§pending_conf_index: u64§read_only: ReadOnly§election_elapsed: u64§heartbeat_elapsed: u64§check_quorum: bool§pre_vote: bool§heartbeat_timeout: u64§election_timeout: u64§randomized_election_timeout: u64§disable_proposal_forwarding: bool

Implementations§

Source§

impl<T: Storage> Raft<T>

Source

pub fn new(c: &mut Config, storage: T) -> Raft<T>

Storage is the storage for raft. raft generates entries and states to be stored in storage. raft reads the persisted entries and states out of Storage when it needs. raft reads out the previous state and configuration out of storage when restarting.

Source

pub fn get_status(&self) -> Status

Source

pub fn load_state(&mut self, state: &HardState)

Source

pub fn append_entry(&mut self, ents: &mut [Entry])

Source

pub fn maybe_commit(&mut self) -> bool

Source

pub fn become_follower(&mut self, term: u64, lead: u64)

Source

pub fn become_leader(&mut self)

Source

pub fn become_candidate(&mut self)

Source

pub fn become_pre_candidate(&mut self)

Source

pub fn reset(&mut self, term: u64)

Source

pub fn reset_randomized_election_timeout(&mut self)

Source

pub fn abort_leader_transfer(&mut self)

Source

pub fn nodes(&self) -> Vec<u64>

Source

pub fn learner_nodes(&self) -> Vec<u64>

Source

pub fn add_node(&mut self, id: u64)

Source

pub fn add_learner(&mut self, id: u64)

Source

pub fn add_node_or_learner_node(&mut self, id: u64, is_learner: bool)

Source

pub fn remove_node(&mut self, id: u64)

Source

pub fn del_progress(&mut self, id: u64)

Source

pub fn get_mut_progress(&mut self, id: u64) -> Option<&mut Progress>

Source

pub fn get_progress(&self, id: u64) -> Option<&Progress>

Source

pub fn set_progress( &mut self, id: u64, matched: u64, next: u64, is_learner: bool, )

Source

pub fn soft_state(&self) -> SoftState

Source

pub fn hard_state(&self) -> HardState

Source

pub fn tick(&mut self)

Source

pub fn promotable(&self) -> bool

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

Source

pub fn past_election_timeout(&self) -> bool

past_election_timeout returns true iff r.electionElapsed is greater than or equal to the randomized election timeout in [electiontimeout, 2 * electiontimeout - 1].

Source

pub fn step(&mut self, msg: Message) -> Result<()>

Source

pub fn bcast_append(&mut self)

Source

pub fn set_prs(&mut self, prs: HashMap<u64, Progress>)

Source

pub fn take_prs(&mut self) -> HashMap<u64, Progress>

Source

pub fn take_learner_prs(&mut self) -> HashMap<u64, Progress>

Source

pub fn set_learner_prs(&mut self, learner_prs: HashMap<u64, Progress>)

Source

pub fn restore(&mut self, s: Snapshot) -> bool

Source

pub fn handle_heartbeat(&mut self, msg: Message)

Source

pub fn handle_append_entries(&mut self, msg: &Message)

Source

pub fn campaign(&mut self, campaign_type: &[u8])

Trait Implementations§

Source§

impl<T: Default + Storage> Default for Raft<T>

Source§

fn default() -> Raft<T>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<T> !Freeze for Raft<T>

§

impl<T> !RefUnwindSafe for Raft<T>

§

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

§

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

§

impl<T> Unpin for Raft<T>
where T: Unpin,

§

impl<T> UnwindSafe for Raft<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.