diff --git a/guide/src/feature-flags.md b/guide/src/feature-flags.md index 6dff6b50e..75989c6d4 100644 --- a/guide/src/feature-flags.md +++ b/guide/src/feature-flags.md @@ -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. + \ No newline at end of file diff --git a/openraft/Cargo.toml b/openraft/Cargo.toml index c11c34df8..9123039a1 100644 --- a/openraft/Cargo.toml +++ b/openraft/Cargo.toml @@ -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] diff --git a/openraft/src/storage/mod.rs b/openraft/src/storage/mod.rs index 2a99e5895..0c309d8a6 100644 --- a/openraft/src/storage/mod.rs +++ b/openraft/src/storage/mod.rs @@ -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; @@ -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; diff --git a/openraft/src/storage/v2.rs b/openraft/src/storage/v2.rs index 7937ef234..2a640bdf3 100644 --- a/openraft/src/storage/v2.rs +++ b/openraft/src/storage/v2.rs @@ -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 Sealed for T {} } #[async_trait]