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>
impl<T: Storage> Raft<T>
Sourcepub fn new(c: &mut Config, storage: T) -> Raft<T>
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.
pub fn get_status(&self) -> Status
pub fn load_state(&mut self, state: &HardState)
pub fn append_entry(&mut self, ents: &mut [Entry])
pub fn maybe_commit(&mut self) -> bool
pub fn become_follower(&mut self, term: u64, lead: u64)
pub fn become_leader(&mut self)
pub fn become_candidate(&mut self)
pub fn become_pre_candidate(&mut self)
pub fn reset(&mut self, term: u64)
pub fn reset_randomized_election_timeout(&mut self)
pub fn abort_leader_transfer(&mut self)
pub fn nodes(&self) -> Vec<u64>
pub fn learner_nodes(&self) -> Vec<u64>
pub fn add_node(&mut self, id: u64)
pub fn add_learner(&mut self, id: u64)
pub fn add_node_or_learner_node(&mut self, id: u64, is_learner: bool)
pub fn remove_node(&mut self, id: u64)
pub fn del_progress(&mut self, id: u64)
pub fn get_mut_progress(&mut self, id: u64) -> Option<&mut Progress>
pub fn get_progress(&self, id: u64) -> Option<&Progress>
pub fn set_progress( &mut self, id: u64, matched: u64, next: u64, is_learner: bool, )
pub fn soft_state(&self) -> SoftState
pub fn hard_state(&self) -> HardState
pub fn tick(&mut self)
Sourcepub fn promotable(&self) -> bool
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.
Sourcepub fn past_election_timeout(&self) -> bool
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].
pub fn step(&mut self, msg: Message) -> Result<()>
pub fn bcast_append(&mut self)
pub fn set_prs(&mut self, prs: HashMap<u64, Progress>)
pub fn take_prs(&mut self) -> HashMap<u64, Progress>
pub fn take_learner_prs(&mut self) -> HashMap<u64, Progress>
pub fn set_learner_prs(&mut self, learner_prs: HashMap<u64, Progress>)
pub fn restore(&mut self, s: Snapshot) -> bool
pub fn handle_heartbeat(&mut self, msg: Message)
pub fn handle_append_entries(&mut self, msg: &Message)
pub fn campaign(&mut self, campaign_type: &[u8])
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more