Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
jopemachine committed Sep 30, 2024
1 parent 1d432e9 commit 35216ae
Show file tree
Hide file tree
Showing 7 changed files with 268 additions and 82 deletions.
11 changes: 11 additions & 0 deletions examples/memstore/dynamic-members/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ use raftify::MemStorage;
#[cfg(feature = "heed_storage")]
use raftify::HeedStorage;

#[cfg(feature = "rocksdb_storage")]
use raftify::RocksDBStorage;

#[derive(Debug, StructOpt)]
struct Options {
#[structopt(long)]
Expand Down Expand Up @@ -88,6 +91,10 @@ async fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
let log_storage = HeedStorage::create(&storage_pth, &cfg.clone(), logger.clone())
.expect("Failed to create heed storage");

#[cfg(feature = "rocksdb_storage")]
let log_storage = RocksDBStorage::create(&storage_pth, logger.clone())
.expect("Failed to create heed storage");

let raft = Raft::bootstrap(
node_id,
options.raft_addr,
Expand Down Expand Up @@ -131,6 +138,10 @@ async fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
let log_storage = HeedStorage::create(&storage_pth, &cfg.clone(), logger.clone())
.expect("Failed to create heed storage");

#[cfg(feature = "rocksdb_storage")]
let log_storage = RocksDBStorage::create(&storage_pth, logger.clone())
.expect("Failed to create heed storage");

let raft = Raft::bootstrap(
leader_node_id,
options.raft_addr,
Expand Down
6 changes: 6 additions & 0 deletions examples/memstore/src/state_machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@ use std::{
sync::{Arc, RwLock},
};

#[cfg(feature = "inmemory_storage")]
pub use raftify::MemStorage as StorageType;

#[cfg(feature = "heed_storage")]
pub use raftify::HeedStorage as StorageType;

#[cfg(feature = "rocksdb_storage")]
pub use raftify::RocksDBStorage as StorageType;

pub type Raft = Raft_<LogEntry, StorageType, HashStore>;

#[derive(Clone, Debug, Serialize, Deserialize)]
Expand Down
7 changes: 7 additions & 0 deletions examples/memstore/static-members/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ use raftify::MemStorage;
#[cfg(feature = "heed_storage")]
use raftify::HeedStorage;

#[cfg(feature = "rocksdb_storage")]
use raftify::RocksDBStorage;

#[derive(Debug, StructOpt)]
struct Options {
#[structopt(long)]
Expand Down Expand Up @@ -84,6 +87,10 @@ async fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
let log_storage = HeedStorage::create(&storage_pth, &cfg.clone(), logger.clone())
.expect("Failed to create heed storage");

#[cfg(feature = "rocksdb_storage")]
let log_storage = RocksDBStorage::create(&storage_pth, logger.clone())
.expect("Failed to create heed storage");

let raft = Raft::bootstrap(
node_id,
options.raft_addr.clone(),
Expand Down
1 change: 0 additions & 1 deletion examples/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ pub fn build_config(node_id: u64) -> Config {
id: node_id,
election_tick: 10,
heartbeat_tick: 3,
omit_heartbeat_log: true,
..Default::default()
};

Expand Down
2 changes: 1 addition & 1 deletion raftify/src/storage/heed_storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ impl Storage for HeedStorage {

impl HeedStorage {
#[allow(dead_code)]
fn replace_entries(&mut self, entries: &[Entry]) -> raft::Result<()> {
pub fn replace_entries(&mut self, entries: &[Entry]) -> raft::Result<()> {
let store = self.wl();
let mut writer = store.env.write_txn().unwrap();
store.replace_entries(&mut writer, entries).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion raftify/src/storage/rocksdb_storage/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pub const LAST_INDEX_KEY: &[u8] = b"last_index";
pub const HARD_STATE_KEY: &[u8] = b"hard_state";
pub const CONF_STATE_KEY: &[u8] = b"conf_state";

pub const ENTRY_KEY_LENGTH: usize = 20;
pub const ENTRY_KEY_LENGTH: usize = 10;

pub const METADATA_CF_KEY: &str = "meta_data";
pub const LOG_ENTRY_CF_KEY: &str = "log_entries";
Loading

0 comments on commit 35216ae

Please sign in to comment.