diff --git a/raftify/src/raft_node/mod.rs b/raftify/src/raft_node/mod.rs index 9c1f2593..3c038b41 100644 --- a/raftify/src/raft_node/mod.rs +++ b/raftify/src/raft_node/mod.rs @@ -51,7 +51,10 @@ use crate::{ ResponseMessage, }, storage::{ - heed_storage::{utils::{get_data_mdb_path, get_storage_path}, HeedStorage}, + heed_storage::{ + utils::{get_data_mdb_path, get_storage_path}, + HeedStorage, + }, inmemory_storage::MemStorage, utils::{clear_storage_path, ensure_directory_exist}, }, diff --git a/raftify/src/storage/inmemory_storage/mod.rs b/raftify/src/storage/inmemory_storage/mod.rs index 65c47470..c4adef3a 100644 --- a/raftify/src/storage/inmemory_storage/mod.rs +++ b/raftify/src/storage/inmemory_storage/mod.rs @@ -4,6 +4,7 @@ use crate::{ self, eraftpb::{ConfState, Entry, HardState, Snapshot}, storage::{MemStorage as MemStorageCore, Storage}, + INVALID_INDEX, }, StableStorage, }; @@ -71,6 +72,14 @@ impl StableStorage for MemStorage { fn apply_snapshot(&mut self, snapshot: Snapshot) -> Result<()> { let mut store = self.core.wl(); + + // Pass apply snapshot if the snapshot is empty + if snapshot.get_metadata().get_index() == INVALID_INDEX { + // Update conf states. + store.set_conf_state(snapshot.get_metadata().clone().take_conf_state()); + return Ok(()); + } + store.apply_snapshot(snapshot)?; Ok(()) }