Struct raft::raw_node::RawNode[][src]

pub struct RawNode<T: Storage> {
    pub raft: Raft<T>,
    // some fields omitted
}

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

impl<T: Storage> RawNode<T>[src]

pub fn new(config: &Config, store: T, logger: &Logger) -> Result<Self>[src]

Create a new RawNode given some Config.

pub fn set_priority(&mut self, priority: u64)[src]

Sets priority of node.

pub fn tick(&mut self) -> bool[src]

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.

pub fn campaign(&mut self) -> Result<()>[src]

Campaign causes this RawNode to transition to candidate state.

pub fn propose(&mut self, context: Vec<u8>, data: Vec<u8>) -> Result<()>[src]

Propose proposes data be appended to the raft log.

pub fn ping(&mut self)[src]

Broadcast heartbeats to all the followers.

If it’s not leader, nothing will happen.

pub fn propose_conf_change(
    &mut self,
    context: Vec<u8>,
    cc: impl ConfChangeI
) -> Result<()>
[src]

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.

pub fn apply_conf_change(&mut self, cc: &impl ConfChangeI) -> Result<ConfState>[src]

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.

pub fn step(&mut self, m: Message) -> Result<()>[src]

Step advances the state machine using the given message.

pub fn ready(&mut self) -> Ready[src]

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.

has_ready should be called first to check if it’s necessary to handle the ready.

pub fn has_ready(&self) -> bool[src]

HasReady called when RawNode user need to check if any Ready pending.

pub fn on_persist_ready(&mut self, number: u64)[src]

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.

has_ready and ready should be called later to handle further updates that become valid after ready being persisted.

pub fn advance(&mut self, rd: Ready) -> LightReady[src]

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 advance_apply or advance_apply_to should be used later to update applying progress.

pub fn advance_append(&mut self, rd: Ready) -> LightReady[src]

Advances the ready without applying committed entries. advance_apply or 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.

pub fn advance_append_async(&mut self, rd: Ready)[src]

Same as advance_append except that it allows to only store the updates in cache. 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.

pub fn advance_apply(&mut self)[src]

Advance apply to the index of the last committed entries given before.

pub fn advance_apply_to(&mut self, applied: u64)[src]

Advance apply to the passed index.

pub fn snap(&self) -> Option<&Snapshot>[src]

Grabs the snapshot from the raft if available.

pub fn status(&self) -> Status<'_>[src]

Status returns the current status of the given group.

pub fn report_unreachable(&mut self, id: u64)[src]

ReportUnreachable reports the given node is not reachable for the last send.

pub fn report_snapshot(&mut self, id: u64, status: SnapshotStatus)[src]

ReportSnapshot reports the status of the sent snapshot.

pub fn request_snapshot(&mut self, request_index: u64) -> Result<()>[src]

Request a snapshot from a leader. The snapshot’s index must be greater or equal to the request_index.

pub fn transfer_leader(&mut self, transferee: u64)[src]

TransferLeader tries to transfer leadership to the given transferee.

pub fn read_index(&mut self, rctx: Vec<u8>)[src]

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.

pub fn store(&self) -> &T[src]

Returns the store as an immutable reference.

pub fn mut_store(&mut self) -> &mut T[src]

Returns the store as a mutable reference.

pub fn skip_bcast_commit(&mut self, skip: bool)[src]

Set whether skip broadcast empty commit messages at runtime.

pub fn set_batch_append(&mut self, batch_append: bool)[src]

Set whether to batch append msg at runtime.

Auto Trait Implementations

impl<T> RefUnwindSafe for RawNode<T> where
    T: RefUnwindSafe

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

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

impl<T> Unpin for RawNode<T> where
    T: Unpin

impl<T> UnwindSafe for RawNode<T> where
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> SendSyncUnwindSafe for T where
    T: Send + Sync + UnwindSafe + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 
[src]