Skip to content

Commit 055af12

Browse files
hsun324facebook-github-bot
authored andcommitted
Always update leader live or stale if necessary
Summary: Separate the checks for whether or not leader's live or stale info needs to be updated. Reviewed By: jaher Differential Revision: D80632772 fbshipit-source-id: e3e8c7577dc7c247171a9ae8f849e5363198790d
1 parent 42d5d30 commit 055af12

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/wa_raft_server.erl

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3432,18 +3432,28 @@ check_leader_liveness(
34323432
NowTs = erlang:monotonic_time(millisecond),
34333433
QuorumTs = compute_quorum(HeartbeatResponse#{node() => NowTs}, 0, config(State)),
34343434

3435+
% If the quorum of the most recent timestamps of follower's acknowledgement
3436+
% of heartbeats is too old, then the leader is considered stale.
34353437
QuorumAge = NowTs - QuorumTs,
34363438
MaxAge = ?RAFT_LEADER_STALE_INTERVAL(App),
3439+
ShouldBeStale = QuorumAge >= MaxAge,
3440+
ShouldBeLive = not ShouldBeStale,
34373441

3438-
case QuorumAge >= MaxAge of
3442+
% Update liveness if necessary
3443+
wa_raft_info:get_live(Table, Partition) =/= ShouldBeLive andalso
3444+
wa_raft_info:set_live(Table, Partition, ShouldBeLive),
3445+
3446+
% Update staleness if necessary
3447+
Stale = wa_raft_info:get_stale(Table, Partition),
3448+
case ShouldBeStale of
3449+
Stale ->
3450+
ok;
34393451
true ->
34403452
?SERVER_LOG_NOTICE(leader, State, "is now stale due to last heartbeat quorum age being ~0p ms >= ~0p ms max", [QuorumAge, MaxAge]),
3441-
wa_raft_info:set_live(Table, Partition, false),
3442-
wa_raft_info:set_stale(Table, Partition, true);
3453+
wa_raft_info:set_stale(Table, Partition, ShouldBeStale);
34433454
false ->
34443455
?SERVER_LOG_NOTICE(leader, State, "is no longer stale after heartbeat quorum age drops to ~0p ms < ~0p ms max", [QuorumAge, MaxAge]),
3445-
wa_raft_info:set_live(Table, Partition, true),
3446-
wa_raft_info:set_stale(Table, Partition, false)
3456+
wa_raft_info:set_stale(Table, Partition, ShouldBeStale)
34473457
end.
34483458

34493459
%% Based on information that the leader has available as a result of heartbeat replies, attempt

0 commit comments

Comments
 (0)