Skip to content

Commit

Permalink
Feature: add feature flag storage-v2 to enable RaftLogStorage and Raf…
Browse files Browse the repository at this point in the history
…tStateMachine

`storage-v2`: enables `RaftLogStorage` and `RaftStateMachine` as the v2 storage
This is a temporary feature flag, and will be removed in the future, when v2 storage is stable.
This feature disables `Adapter`, which is for v1 storage to be used as v2.
V2 storage separates log store and state machine store so that log IO and state machine IO can be parallelized naturally.
  • Loading branch information
drmingdrmer committed Apr 19, 2023
1 parent 8c61a24 commit 87d62d5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
6 changes: 6 additions & 0 deletions guide/src/feature-flags.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,9 @@ By default openraft enables no features.
compat-07 = ["compat", "single-term-leader", "serde", "dep:or07", "compat-07-testing"]
compat-07-testing = ["dep:tempdir", "anyhow", "dep:serde_json"]
```

- `storage-v2`: enables `RaftLogStorage` and `RaftStateMachine` as the v2 storage
This is a temporary feature flag, and will be removed in the future, when v2 storage is stable.
This feature disables `Adapter`, which is for v1 storage to be used as v2.
V2 storage separates log store and state machine store so that log IO and state machine IO can be parallelized naturally.

5 changes: 5 additions & 0 deletions openraft/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ compat = []
compat-07 = ["compat", "serde", "dep:or07", "compat-07-testing"]
compat-07-testing = ["dep:tempfile", "anyhow", "dep:serde_json"]

# 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.
storage-v2 = []

# default = ["single-term-leader"]

[package.metadata.docs.rs]
Expand Down
4 changes: 2 additions & 2 deletions openraft/src/storage/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! The Raft storage interface and data types.

pub(crate) mod adapter;
#[cfg(not(feature = "storage-v2"))] pub(crate) mod adapter;
mod callback;
mod helper;
mod log_store_ext;
Expand All @@ -10,7 +10,7 @@ mod v2;
use std::fmt::Debug;
use std::ops::RangeBounds;

pub use adapter::Adaptor;
#[cfg(not(feature = "storage-v2"))] pub use adapter::Adaptor;
use async_trait::async_trait;
pub use helper::StorageHelper;
pub use log_store_ext::RaftLogReaderExt;
Expand Down
5 changes: 5 additions & 0 deletions openraft/src/storage/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ pub(crate) mod sealed {
/// Seal [`RaftLogStorage`] and [`RaftStateMachine`]. This is to prevent users from implementing
/// them before being stable.
pub trait Sealed {}

/// Implement non-public trait [`Sealed`] for all types so that [`RaftLogStorage`] and
/// [`RaftStateMachine`] can be implemented by 3rd party crates.
#[cfg(feature = "storage-v2")]
impl<T> Sealed for T {}
}

#[async_trait]
Expand Down

0 comments on commit 87d62d5

Please sign in to comment.