Skip to content

Commit 625d7e9

Browse files
committed
refactor: MemStoreSnapshot: merge term and index into last_log_id: LogId
1 parent c6418cb commit 625d7e9

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

memstore/src/lib.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use async_raft::storage::HardState;
1919
use async_raft::storage::InitialState;
2020
use async_raft::AppData;
2121
use async_raft::AppDataResponse;
22+
use async_raft::LogId;
2223
use async_raft::NodeId;
2324
use async_raft::RaftStorage;
2425
use async_raft::SnapshotId;
@@ -66,10 +67,9 @@ pub enum ShutdownError {
6667
/// The application snapshot type which the `MemStore` works with.
6768
#[derive(Serialize, Deserialize, Debug, Clone)]
6869
pub struct MemStoreSnapshot {
69-
/// The last index covered by this snapshot.
70-
pub index: u64,
71-
/// The term of the last index covered by this snapshot.
72-
pub term: u64,
70+
/// The last log covered by this snapshot.
71+
pub last_log_id: LogId,
72+
7373
/// The last memberhsip config included in this snapshot.
7474
pub membership: MembershipConfig,
7575

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

340340
snapshot_id = format!("{}-{}-{}", term, last_applied_log, snapshot_idx);
341341
let snapshot = MemStoreSnapshot {
342-
index: last_applied_log,
343-
term,
342+
last_log_id: LogId {
343+
term,
344+
index: last_applied_log,
345+
},
344346
snapshot_id: snapshot_id.clone(),
345347
membership: membership_config.clone(),
346348
data,
@@ -433,7 +435,7 @@ impl RaftStorage<ClientRequest, ClientResponse> for MemStore {
433435
Some(snapshot) => {
434436
let reader = serde_json::to_vec(&snapshot)?;
435437
Ok(Some(CurrentSnapshotData {
436-
last_log_id: (snapshot.term, snapshot.index).into(),
438+
last_log_id: snapshot.last_log_id,
437439
membership: snapshot.membership.clone(),
438440
snapshot_id: snapshot.snapshot_id.clone(),
439441
snapshot: Box::new(Cursor::new(reader)),

0 commit comments

Comments
 (0)