Skip to content

Commit ed46f0d

Browse files
committed
handle missing segments event after follower recovery
1 parent b738d2b commit ed46f0d

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
@@ -407,6 +407,7 @@ init(#{id := Id,
407407
maps:get(membership, Config, voter)),
408408

409409
#{cfg => Cfg,
410+
leader_id => undefined,
410411
current_term => CurrentTerm,
411412
cluster => Cluster0,
412413
% There may be scenarios when a single server
@@ -1342,8 +1343,8 @@ handle_follower(#heartbeat_rpc{leader_id = LeaderId,
13421343
{follower, State, [cast_reply(Id, LeaderId, Reply)]};
13431344
handle_follower({ra_log_event, Evt}, #{log := Log0,
13441345
cfg := #cfg{id = Id},
1345-
leader_id := LeaderId,
13461346
current_term := Term} = State0) ->
1347+
LeaderId = maps:get(leader_id, State0, undefined),
13471348
% forward events to ra_log
13481349
% if the last written changes then send an append entries reply
13491350
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)