Skip to content

Commit 8cbc7c2

Browse files
committed
docs: add FAQ: customized snapshot building
1 parent 37d6943 commit 8cbc7c2

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

openraft/src/docs/faq/faq-toc.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
* [Why is log id a tuple of `(term, node_id, log_index)`?](#why-is-log-id-a-tuple-of-term-node_id-log_index)
77
- [Replication](#replication)
88
* [How to minimize error logging when a follower is offline](#how-to-minimize-error-logging-when-a-follower-is-offline)
9+
- [Node management](#node-management)
10+
* [How to customize snapshot building policy?](#how-to-customize-snapshot-building-policy)
911
- [Cluster management](#cluster-management)
1012
* [How to initialize a cluster?](#how-to-initialize-a-cluster)
1113
* [Are there any issues with running a single node service?](#are-there-any-issues-with-running-a-single-node-service)

openraft/src/docs/faq/faq.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,23 @@ See: [`leader-id`](`crate::docs::data::leader_id`) for details.
8686
Excessive error logging, like `ERROR openraft::replication: 248: RPCError err=NetworkError: ...`, occurs when a follower node becomes unresponsive. To alleviate this, implement a mechanism within [`RaftNetwork`][] that returns a [`Unreachable`][] error instead of a [`NetworkError`][] when immediate replication retries to the affected node are not advised.
8787

8888

89+
## Node management
90+
91+
92+
### How to customize snapshot building policy?
93+
94+
OpenRaft provides a default snapshot building policy that triggers snapshots
95+
when the log count exceeds a threshold. Configure this via [`Config::snapshot_policy`]
96+
set to [`SnapshotPolicy::LogsSinceLast(n)`][`SnapshotPolicy::LogsSinceLast`].
97+
98+
To customize snapshot behavior:
99+
100+
- **Disable automatic snapshots**: Set [`Config::snapshot_policy`] to [`SnapshotPolicy::Never`]
101+
- **Manual snapshot triggers**: Use [`Raft::trigger().snapshot()`][`Trigger::snapshot`] to build snapshots on demand
102+
103+
This allows full control over when snapshots are created based on your application's specific requirements.
104+
105+
89106
## Cluster management
90107

91108

@@ -305,6 +322,10 @@ OpenRaft intentionally supports this behavior because:
305322
[`RaftTypeConfig`]: `crate::RaftTypeConfig`
306323

307324
[`Config::allow_log_reversion`]: `crate::config::Config::allow_log_reversion`
325+
[`Config::snapshot_policy`]: `crate::config::Config::snapshot_policy`
326+
327+
[`SnapshotPolicy::LogsSinceLast`]: `crate::config::SnapshotPolicy::LogsSinceLast`
328+
[`SnapshotPolicy::Never`]: `crate::config::SnapshotPolicy::Never`
308329

309330
[`RaftLogStorage::save_committed()`]: `crate::storage::RaftLogStorage::save_committed`
310331

@@ -325,3 +346,5 @@ OpenRaft intentionally supports this behavior because:
325346
[`Raft::metrics()`]: `crate::Raft::metrics`
326347
[`Raft::server_metrics()`]: `crate::Raft::server_metrics`
327348
[`Raft::data_metrics()`]: `crate::Raft::data_metrics`
349+
350+
[`Trigger::snapshot`]: `crate::raft::trigger::Trigger::snapshot`

0 commit comments

Comments
 (0)