@@ -58,8 +58,8 @@ impl<D: AppData, R: AppDataResponse, N: RaftNetwork<D>, S: RaftStorage<D, R>> Ra
58
58
// Then it will update commit_index to 3 and apply {2,3}
59
59
60
60
// TODO(xp): cleanup commit index at sender side.
61
- let valid_commit_index = msg_entries. last ( ) . map ( |x| x. log_id ) . unwrap_or_else ( || msg. prev_log_id ) . index ;
62
- let valid_commit_index = std:: cmp:: min ( msg. leader_commit , valid_commit_index) ;
61
+ let valid_commit_index = msg_entries. last ( ) . map ( |x| x. log_id ) . unwrap_or_else ( || msg. prev_log_id ) ;
62
+ let valid_committed = std:: cmp:: min ( msg. leader_commit , valid_commit_index) ;
63
63
64
64
tracing:: debug!( "start to check and update to latest term/leader" ) ;
65
65
{
@@ -94,7 +94,7 @@ impl<D: AppData, R: AppDataResponse, N: RaftNetwork<D>, S: RaftStorage<D, R>> Ra
94
94
// +----------------+------------------------+
95
95
// ` 0 ` last_applied ` last_log_id
96
96
97
- return self . append_apply_log_entries ( & msg. prev_log_id , msg_entries, valid_commit_index ) . await ;
97
+ return self . append_apply_log_entries ( & msg. prev_log_id , msg_entries, valid_committed ) . await ;
98
98
}
99
99
100
100
#[ tracing:: instrument( level = "debug" , skip( self ) ) ]
@@ -227,13 +227,13 @@ impl<D: AppData, R: AppDataResponse, N: RaftNetwork<D>, S: RaftStorage<D, R>> Ra
227
227
& mut self ,
228
228
prev_log_id : & LogId ,
229
229
entries : & [ Entry < D > ] ,
230
- commit_index : u64 ,
230
+ committed : LogId ,
231
231
) -> RaftResult < AppendEntriesResponse > {
232
232
let matching = self . does_log_id_match ( prev_log_id) . await ?;
233
233
tracing:: debug!(
234
- "check prev_log_id {} match: commit_index : {}, matches: {}" ,
234
+ "check prev_log_id {} match: committed : {}, matches: {}" ,
235
235
prev_log_id,
236
- self . commit_index ,
236
+ self . committed ,
237
237
matching,
238
238
) ;
239
239
@@ -263,7 +263,7 @@ impl<D: AppData, R: AppDataResponse, N: RaftNetwork<D>, S: RaftStorage<D, R>> Ra
263
263
let ( n_matching, entries) = self . skip_matching_entries ( entries) . await ?;
264
264
265
265
tracing:: debug!(
266
- commit_index = self . commit_index ,
266
+ % self . committed ,
267
267
n_matching,
268
268
entries = %entries. summary( ) ,
269
269
"skip matching entries" ,
@@ -278,7 +278,7 @@ impl<D: AppData, R: AppDataResponse, N: RaftNetwork<D>, S: RaftStorage<D, R>> Ra
278
278
279
279
// commit index must not > last_log_id.index
280
280
// This is guaranteed by caller.
281
- self . commit_index = commit_index ;
281
+ self . committed = committed ;
282
282
283
283
self . replicate_to_state_machine_if_needed ( ) . await ?;
284
284
@@ -306,7 +306,7 @@ impl<D: AppData, R: AppDataResponse, N: RaftNetwork<D>, S: RaftStorage<D, R>> Ra
306
306
let log_id = entries[ i] . log_id ;
307
307
let index = log_id. index ;
308
308
309
- if index <= self . commit_index {
309
+ if index <= self . committed . index {
310
310
continue ;
311
311
}
312
312
@@ -333,7 +333,7 @@ impl<D: AppData, R: AppDataResponse, N: RaftNetwork<D>, S: RaftStorage<D, R>> Ra
333
333
let index = remote_log_id. index ;
334
334
335
335
// Committed entries are always safe and are consistent to a valid leader.
336
- if index <= self . commit_index {
336
+ if index <= self . committed . index {
337
337
return Ok ( true ) ;
338
338
}
339
339
@@ -410,10 +410,10 @@ impl<D: AppData, R: AppDataResponse, N: RaftNetwork<D>, S: RaftStorage<D, R>> Ra
410
410
}
411
411
412
412
// If we don't have any new entries to replicate, then do nothing.
413
- if self . commit_index <= self . last_applied . index {
413
+ if self . committed <= self . last_applied {
414
414
tracing:: debug!(
415
- "commit_index ({}) <= last_applied({}), return" ,
416
- self . commit_index ,
415
+ "committed ({}) <= last_applied({}), return" ,
416
+ self . committed ,
417
417
self . last_applied
418
418
) ;
419
419
return Ok ( ( ) ) ;
@@ -423,7 +423,7 @@ impl<D: AppData, R: AppDataResponse, N: RaftNetwork<D>, S: RaftStorage<D, R>> Ra
423
423
424
424
let entries = self
425
425
. storage
426
- . get_log_entries ( self . last_applied . index + 1 ..=self . commit_index )
426
+ . get_log_entries ( self . last_applied . index + 1 ..=self . committed . index )
427
427
. await
428
428
. map_err ( |e| self . map_storage_error ( e) ) ?;
429
429
@@ -452,11 +452,11 @@ impl<D: AppData, R: AppDataResponse, N: RaftNetwork<D>, S: RaftStorage<D, R>> Ra
452
452
/// from the AppendEntries RPC handler.
453
453
#[ tracing:: instrument( level = "debug" , skip( self ) ) ]
454
454
async fn initial_replicate_to_state_machine ( & mut self ) -> Result < ( ) , RaftError > {
455
- let stop = std:: cmp:: min ( self . commit_index , self . last_log_id . index ) + 1 ;
455
+ let stop = std:: cmp:: min ( self . committed . index , self . last_log_id . index ) + 1 ;
456
456
let start = self . last_applied . index + 1 ;
457
457
let storage = self . storage . clone ( ) ;
458
458
459
- tracing:: debug!( start, stop, self . commit_index , %self . last_log_id, "start stop" ) ;
459
+ tracing:: debug!( start, stop, % self . committed , %self . last_log_id, "start stop" ) ;
460
460
461
461
// when self.commit_index is not initialized, e.g. the first heartbeat from leader always has a commit_index to
462
462
// be 0, because the leader needs one round of heartbeat to find out the commit index.
0 commit comments