@@ -84,13 +84,15 @@ pub struct RaftCore<D: AppData, R: AppDataResponse, N: RaftNetwork<D>, S: RaftSt
84
84
/// Is initialized to 0, and increases monotonically. This is always based on the leader's
85
85
/// commit index which is communicated to other members via the AppendEntries protocol.
86
86
commit_index : u64 ,
87
- /// The index of the highest log entry which has been applied to the local state machine.
87
+
88
+ /// The log id of the highest log entry which has been applied to the local state machine.
88
89
///
89
- /// Is initialized to 0 for a pristine node; else, for nodes with existing state it is
90
+ /// Is initialized to 0,0 for a pristine node; else, for nodes with existing state it is
90
91
/// is initialized to the value returned from the `RaftStorage::get_initial_state` on startup.
91
92
/// This value increases following the `commit_index` as logs are applied to the state
92
93
/// machine (via the storage interface).
93
- last_applied : u64 ,
94
+ last_applied : LogId ,
95
+
94
96
/// The current term.
95
97
///
96
98
/// Is initialized to 0 on first boot, and increases monotonically. This is normally based on
@@ -130,7 +132,7 @@ pub struct RaftCore<D: AppData, R: AppDataResponse, N: RaftNetwork<D>, S: RaftSt
130
132
/// This abstraction is needed to ensure that replicating to the state machine does not block
131
133
/// the AppendEntries RPC flow, and to ensure that we have a smooth transition to becoming
132
134
/// leader without concern over duplicate application of entries to the state machine.
133
- replicate_to_sm_handle : FuturesOrdered < JoinHandle < anyhow:: Result < Option < u64 > > > > ,
135
+ replicate_to_sm_handle : FuturesOrdered < JoinHandle < anyhow:: Result < Option < LogId > > > > ,
134
136
/// A bool indicating if this system has performed its initial replication of
135
137
/// outstanding entries to the state machine.
136
138
has_completed_initial_replication_to_sm : bool ,
@@ -168,7 +170,7 @@ impl<D: AppData, R: AppDataResponse, N: RaftNetwork<D>, S: RaftStorage<D, R>> Ra
168
170
storage,
169
171
target_state : State :: Follower ,
170
172
commit_index : 0 ,
171
- last_applied : 0 ,
173
+ last_applied : LogId { term : 0 , index : 0 } ,
172
174
current_term : 0 ,
173
175
current_leader : None ,
174
176
voted_for : None ,
@@ -281,7 +283,7 @@ impl<D: AppData, R: AppDataResponse, N: RaftNetwork<D>, S: RaftStorage<D, R>> Ra
281
283
state : self . target_state ,
282
284
current_term : self . current_term ,
283
285
last_log_index : self . last_log_id . index ,
284
- last_applied : self . last_applied ,
286
+ last_applied : self . last_applied . index ,
285
287
current_leader : self . current_leader ,
286
288
membership_config : self . membership . clone ( ) ,
287
289
snapshot : self . snapshot_last_log_id ,
@@ -425,13 +427,13 @@ impl<D: AppData, R: AppDataResponse, N: RaftNetwork<D>, S: RaftStorage<D, R>> Ra
425
427
}
426
428
let SnapshotPolicy :: LogsSinceLast ( threshold) = & self . config . snapshot_policy ;
427
429
// Check to ensure we have actual entries for compaction.
428
- if self . last_applied == 0 || self . last_applied < self . snapshot_last_log_id . index {
430
+ if self . last_applied . index == 0 || self . last_applied . index < self . snapshot_last_log_id . index {
429
431
return ;
430
432
}
431
433
432
434
if !force {
433
435
// If we are below the threshold, then there is nothing to do.
434
- if self . last_applied < self . snapshot_last_log_id . index + * threshold {
436
+ if self . last_applied . index < self . snapshot_last_log_id . index + * threshold {
435
437
return ;
436
438
}
437
439
}
@@ -471,7 +473,7 @@ impl<D: AppData, R: AppDataResponse, N: RaftNetwork<D>, S: RaftStorage<D, R>> Ra
471
473
472
474
/// Handle the output of an async task replicating entries to the state machine.
473
475
#[ tracing:: instrument( level = "trace" , skip( self , res) ) ]
474
- pub ( self ) fn handle_replicate_to_sm_result ( & mut self , res : anyhow:: Result < Option < u64 > > ) -> RaftResult < ( ) > {
476
+ pub ( self ) fn handle_replicate_to_sm_result ( & mut self , res : anyhow:: Result < Option < LogId > > ) -> RaftResult < ( ) > {
475
477
let last_applied_opt = res. map_err ( |err| self . map_fatal_storage_error ( err) ) ?;
476
478
if let Some ( last_applied) = last_applied_opt {
477
479
self . last_applied = last_applied;
0 commit comments