Skip to content

Commit 3aa50f2

Browse files
Fix log divergence bug (#508)
* Fix log divergence bug. When a follower with uncommitted entries in a prior term when it was leader receives certain append entry rpc combinations it would incorrectly increment and evalaute the leader's commit index and in some cases apply uncommitted entries. This commit ensures that the commit index is only incremented and evaluated _if_ the local log's last index is validated against the leaders's log. Also handle the case where a snapshot with an index lower than the follower's last applied index would cause the replication to this follower to stop. * reset open segment counter on init * Update src/ra_server.erl Co-authored-by: Michael Davis <[email protected]> * Update src/ra_server.erl Co-authored-by: Michael Davis <[email protected]> * Update src/ra_server.erl Co-authored-by: Michael Davis <[email protected]> --------- Co-authored-by: Michael Davis <[email protected]>
1 parent 4a0f8f4 commit 3aa50f2

File tree

4 files changed

+295
-111
lines changed

4 files changed

+295
-111
lines changed

src/ra_log_reader.erl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ init(UId, Dir, MaxOpen, AccessPattern, SegRefs0, #{}, Counter)
8787
undefined
8888
end,
8989
SegRefsRev = lists:reverse(SegRefs),
90+
reset_counter(Cfg, ?C_RA_LOG_OPEN_SEGMENTS),
9091
#?STATE{cfg = Cfg,
9192
open_segments = ra_flru:new(MaxOpen, FlruHandler),
9293
range = Range,
@@ -434,6 +435,12 @@ limit(LimitIdx, [{PrevRange, PrevFn} | PrevRem]) ->
434435
[{NewPrevRange, PrevFn} | PrevRem]
435436
end.
436437

438+
reset_counter(#cfg{counter = Cnt}, Ix)
439+
when Cnt =/= undefined ->
440+
counters:put(Cnt, Ix, 0);
441+
reset_counter(#cfg{counter = undefined}, _) ->
442+
ok.
443+
437444
incr_counter(#cfg{counter = Cnt}, Ix, N) when Cnt =/= undefined ->
438445
counters:add(Cnt, Ix, N);
439446
incr_counter(#cfg{counter = undefined}, _, _) ->

0 commit comments

Comments
 (0)