Update docs on RaftStorage::Snapshot usage.

closes #93
This commit is contained in:
Anthony Dodd 2021-01-17 09:38:07 -06:00
parent e26d6ab423
commit 5ca6f8d1cf
No known key found for this signature in database
GPG Key ID: 6E0613E0F653DBC0
2 changed files with 4 additions and 1 deletions

View File

@ -83,6 +83,9 @@ where
R: AppDataResponse,
{
/// The storage engine's associated type used for exposing a snapshot for reading & writing.
///
/// See the [storage chapter of the guide](https://async-raft.github.io/async-raft/storage.html)
/// for details on where and how this is used.
type Snapshot: AsyncRead + AsyncWrite + AsyncSeek + Send + Unpin + 'static;
/// The error type used to indicate to Raft that shutdown is needed when calling the
/// `apply_entry_to_state_machine` method.

View File

@ -13,7 +13,7 @@ Once you're ready to begin with your implementation, be sure to adhere to the do
For inspiration, have a look at this [repo's `memstore` project](https://github.com/async-raft/async-raft/tree/master/memstore). It is an in-memory implementation of the `RaftStorage` trait, intended for demo and testing purposes.
### compaction / snapshots
This implementation of Raft automatically triggers log compaction based on runtime configuration, using the [`RaftStorage::do_log_compaction`](https://docs.rs/async-raft/latest/async_raft/storage/trait.RaftStorage.html#tymethod.do_log_compaction) method. Everything related to compaction / snapshots starts with this method. Though snapshots are originally created in the [`RaftStorage::do_log_compaction`](https://docs.rs/async-raft/latest/async_raft/storage/trait.RaftStorage.html#tymethod.do_log_compaction) method, the Raft cluster leader may stream a snapshot over to other nodes if the node is new and needs to be brought up-to-speed, or if a node is lagging behind.
This implementation of Raft automatically triggers log compaction based on runtime configuration, using the [`RaftStorage::do_log_compaction`](https://docs.rs/async-raft/latest/async_raft/storage/trait.RaftStorage.html#tymethod.do_log_compaction) method. Everything related to compaction / snapshots starts with this method. Though snapshots are originally created in the [`RaftStorage::do_log_compaction`](https://docs.rs/async-raft/latest/async_raft/storage/trait.RaftStorage.html#tymethod.do_log_compaction) method, the Raft cluster leader may stream a snapshot over to other nodes if the node is new and needs to be brought up-to-speed, or if a node is lagging behind. Internally, Raft uses the `RaftStorage::Snapshot` associated type to work with the snapshot locally and for streaming to follower nodes.
Compaction / snapshotting are not optional in this system. It is an integral component of the Raft spec, and `RaftStorage` implementations should be careful to implement the compaction / snapshotting related methods carefully according to the trait's documentation.