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§

source

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,

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.

source

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 a SnapshotData 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§

This trait is not object safe.

Implementors§

source§

impl<C: RaftTypeConfig> SnapshotTransport<C> for Chunked

This chunk based implementation requires SnapshotData to be AsyncRead + AsyncSeek.