Skip to content

Commit

Permalink
update raft-rs to 0.7.0 (#88)
Browse files Browse the repository at this point in the history
* update raft-rs to 0.7.0

* use crate.io raft

---------

Co-authored-by: Jayanring <956165026@qq.com>
  • Loading branch information
Jayanring and Jayanring authored Jul 28, 2023
1 parent 9a5fc34 commit 99e5f69
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ slog = { version = "2.7", features = ["release_max_level_trace"] }
sloggers = "2.1"
log = "0.4"
hex = "0.4"
raft = { git = "https://github.com/cita-cloud/raft-rs", version = "0.6.0", default-features = false, features = ["prost-codec"] }
raft = { version = "0.7.0", default-features = false, features = ["prost-codec"] }
prost = "0.11"
tokio = { version = "1.29", features = ["fs", "io-util", "rt", "macros"] }
serde = "1.0"
Expand Down
17 changes: 12 additions & 5 deletions src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use raft::prelude::RaftState;
use raft::prelude::Snapshot;
use raft::prelude::SnapshotMetadata;
use raft::prelude::Storage;
use raft::GetEntriesContext;
use raft::StorageError;
use slog::info;
use slog::warn;
Expand Down Expand Up @@ -265,7 +266,7 @@ impl RaftStorage {
.open(&snapshot_path)
.await
.unwrap();
let snapshot = self.snapshot(self.applied_index).unwrap();
let snapshot = self.snapshot(self.applied_index, 0).unwrap();
let mut buf = BytesMut::new();
snapshot.encode_length_delimited(&mut buf).unwrap();
file.write_all(&buf).await.unwrap();
Expand Down Expand Up @@ -346,7 +347,13 @@ impl Storage for RaftStorage {
Ok(self.entries[(idx - offset) as usize].term)
}

fn entries(&self, low: u64, high: u64, _: impl Into<Option<u64>>) -> raft::Result<Vec<Entry>> {
fn entries(
&self,
low: u64,
high: u64,
_: impl Into<Option<u64>>,
_: GetEntriesContext,
) -> raft::Result<Vec<Entry>> {
if low < self.first_index().unwrap() {
return Err(raft::Error::Store(StorageError::Compacted));
}
Expand All @@ -366,7 +373,7 @@ impl Storage for RaftStorage {
Ok(ents)
}

fn snapshot(&self, request_index: u64) -> raft::Result<Snapshot> {
fn snapshot(&self, request_index: u64, _: u64) -> raft::Result<Snapshot> {
if request_index > self.applied_index {
return Err(raft::Error::Store(
StorageError::SnapshotTemporarilyUnavailable,
Expand Down Expand Up @@ -468,7 +475,7 @@ mod tests {
let log_dir = tempdir().unwrap();
let mut store = new_store(&log_dir).await;

let snapshot = store.snapshot(0).unwrap();
let snapshot = store.snapshot(0, 0).unwrap();
store.apply_snapshot(snapshot).unwrap();
store = new_store(&log_dir).await;
assert!(store.entries.is_empty());
Expand Down Expand Up @@ -502,7 +509,7 @@ mod tests {
commit: 5,
});
store.advance_applied_index(3);
let snapshot = store.snapshot(3).unwrap();
let snapshot = store.snapshot(3, 0).unwrap();
// apply_snapshot will clear entries
store.apply_snapshot(snapshot).unwrap();
// This commit index should not shrink to 3.
Expand Down

0 comments on commit 99e5f69

Please sign in to comment.