Ivan Andika created RATIS-2845:
----------------------------------
Summary: Rejected or term-mismatched AppendEntries replies must
not renew leader-lease evidence
Key: RATIS-2845
URL: https://issues.apache.org/jira/browse/RATIS-2845
Project: Ratis
Issue Type: Improvement
Reporter: Ivan Andika
Assignee: Ivan Andika
Both log appender implementations previously refreshed the follower timestamp
used as leader-lease evidence whenever an AppendEntries RPC returned. This
included `NOT_LEADER` replies and replies whose term did not match the
request's leader term.
Receiving a response is not sufficient evidence that a follower still
recognizes the requesting leader. A delayed rejection must not extend that
leader's authority to serve reads.
h2. Reproduction
1. Record a follower's existing `lastRespondedAppendEntriesSendTime`.
2. Send an AppendEntries request in term 1.
3. Deliver a reply with `NOT_LEADER`, first with term 1 and then with term 2.
4. Inspect the timestamp used by the lease computation. The pre-fix code
advances it despite the rejection.
5. For gRPC, also deliver `SUCCESS` with reply term 2 for the pending term-1
request. This must not count as a term-1 acknowledgement.
6. As controls, deliver `SUCCESS` and `INCONSISTENCY` replies in term 1. Both
should count: a same-term log inconsistency can acknowledge leadership while
rejecting the log position.
h2. Expected behavior and impact
Only `SUCCESS` or `INCONSISTENCY` in the request's leader term may update lease
acknowledgement evidence. General RPC-response timestamps may still advance
independently.
The deterministic regressions directly demonstrate invalid lease-timestamp
updates. They do not constitute a separate captured end-to-end stale-read
history for this specific race; the safety concern is that the lease fast path
is using evidence that does not establish leadership.
h2. Root cause
The default appender updated the timestamp before validating the reply. The
gRPC callback did the same when matching a pending request, without preserving
and checking that request's leader term.
h2. Proposed fix
Check both the result and term before recording the request's send time as
lease evidence. Retain the leader term in pending gRPC request metadata. Keep
ordinary response bookkeeping separate from acknowledgement of leadership.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)