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