Skip to content

Commit 954c67a

Browse files
committed
change: InstallSnapshotRequest: merge last_included{term,index} into last_included
1 parent cf4badd commit 954c67a

File tree

4 files changed

+18
-14
lines changed

4 files changed

+18
-14
lines changed

async-raft/src/core/install_snapshot.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,15 @@ impl<D: AppData, R: AppDataResponse, N: RaftNetwork<D>, S: RaftStorage<D, R>> Ra
145145
mut snapshot: Box<S::Snapshot>,
146146
) -> RaftResult<()> {
147147
snapshot.as_mut().shutdown().await.map_err(|err| self.map_fatal_storage_error(err.into()))?;
148-
let delete_through = if self.last_log_index > req.last_included_index {
149-
Some(req.last_included_index)
148+
let delete_through = if self.last_log_index > req.last_included.index {
149+
Some(req.last_included.index)
150150
} else {
151151
None
152152
};
153153
self.storage
154154
.finalize_snapshot_installation(
155-
req.last_included_index,
156-
req.last_included_term,
155+
req.last_included.index,
156+
req.last_included.term,
157157
delete_through,
158158
id,
159159
snapshot,
@@ -162,10 +162,10 @@ impl<D: AppData, R: AppDataResponse, N: RaftNetwork<D>, S: RaftStorage<D, R>> Ra
162162
.map_err(|err| self.map_fatal_storage_error(err))?;
163163
let membership = self.storage.get_membership_config().await.map_err(|err| self.map_fatal_storage_error(err))?;
164164
self.update_membership(membership)?;
165-
self.last_log_index = req.last_included_index;
166-
self.last_log_term = req.last_included_term;
167-
self.last_applied = req.last_included_index;
168-
self.snapshot_index = req.last_included_index;
165+
self.last_log_index = req.last_included.index;
166+
self.last_log_term = req.last_included.term;
167+
self.last_applied = req.last_included.index;
168+
self.snapshot_index = req.last_included.index;
169169
Ok(())
170170
}
171171
}

async-raft/src/raft.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use crate::metrics::RaftMetrics;
2424
use crate::metrics::Wait;
2525
use crate::AppData;
2626
use crate::AppDataResponse;
27+
use crate::LogId;
2728
use crate::NodeId;
2829
use crate::RaftNetwork;
2930
use crate::RaftStorage;
@@ -575,10 +576,8 @@ pub struct InstallSnapshotRequest {
575576
pub term: u64,
576577
/// The leader's ID. Useful in redirecting clients.
577578
pub leader_id: u64,
578-
/// The snapshot replaces all log entries up through and including this index.
579-
pub last_included_index: u64,
580-
/// The term of the `last_included_index`.
581-
pub last_included_term: u64,
579+
/// The snapshot replaces all log entries up through and including this log.
580+
pub last_included: LogId,
582581
/// The byte offset where this chunk of data is positioned in the snapshot file.
583582
pub offset: u64,
584583
/// The raw bytes of the snapshot chunk, starting at `offset`.

async-raft/src/raft_types.rs

+6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ pub struct LogId {
99
pub index: u64,
1010
}
1111

12+
impl From<(u64, u64)> for LogId {
13+
fn from(v: (u64, u64)) -> Self {
14+
LogId { term: v.0, index: v.1 }
15+
}
16+
}
17+
1218
// An update action with option to update with some value or just ignore this update.
1319
#[derive(Debug, Clone, PartialOrd, PartialEq, Eq, Serialize, Deserialize)]
1420
pub enum Update<T> {

async-raft/src/replication/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -856,8 +856,7 @@ impl<'a, D: AppData, R: AppDataResponse, N: RaftNetwork<D>, S: RaftStorage<D, R>
856856
let req = InstallSnapshotRequest {
857857
term: self.core.term,
858858
leader_id: self.core.id,
859-
last_included_index: snapshot.index,
860-
last_included_term: snapshot.term,
859+
last_included: (snapshot.term, snapshot.index).into(),
861860
offset,
862861
data: Vec::from(&buf[..nread]),
863862
done,

0 commit comments

Comments
 (0)