Skip to content

Commit

Permalink
Merge pull request #777 from drmingdrmer/51-v2-rocks-store
Browse files Browse the repository at this point in the history
Refactor: add example stores/rocksstore using v2 storage
  • Loading branch information
drmingdrmer committed Apr 19, 2023
2 parents 8c61a24 + dbdaf0a commit 17a658f
Show file tree
Hide file tree
Showing 11 changed files with 687 additions and 4 deletions.
35 changes: 34 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,39 @@ jobs:
OPENRAFT_STORE_DEFENSIVE: on


# Test external stores that enable different openraft features.
external-stores:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
include:
- store: "stores/rocksstore-v2"

steps:
- name: Setup | Checkout
uses: actions/checkout@v2


- name: Setup | Toolchain
uses: actions-rs/toolchain@v1.0.6
with:
toolchain: "nightly"
override: true


- name: Unit Tests
uses: actions-rs/cargo@v1
with:
command: test
args: --manifest-path "${{ matrix.store }}/Cargo.toml"
env:
# Parallel tests block each other and result in timeout.
RUST_TEST_THREADS: 2
RUST_LOG: debug
RUST_BACKTRACE: full
OPENRAFT_STORE_DEFENSIVE: on

# Feature "serde" will be enabled if one of the member carge enables
# "serde", such as `memstore`, when building cargo workspace.
Expand Down Expand Up @@ -261,7 +294,7 @@ jobs:
shell: bash
run: |
cargo clippy --no-deps --workspace --all-targets -- -D warnings
cargo clippy --no-deps --workspace --all-targets --all-features -- -D warnings
cargo clippy --no-deps --workspace --all-targets --features "bt,serde,bench,single-term-leader,compat-07" -- -D warnings
- name: Build-doc
Expand Down
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,8 @@ members = [
"rocksstore",
"rocksstore-compat07",
"sledstore"]
exclude = ["examples/raft-kv-memstore", "examples/raft-kv-rocksdb"]
exclude = [
"stores/rocksstore-v2",
"examples/raft-kv-memstore",
"examples/raft-kv-rocksdb",
]
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
4 changes: 4 additions & 0 deletions stores/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Storage implementations.

These crates are not members of the workspace, because they enable different features.
E.g., `rocksstore-v2` enables `storage-v2` feature.
35 changes: 35 additions & 0 deletions stores/rocksstore-v2/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[package]
name = "openraft-rocksstore-v2"
description = "A rocksdb based implementation of the `openraft::RaftStorage` trait."
documentation = "https://docs.rs/openraft-rocksstore"
readme = "README.md"

version = "0.1.0"
edition = "2021"
authors = [
"drdr xp <drdr.xp@gmail.com>",
]
categories = ["algorithms", "asynchronous", "data-structures"]
homepage = "https://github.com/datafuselabs/openraft"
keywords = ["raft", "consensus"]
license = "MIT/Apache-2.0"
repository = "https://github.com/datafuselabs/openraft"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
openraft = { path= "../../openraft", version = "0.8.4", features=["serde", "storage-v2"] }

rocksdb = "0.20.1"
rand = "*"
byteorder = "1.4.3"
serde = { version = "1.0.114", features = ["derive"] }
serde_json = "1.0.57"
tracing = "0.1.29"

[dev-dependencies]
async-trait = { version = "0.1.36" }
tempfile = { version = "3.4.0" }

[package.metadata.docs.rs]
all-features = true
6 changes: 6 additions & 0 deletions stores/rocksstore-v2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# openraft-rocksstore-v2

This is an example of v2 storage [`RaftLogStorage`] and [`RaftStateMachine`] implementation
with [`rocksdb`](https://docs.rs/rocksdb/latest/rocksdb/) based on [openraft-0.8](https://github.com/datafuselabs/openraft/tree/release-0.8).

This crate is built mainly for testing or demonstrating purpose.:)
Loading

0 comments on commit 17a658f

Please sign in to comment.