Skip to content

Commit 606805e

Browse files
committed
fixes
1 parent fd1a3fb commit 606805e

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/ra_server.erl

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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}]};

src/ra_server_proc.erl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1946,6 +1946,8 @@ send_snapshots(Id, Term, {_, ToNode} = To, ChunkSize,
19461946
[LogId, To, TheirMacVer, SnapMacVer]),
19471947
ok;
19481948
false ->
1949+
%% TODO: this could be stale, replace with a call into the
1950+
%% process insted perhaps?
19491951
#{last_applied := LastApplied} = erpc:call(ToNode,
19501952
ra_counters,
19511953
counters,

0 commit comments

Comments
 (0)