@@ -444,11 +444,11 @@ recover(#{cfg := #cfg{log_id = LogId,
444444 {#{log := Log0 ,
445445 cfg := # cfg {effective_machine_version = EffMacVerAfter }} = State1 , _ } =
446446 apply_to (CommitIndex ,
447- fun ({Idx , _ , _ } = E , S0 ) ->
447+ fun ({_Idx , _ , _ } = E , S0 ) ->
448448 % % Clear out the effects and notifies map
449449 % % to avoid memory explosion
450450 {Mod , LastAppl , S , MacSt , _E , _N , LastTs } = apply_with (E , S0 ),
451- put_counter (Cfg , ? C_RA_SVR_METRIC_LAST_APPLIED , Idx ),
451+ put_counter (Cfg , ? C_RA_SVR_METRIC_LAST_APPLIED , LastAppl ),
452452 {Mod , LastAppl , S , MacSt , [], #{}, LastTs }
453453 end ,
454454 State0 , []),
@@ -1582,10 +1582,13 @@ handle_receive_snapshot(#install_snapshot_rpc{term = Term,
15821582 % % are of the right term
15831583 {LastIdx , _ } = ra_log :last_index_term (Log00 ),
15841584 {Log , _ } = lists :foldl (
1585- fun ({I , _ , _ } = E , {L0 , LstIdx }) ->
1586- {ok , L } = ra_log :write_sparse (E , LstIdx , L0 ),
1587- {L , I }
1588- end , {Log00 , LastIdx }, ChunkOrEntries ),
1585+ fun ({I , _ , _ } = E , {L0 , LstIdx }) when I > LastApplied ->
1586+ {ok , L } = ra_log :write_sparse (E , LstIdx , L0 ),
1587+ {L , I };
1588+ (_ , Acc ) ->
1589+ % % drop any entries that are lower than last applied
1590+ Acc
1591+ end , {Log00 , LastIdx }, ChunkOrEntries ),
15891592 State = update_term (Term , State0 #{log => Log ,
15901593 snapshot_phase => pre }),
15911594 {receive_snapshot , State , [{reply , Reply }]};
0 commit comments