Skip to content

Commit 7207b2c

Browse files
committed
handle missing segments event after follower recovery
1 parent 6940b57 commit 7207b2c

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/ra_server.erl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ init(#{id := Id,
405405
maps:get(membership, Config, voter)),
406406

407407
#{cfg => Cfg,
408+
leader_id => undefined,
408409
current_term => CurrentTerm,
409410
cluster => Cluster0,
410411
% There may be scenarios when a single server
@@ -1340,8 +1341,8 @@ handle_follower(#heartbeat_rpc{leader_id = LeaderId,
13401341
{follower, State, [cast_reply(Id, LeaderId, Reply)]};
13411342
handle_follower({ra_log_event, Evt}, #{log := Log0,
13421343
cfg := #cfg{id = Id},
1343-
leader_id := LeaderId,
13441344
current_term := Term} = State0) ->
1345+
LeaderId = maps:get(leader_id, State0, undefined),
13451346
% forward events to ra_log
13461347
% if the last written changes then send an append entries reply
13471348
LW = ra_log:last_written(Log0),

test/ra_log_2_SUITE.erl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1832,9 +1832,10 @@ sparse_write(Config) ->
18321832
SnapState0 = ra_log:snapshot_state(Log2),
18331833
{ok, SnapState1} = ra_snapshot:begin_accept(Meta, SnapState0),
18341834
Machine = {machine, ?MODULE, #{}},
1835-
{SnapState, _, LiveIndexes, AEffs} = ra_snapshot:complete_accept(Chunk, 1,
1836-
Machine,
1837-
SnapState1),
1835+
{SnapState, _, LiveIndexesSeq, AEffs} = ra_snapshot:complete_accept(Chunk, 1,
1836+
Machine,
1837+
SnapState1),
1838+
?assertEqual(LiveIndexes, lists:reverse(ra_seq:expand(LiveIndexesSeq))),
18381839
run_effs(AEffs),
18391840
Log3 = ra_log:set_snapshot_state(SnapState, Log2),
18401841
{ok, Log4, _} = ra_log:install_snapshot({15, 2}, ?MODULE,

0 commit comments

Comments
 (0)