Skip to content

Commit 39a9087

Browse files
committed
fixes
1 parent 7e612b8 commit 39a9087

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
@@ -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}]};

src/ra_server_proc.erl

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

0 commit comments

Comments
 (0)