@@ -9,7 +9,6 @@ use crate::raft::Entry;
9
9
use crate :: raft:: EntryPayload ;
10
10
use crate :: AppData ;
11
11
use crate :: AppDataResponse ;
12
- use crate :: LogId ;
13
12
use crate :: RaftNetwork ;
14
13
use crate :: RaftStorage ;
15
14
use crate :: Update ;
@@ -105,12 +104,12 @@ impl<D: AppData, R: AppDataResponse, N: RaftNetwork<D>, S: RaftStorage<D, R>> Ra
105
104
} ;
106
105
107
106
// The target entry was found. Compare its term with target term to ensure everything is consistent.
108
- if target_entry. term == msg. prev_log . term {
107
+ if target_entry. log_id . term == msg. prev_log . term {
109
108
// We've found a point of agreement with the leader. If we have any logs present
110
109
// with an index greater than this, then we must delete them per §5.3.
111
- if self . last_log . index > target_entry. index {
110
+ if self . last_log . index > target_entry. log_id . index {
112
111
self . storage
113
- . delete_logs_from ( target_entry. index + 1 , None )
112
+ . delete_logs_from ( target_entry. log_id . index + 1 , None )
114
113
. await
115
114
. map_err ( |err| self . map_fatal_storage_error ( err) ) ?;
116
115
let membership =
@@ -131,13 +130,8 @@ impl<D: AppData, R: AppDataResponse, N: RaftNetwork<D>, S: RaftStorage<D, R>> Ra
131
130
. get_log_entries ( start, msg. prev_log . index )
132
131
. await
133
132
. map_err ( |err| self . map_fatal_storage_error ( err) ) ?;
134
- let opt = match old_entries. iter ( ) . find ( |entry| entry. term == msg. prev_log . term ) {
135
- Some ( entry) => Some ( ConflictOpt {
136
- log_id : LogId {
137
- term : entry. term ,
138
- index : entry. index ,
139
- } ,
140
- } ) ,
133
+ let opt = match old_entries. iter ( ) . find ( |entry| entry. log_id . term == msg. prev_log . term ) {
134
+ Some ( entry) => Some ( ConflictOpt { log_id : entry. log_id } ) ,
141
135
None => Some ( ConflictOpt { log_id : self . last_log } ) ,
142
136
} ;
143
137
if report_metrics {
@@ -188,10 +182,7 @@ impl<D: AppData, R: AppDataResponse, N: RaftNetwork<D>, S: RaftStorage<D, R>> Ra
188
182
// Replicate entries to log (same as append, but in follower mode).
189
183
self . storage . replicate_to_log ( entries) . await . map_err ( |err| self . map_fatal_storage_error ( err) ) ?;
190
184
if let Some ( entry) = entries. last ( ) {
191
- self . last_log = LogId {
192
- term : entry. term ,
193
- index : entry. index ,
194
- } ;
185
+ self . last_log = entry. log_id ;
195
186
}
196
187
Ok ( ( ) )
197
188
}
@@ -204,7 +195,7 @@ impl<D: AppData, R: AppDataResponse, N: RaftNetwork<D>, S: RaftStorage<D, R>> Ra
204
195
async fn replicate_to_state_machine_if_needed ( & mut self , entries : Vec < Entry < D > > ) {
205
196
// Update cache. Always.
206
197
for entry in entries {
207
- self . entries_cache . insert ( entry. index , entry) ;
198
+ self . entries_cache . insert ( entry. log_id . index , entry) ;
208
199
}
209
200
// Perform initial replication to state machine if needed.
210
201
if !self . has_completed_initial_replication_to_sm {
@@ -222,7 +213,7 @@ impl<D: AppData, R: AppDataResponse, N: RaftNetwork<D>, S: RaftStorage<D, R>> Ra
222
213
}
223
214
// If we have no cached entries, then do nothing.
224
215
let first_idx = match self . entries_cache . iter ( ) . next ( ) {
225
- Some ( ( _, entry) ) => entry. index ,
216
+ Some ( ( _, entry) ) => entry. log_id . index ,
226
217
None => return ,
227
218
} ;
228
219
@@ -231,9 +222,9 @@ impl<D: AppData, R: AppDataResponse, N: RaftNetwork<D>, S: RaftStorage<D, R>> Ra
231
222
let entries: Vec < _ > = ( first_idx..=self . commit_index )
232
223
. filter_map ( |idx| {
233
224
if let Some ( entry) = self . entries_cache . remove ( & idx) {
234
- last_entry_seen = Some ( entry. index ) ;
225
+ last_entry_seen = Some ( entry. log_id . index ) ;
235
226
match entry. payload {
236
- EntryPayload :: Normal ( inner) => Some ( ( entry. index , inner. data ) ) ,
227
+ EntryPayload :: Normal ( inner) => Some ( ( entry. log_id . index , inner. data ) ) ,
237
228
_ => None ,
238
229
}
239
230
} else {
@@ -285,12 +276,12 @@ impl<D: AppData, R: AppDataResponse, N: RaftNetwork<D>, S: RaftStorage<D, R>> Ra
285
276
let mut new_last_applied: Option < u64 > = None ;
286
277
let entries = storage. get_log_entries ( start, stop) . await ?;
287
278
if let Some ( entry) = entries. last ( ) {
288
- new_last_applied = Some ( entry. index ) ;
279
+ new_last_applied = Some ( entry. log_id . index ) ;
289
280
}
290
281
let data_entries: Vec < _ > = entries
291
282
. iter ( )
292
283
. filter_map ( |entry| match & entry. payload {
293
- EntryPayload :: Normal ( inner) => Some ( ( & entry. index , & inner. data ) ) ,
284
+ EntryPayload :: Normal ( inner) => Some ( ( & entry. log_id . index , & inner. data ) ) ,
294
285
_ => None ,
295
286
} )
296
287
. collect ( ) ;
0 commit comments