Feature: RaftNetwork::snapshot()
to send a complete snapshot
#1009
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Changelog
Feature:
RaftNetwork::snapshot()
to send a complete snapshotAdd
RaftNetwork::snapshot()
to send a complete snapshot and movesending snapshot by chunks out of ReplicationCore.
To enable a fully customizable implementation of snapshot transmission
tailored to the application's needs, this commit relocates the
chunk-by-chunk transmission logic from
ReplicationCore
to a newsub mod,
crate::network::stream_snapshot
.The
stream_snapshot
mod provides a default chunk-based snapshottransmission mechanism, which can be overridden by creating a custom
implementation of the
RaftNetwork::snapshot()
method. As part of thiscommit,
RaftNetwork::snapshot()
simply delegates tostream_snapshot
.Developers may use
stream_snapshot
as a reference when implementingtheir own snapshot transmission strategy.
Snapshot transmission is internally divided into two distinct phases:
Upon request for snapshot transmission,
ReplicationCore
initiates anew task
RaftNetwork::snapshot()
dedicated to sending a completeSnapshot
. This task should be able to be terminated gracefully bysubscribing the
cancel
future.Once the snapshot has been fully transmitted by
RaftNetwork::snapshot()
, the task signals an event back toReplicationCore
. Subsequently,ReplicationCore
informsRaftCore
of the event, allowing it to acknowledge the completion of the
snapshot transmission.
Other changes:
ReplicationCore
has twoRaftNetwork
s, one for log replication andheartbeat, the other for snapshot only.
ReplicationClosed
becomes a public error for notifying theapplication implemented sender that a snapshot replication is
canceled.
StreamingError
is introduced as a container of errors that may occurin application defined snapshot transmission, including local IO
error, network errors, errors returned by remote peer and
ReplicationClosed
.The
SnapshotResponse
type is introduced to differentiate it from theInstallSnapshotResponse
, which is used for chunk-based responses.This change is