Commit 81f445b
committed
raft: refresh election timer on recovery-path append_entries
A follower that is behind a live leader can get stuck in a perpetual
pre-vote storm. `should_skip_vote` suppresses elections only while
`_hbeat` (last leader contact) is within one election timeout, but in
`do_append_entries` the `_hbeat` refresh lives on the successful
batch-append path (a deferred update). The two early returns that fire
when the follower is behind, log gap (prev_log_index > last_log_offset)
and prev-log-term mismatch, call maybe_update_leader() and reply to the
leader but never refresh `_hbeat`.
So a follower in continuous contact with the current-term leader, but
unable to append because it is still being recovered, lets its election
timer expire, starts a (pre-)vote that deterministically fails the
longest-log check (log_ok=false), rearms, and repeats. The storm burns
CPU that further starves recovery, a self-reinforcing livelock that
leaves partitions under-replicated and stalls acks=all produce with
REQUEST_TIMED_OUT.
Refresh `_hbeat` as soon as an append_entries from the current-term
leader is accepted (right after maybe_update_leader), covering the
recovery early-return paths as well as the success path. This matches
the existing design intent noted in vote_request handling, where the
comment states `_hbeat` is updated by the leader. Liveness is preserved:
if the leader is actually gone, no append_entries arrive, `_hbeat` goes
stale, and elections proceed as before.
Fixes #30815
Signed-off-by: Steven Pall <mail@stevenpall.ca>1 parent 84702c7 commit 81f445b
1 file changed
Lines changed: 2 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2052 | 2052 | | |
2053 | 2053 | | |
2054 | 2054 | | |
| 2055 | + | |
| 2056 | + | |
2055 | 2057 | | |
2056 | 2058 | | |
2057 | 2059 | | |
| |||
2307 | 2309 | | |
2308 | 2310 | | |
2309 | 2311 | | |
2310 | | - | |
2311 | | - | |
2312 | | - | |
2313 | | - | |
2314 | | - | |
2315 | 2312 | | |
2316 | 2313 | | |
2317 | 2314 | | |
| |||
0 commit comments