Trait openraft::network::RaftNetwork
source · pub trait RaftNetwork<C>:
OptionalSend
+ OptionalSync
+ 'static
+ Sendwhere
C: RaftTypeConfig,{
// Required methods
fn append_entries(
&mut self,
rpc: AppendEntriesRequest<C>,
option: RPCOption,
) -> impl Future<Output = Result<AppendEntriesResponse<C::NodeId>, RPCError<C::NodeId, C::Node, RaftError<C::NodeId>>>> + Send;
fn vote(
&mut self,
rpc: VoteRequest<C::NodeId>,
option: RPCOption,
) -> impl Future<Output = Result<VoteResponse<C::NodeId>, RPCError<C::NodeId, C::Node, RaftError<C::NodeId>>>> + Send;
fn full_snapshot(
&mut self,
vote: Vote<C::NodeId>,
snapshot: Snapshot<C>,
cancel: impl Future<Output = ReplicationClosed> + OptionalSend + 'static,
option: RPCOption,
) -> impl Future<Output = Result<SnapshotResponse<C::NodeId>, StreamingError<C, Fatal<C::NodeId>>>> + Send;
// Provided methods
fn install_snapshot(
&mut self,
_rpc: InstallSnapshotRequest<C>,
_option: RPCOption,
) -> impl Future<Output = Result<InstallSnapshotResponse<C::NodeId>, RPCError<C::NodeId, C::Node, RaftError<C::NodeId, InstallSnapshotError>>>> + Send { ... }
fn backoff(&self) -> Backoff ⓘ { ... }
}
Expand description
A trait defining the interface for a Raft network between cluster members.
See the network chapter of the guide for details and discussion on this trait and how to implement it.
A single network instance is used to connect to a single target node. The network instance is
constructed by the RaftNetworkFactory
.
Required Methods§
sourcefn append_entries(
&mut self,
rpc: AppendEntriesRequest<C>,
option: RPCOption,
) -> impl Future<Output = Result<AppendEntriesResponse<C::NodeId>, RPCError<C::NodeId, C::Node, RaftError<C::NodeId>>>> + Send
fn append_entries( &mut self, rpc: AppendEntriesRequest<C>, option: RPCOption, ) -> impl Future<Output = Result<AppendEntriesResponse<C::NodeId>, RPCError<C::NodeId, C::Node, RaftError<C::NodeId>>>> + Send
Send an AppendEntries RPC to the target.
sourcefn vote(
&mut self,
rpc: VoteRequest<C::NodeId>,
option: RPCOption,
) -> impl Future<Output = Result<VoteResponse<C::NodeId>, RPCError<C::NodeId, C::Node, RaftError<C::NodeId>>>> + Send
fn vote( &mut self, rpc: VoteRequest<C::NodeId>, option: RPCOption, ) -> impl Future<Output = Result<VoteResponse<C::NodeId>, RPCError<C::NodeId, C::Node, RaftError<C::NodeId>>>> + Send
Send a RequestVote RPC to the target.
sourcefn full_snapshot(
&mut self,
vote: Vote<C::NodeId>,
snapshot: Snapshot<C>,
cancel: impl Future<Output = ReplicationClosed> + OptionalSend + 'static,
option: RPCOption,
) -> impl Future<Output = Result<SnapshotResponse<C::NodeId>, StreamingError<C, Fatal<C::NodeId>>>> + Send
fn full_snapshot( &mut self, vote: Vote<C::NodeId>, snapshot: Snapshot<C>, cancel: impl Future<Output = ReplicationClosed> + OptionalSend + 'static, option: RPCOption, ) -> impl Future<Output = Result<SnapshotResponse<C::NodeId>, StreamingError<C, Fatal<C::NodeId>>>> + Send
Send a complete Snapshot to the target.
This method is responsible to fragment the snapshot and send it to the target node.
Before returning from this method, the snapshot should be completely transmitted and
installed on the target node, or rejected because of vote
being smaller than the
remote one.
The default implementation just calls several install_snapshot
RPC for each fragment.
The vote
is the leader vote which is used to check if the leader is still valid by a
follower.
When the follower finished receiving snapshot, it calls Raft::install_full_snapshot()
with this vote.
cancel
get Ready
when the caller decides to cancel this snapshot transmission.
Provided Methods§
sourcefn install_snapshot(
&mut self,
_rpc: InstallSnapshotRequest<C>,
_option: RPCOption,
) -> impl Future<Output = Result<InstallSnapshotResponse<C::NodeId>, RPCError<C::NodeId, C::Node, RaftError<C::NodeId, InstallSnapshotError>>>> + Send
👎Deprecated since 0.9.0: with generic-snapshot-data
enabled, use full_snapshot()
instead to send full snapshot
fn install_snapshot( &mut self, _rpc: InstallSnapshotRequest<C>, _option: RPCOption, ) -> impl Future<Output = Result<InstallSnapshotResponse<C::NodeId>, RPCError<C::NodeId, C::Node, RaftError<C::NodeId, InstallSnapshotError>>>> + Send
generic-snapshot-data
enabled, use full_snapshot()
instead to send full snapshotSend an InstallSnapshot RPC to the target.
sourcefn backoff(&self) -> Backoff ⓘ
fn backoff(&self) -> Backoff ⓘ
Build a backoff instance if the target node is temporarily(or permanently) unreachable.
When a Unreachable
error is returned from the Network
methods, Openraft does not retry connecting to a node immediately. Instead, it sleeps
for a while and retries. The duration of the sleep is determined by the backoff
instance.
The backoff is an infinite iterator that returns the ith sleep interval before the ith retry. The returned instance will be dropped if a successful RPC is made.
By default it returns a constant backoff of 500 ms.