Cargo Features

Openraft has no features set by default.

[dependencies]
openraft = { version = "0.9.5", features = ["bench", "bt", "serde", "single-term-leader", "compat", "storage-v2", "singlethreaded", "loosen-follower-log-revert", "generic-snapshot-data", "tracing-log", "serde_json", "tempfile", "or07"] }
bench

Enables benchmarks in unittest.

Benchmark in openraft depends on the unstable feature test thus it can not be used with stable rust. In order to run the benchmark with stable toolchain, the unstable features have to be enabled explicitly with environment variable RUSTC_BOOTSTRAP=1.

bt

Enable backtrace when generating an error.
Stable rust does not support backtrace.

Enables backtrace of anyerror and anyhow

serde

Add serde::Serialize and serde:Deserialize bound to data types. If you'd like to use serde to serialize messages.

Enables serde

Affects openraft::OptionalSerde, node::NodeId, node::Node

single-term-leader

Turn on this feature it allows at most ONE quorum-granted leader for each term. This is the way standard raft does, by making the LeaderId a partial order value.

  • With this feature on: It is more likely to conflict during election. But every log only needs to store one term in it.

  • With this feature off: Election conflict rate will be reduced, but every log has to store a LeaderId{ term, node_id}, which may be costly if an application uses a big NodeId type.

This feature is disabled by default.

compat

Provide basic compatible types

Affects openraft::compat

storage-v2

Allows an application to implement a custom the v2 storage API. See openraft::storage::v2 for more details. V2 API are unstable and may change in the future.

singlethreaded

Disallows applications to share a raft instance with multiple threads.

Enables singlethreaded of openraft-macros

Affects openraft::OptionalSend, openraft::OptionalSync

loosen-follower-log-revert

Permit the follower's log to roll back to an earlier state without causing the leader to panic.

Although log state reversion is typically seen as a bug, enabling it can be useful for testing or other special scenarios.
For instance, in an even number nodes cluster, erasing a node's data and then rebooting it(log reverts to empty) will not result in data loss.

generic-snapshot-data

Enable this feature flag to eliminate the `AsyncRead + AsyncWrite + AsyncSeek

  • Unpinbound fromRaftTypeConfig::SnapshotData`.

Enabling this feature allows applications to use a custom snapshot data format and transport fragmentation, diverging from the default implementation which typically relies on a single-file structure .

By default it is off. This feature is introduced in 0.9.0

Affects network::RaftNetwork.install_snapshot, network::RaftNetwork.full_snapshot

tracing-log

Enables "log" feature in tracing crate, to let tracing events emit log record. See: https://docs.rs/tracing/latest/tracing/#emitting-log-records

Enables log of tracing

Features from optional dependencies

In crates that don't use the dep: syntax, optional dependencies automatically become Cargo features. These features may have been created by mistake, and this functionality may be removed in the future.

anyhow bt?
serde_json implicit feature

Enables serde_json

serde_json:

A JSON serialization file format

tempfile implicit feature

Enables tempfile

tempfile:

A library for managing temporary files and directories

or07 implicit feature

Enables openraft ^0.7.4

openraft:

Advanced Raft consensus