Skip to content

Commit

Permalink
Update apply_snapshot in MemStorage
Browse files Browse the repository at this point in the history
  • Loading branch information
jopemachine committed Sep 23, 2024
1 parent 09790b0 commit aa84a37
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 4 additions & 1 deletion raftify/src/raft_node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
},
Expand Down
9 changes: 9 additions & 0 deletions raftify/src/storage/inmemory_storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::{
self,
eraftpb::{ConfState, Entry, HardState, Snapshot},
storage::{MemStorage as MemStorageCore, Storage},
INVALID_INDEX,
},
StableStorage,
};
Expand Down Expand Up @@ -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(())
}
Expand Down

0 comments on commit aa84a37

Please sign in to comment.