Skip to content

Commit

Permalink
Fix: fix reviewer comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ariesdevil committed Aug 11, 2024
1 parent c4cd86b commit 7ccd1f3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions examples/raft-kv-memstore-opendal-snapshot-data/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ repository = "https://github.com/datafuselabs/openraft"
memstore = { path = "../memstore", features = [] }
openraft = { path = "../../openraft", features = ["serde", "type-alias"] }

bytes = "1.0"
serde = { version = "1.0.114", features = ["derive"] }
serde_json = "1.0.57"
tokio = { version = "1.0", default-features = false, features = ["sync"] }
Expand Down
6 changes: 6 additions & 0 deletions examples/raft-kv-memstore-opendal-snapshot-data/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

use std::sync::Arc;

use bytes::Buf;
use opendal::Buffer;
use opendal::Operator;
use openraft::Config;

Expand Down Expand Up @@ -68,6 +70,10 @@ pub fn decode<T: serde::de::DeserializeOwned>(s: &str) -> T {
serde_json::from_str(s).unwrap()
}

pub fn decode_buffer<T: serde::de::DeserializeOwned>(b: Buffer) -> T {
serde_json::from_reader(b.reader()).unwrap()
}

pub async fn new_raft(node_id: NodeId, router: Router, op: Operator) -> (typ::Raft, App) {
// Create a configuration for the raft instance.
let config = Config {
Expand Down
4 changes: 2 additions & 2 deletions examples/raft-kv-memstore-opendal-snapshot-data/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use openraft::StoredMembership;
use serde::Deserialize;
use serde::Serialize;

use crate::decode;
use crate::decode_buffer;
use crate::encode;
use crate::typ;
use crate::NodeId;
Expand Down Expand Up @@ -209,7 +209,7 @@ impl RaftStateMachine<TypeConfig> for Arc<StateMachineStore> {
// Update the state machine.
{
let bs = self.storage.read(&new_snapshot.data).await.unwrap();
let updated_state_machine: StateMachineData = decode(&String::from_utf8_lossy(bs.to_vec().as_slice()));
let updated_state_machine: StateMachineData = decode_buffer(bs);
let mut state_machine = self.state_machine.lock().unwrap();
*state_machine = updated_state_machine;
}
Expand Down

0 comments on commit 7ccd1f3

Please sign in to comment.