Skip to content

Commit

Permalink
refactor: MemStoreSnapshot: merge term and index into last_log_id: LogId
Browse files Browse the repository at this point in the history
  • Loading branch information
drmingdrmer committed Jul 12, 2021
1 parent c6418cb commit 625d7e9
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions memstore/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use async_raft::storage::HardState;
use async_raft::storage::InitialState;
use async_raft::AppData;
use async_raft::AppDataResponse;
use async_raft::LogId;
use async_raft::NodeId;
use async_raft::RaftStorage;
use async_raft::SnapshotId;
Expand Down Expand Up @@ -66,10 +67,9 @@ pub enum ShutdownError {
/// The application snapshot type which the `MemStore` works with.
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct MemStoreSnapshot {
/// The last index covered by this snapshot.
pub index: u64,
/// The term of the last index covered by this snapshot.
pub term: u64,
/// The last log covered by this snapshot.
pub last_log_id: LogId,

/// The last memberhsip config included in this snapshot.
pub membership: MembershipConfig,

Expand Down Expand Up @@ -339,8 +339,10 @@ impl RaftStorage<ClientRequest, ClientResponse> for MemStore {

snapshot_id = format!("{}-{}-{}", term, last_applied_log, snapshot_idx);
let snapshot = MemStoreSnapshot {
index: last_applied_log,
term,
last_log_id: LogId {
term,
index: last_applied_log,
},
snapshot_id: snapshot_id.clone(),
membership: membership_config.clone(),
data,
Expand Down Expand Up @@ -433,7 +435,7 @@ impl RaftStorage<ClientRequest, ClientResponse> for MemStore {
Some(snapshot) => {
let reader = serde_json::to_vec(&snapshot)?;
Ok(Some(CurrentSnapshotData {
last_log_id: (snapshot.term, snapshot.index).into(),
last_log_id: snapshot.last_log_id,
membership: snapshot.membership.clone(),
snapshot_id: snapshot.snapshot_id.clone(),
snapshot: Box::new(Cursor::new(reader)),
Expand Down

0 comments on commit 625d7e9

Please sign in to comment.