pub struct RawNode<T: Storage> {
pub raft: Raft<T>,
/* private fields */
}
Expand description
RawNode is a thread-unsafe Node. The methods of this struct correspond to the methods of Node and are described more fully there.
Fields§
§raft: Raft<T>
The internal raft state.
Implementations§
source§impl<T: Storage> RawNode<T>
impl<T: Storage> RawNode<T>
sourcepub fn new(config: &Config, store: T, logger: &Logger) -> Result<Self>
pub fn new(config: &Config, store: T, logger: &Logger) -> Result<Self>
Create a new RawNode given some Config
.
sourcepub fn with_default_logger(c: &Config, store: T) -> Result<Self>
pub fn with_default_logger(c: &Config, store: T) -> Result<Self>
Create a new RawNode given some Config
and the default logger.
The default logger is an slog
to log
adapter.
sourcepub fn set_priority(&mut self, priority: i64)
pub fn set_priority(&mut self, priority: i64)
Sets priority of node.
sourcepub fn tick(&mut self) -> bool
pub fn tick(&mut self) -> bool
Tick advances the internal logical clock by a single tick.
Returns true to indicate that there will probably be some readiness which needs to be handled.
sourcepub fn campaign(&mut self) -> Result<()>
pub fn campaign(&mut self) -> Result<()>
Campaign causes this RawNode to transition to candidate state.
sourcepub fn propose(&mut self, context: Vec<u8>, data: Vec<u8>) -> Result<()>
pub fn propose(&mut self, context: Vec<u8>, data: Vec<u8>) -> Result<()>
Propose proposes data be appended to the raft log.
sourcepub fn ping(&mut self)
pub fn ping(&mut self)
Broadcast heartbeats to all the followers.
If it’s not leader, nothing will happen.
sourcepub fn propose_conf_change(
&mut self,
context: Vec<u8>,
cc: impl ConfChangeI
) -> Result<()>
pub fn propose_conf_change( &mut self, context: Vec<u8>, cc: impl ConfChangeI ) -> Result<()>
ProposeConfChange proposes a config change.
If the node enters joint state with auto_leave
set to true, it’s
caller’s responsibility to propose an empty conf change again to force
leaving joint state.
sourcepub fn apply_conf_change(&mut self, cc: &impl ConfChangeI) -> Result<ConfState>
pub fn apply_conf_change(&mut self, cc: &impl ConfChangeI) -> Result<ConfState>
Applies a config change to the local node. The app must call this when it applies a configuration change, except when it decides to reject the configuration change, in which case no call must take place.
sourcepub fn step(&mut self, m: Message) -> Result<()>
pub fn step(&mut self, m: Message) -> Result<()>
Step advances the state machine using the given message.
sourcepub fn on_entries_fetched(&mut self, context: GetEntriesContext)
pub fn on_entries_fetched(&mut self, context: GetEntriesContext)
A callback when entries are fetched asynchronously. The context should provide the context passed from Storage.entires(). See more in the comment of Storage.entires().
Panics
Panics if passed with the context of context.can_async() == false
sourcepub fn ready(&mut self) -> Ready
pub fn ready(&mut self) -> Ready
Returns the outstanding work that the application needs to handle.
This includes appending and applying entries or a snapshot, updating the HardState,
and sending messages. The returned Ready
MUST be handled and subsequently
passed back via advance
or its families. Before that, DO NOT call any function like
step
, propose
, campaign
to change internal state.
Self::has_ready
should be called first to check if it’s necessary to handle the ready.
sourcepub fn has_ready(&self) -> bool
pub fn has_ready(&self) -> bool
HasReady called when RawNode user need to check if any Ready pending.
sourcepub fn on_persist_ready(&mut self, number: u64)
pub fn on_persist_ready(&mut self, number: u64)
Notifies that the ready of this number has been persisted.
Since Ready must be persisted in order, calling this function implicitly means all readies with numbers smaller than this one have been persisted.
Self::has_ready
and Self::ready
should be called later to handle further
updates that become valid after ready being persisted.
sourcepub fn advance(&mut self, rd: Ready) -> LightReady
pub fn advance(&mut self, rd: Ready) -> LightReady
Advances the ready after fully processing it.
Fully processing a ready requires to persist snapshot, entries and hard states, apply all committed entries, send all messages.
Returns the LightReady that contains commit index, committed entries and messages. LightReady
contains updates that only valid after persisting last ready. It should also be fully processed.
Then Self::advance_apply
or Self::advance_apply_to
should be used later to update applying
progress.
sourcepub fn advance_append(&mut self, rd: Ready) -> LightReady
pub fn advance_append(&mut self, rd: Ready) -> LightReady
Advances the ready without applying committed entries. Self::advance_apply
or
Self::advance_apply_to
should be used later to update applying progress.
Returns the LightReady that contains commit index, committed entries and messages.
Since Ready must be persisted in order, calling this function implicitly means all ready collected before have been persisted.
sourcepub fn advance_append_async(&mut self, rd: Ready)
pub fn advance_append_async(&mut self, rd: Ready)
Same as Self::advance_append
except that it allows to only store the updates in cache.
Self::on_persist_ready
should be used later to update the persisting progress.
Raft works on an assumption persisted updates should not be lost, which usually requires expensive
operations like fsync
. advance_append_async
allows you to control the rate of such operations and
get a reasonable batch size. However, it’s still required that the updates can be read by raft from the
Storage
trait before calling advance_append_async
.
sourcepub fn advance_apply(&mut self)
pub fn advance_apply(&mut self)
Advance apply to the index of the last committed entries given before.
sourcepub fn advance_apply_to(&mut self, applied: u64)
pub fn advance_apply_to(&mut self, applied: u64)
Advance apply to the passed index.
sourcepub fn report_unreachable(&mut self, id: u64)
pub fn report_unreachable(&mut self, id: u64)
ReportUnreachable reports the given node is not reachable for the last send.
sourcepub fn report_snapshot(&mut self, id: u64, status: SnapshotStatus)
pub fn report_snapshot(&mut self, id: u64, status: SnapshotStatus)
ReportSnapshot reports the status of the sent snapshot.
sourcepub fn request_snapshot(&mut self) -> Result<()>
pub fn request_snapshot(&mut self) -> Result<()>
Request a snapshot from a leader. The snapshot’s index must be greater or equal to the request_index (last_index) or the leader’s term must be greater than the request term (last_index’s term).
sourcepub fn transfer_leader(&mut self, transferee: u64)
pub fn transfer_leader(&mut self, transferee: u64)
TransferLeader tries to transfer leadership to the given transferee.
sourcepub fn read_index(&mut self, rctx: Vec<u8>)
pub fn read_index(&mut self, rctx: Vec<u8>)
ReadIndex requests a read state. The read state will be set in ready. Read State has a read index. Once the application advances further than the read index, any linearizable read requests issued before the read request can be processed safely. The read state will have the same rctx attached.
sourcepub fn skip_bcast_commit(&mut self, skip: bool)
pub fn skip_bcast_commit(&mut self, skip: bool)
Set whether skip broadcast empty commit messages at runtime.
sourcepub fn set_batch_append(&mut self, batch_append: bool)
pub fn set_batch_append(&mut self, batch_append: bool)
Set whether to batch append msg at runtime.