Trait openraft::network::snapshot_transport::SnapshotTransport
source · pub trait SnapshotTransport<C: RaftTypeConfig>: Send {
// Required methods
fn send_snapshot<Net>(
net: &mut Net,
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
where Net: RaftNetwork<C> + ?Sized;
fn receive_snapshot(
streaming: &mut Option<Streaming<C>>,
raft: &Raft<C>,
req: InstallSnapshotRequest<C>,
) -> impl Future<Output = Result<Option<Snapshot<C>>, RaftError<C::NodeId, InstallSnapshotError>>> + Send;
}
Expand description
Defines the sending and receiving API for snapshot transport.
Required Methods§
sourcefn send_snapshot<Net>(
net: &mut Net,
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>>>> + Sendwhere
Net: RaftNetwork<C> + ?Sized,
fn send_snapshot<Net>(
net: &mut Net,
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>>>> + Sendwhere
Net: RaftNetwork<C> + ?Sized,
Send a snapshot to a target node via Net
.
This function is for backward compatibility and provides a default implement for
RaftNetwork::full_snapshot()
upon RafNetwork::install_snapshot()
.
The argument vote
is the leader’s(the caller’s) vote,
which is used to check if the leader is still valid by a follower.
cancel
is a future that is polled by this function to check if the caller decides to
cancel.
It return Ready
if the caller decide to cancel this snapshot transmission.
sourcefn receive_snapshot(
streaming: &mut Option<Streaming<C>>,
raft: &Raft<C>,
req: InstallSnapshotRequest<C>,
) -> impl Future<Output = Result<Option<Snapshot<C>>, RaftError<C::NodeId, InstallSnapshotError>>> + Send
fn receive_snapshot( streaming: &mut Option<Streaming<C>>, raft: &Raft<C>, req: InstallSnapshotRequest<C>, ) -> impl Future<Output = Result<Option<Snapshot<C>>, RaftError<C::NodeId, InstallSnapshotError>>> + Send
Receive a chunk of snapshot. If the snapshot is done receiving, return the snapshot.
This method provide a default implementation for chunk based snapshot transport, and requires the caller to provide two things:
- The receiving state
streaming
is maintained by the caller. - And it depends on
Raft::begin_receiving_snapshot()
to create aSnapshotData
for receiving data.
Example usage:
struct App<C> {
raft: Raft<C>
streaming: Option<Streaming<C>>,
}
impl<C> App<C> {
fn handle_install_snapshot_request(&mut self, req: InstallSnapshotRequest<C>) {
let res = Chunked::receive_snapshot(&mut self.streaming, &self.raft, req).await?;
if let Some(snapshot) = res {
self.raft.install_snapshot(snapshot).await?;
}
}
}
Object Safety§
Implementors§
impl<C: RaftTypeConfig> SnapshotTransport<C> for Chunked
This chunk based implementation requires SnapshotData
to be AsyncRead + AsyncSeek
.