Ivan Andika created RATIS-2846:
----------------------------------
Summary: REPLIED_INDEX can let a later follower read return older
state than a completed leader read
Key: RATIS-2846
URL: https://issues.apache.org/jira/browse/RATIS-2846
Project: Ratis
Issue Type: Bug
Reporter: Ivan Andika
Assignee: Ivan Andika
The Porcupine counter workload captured a completed leader read returning
**12**, followed by a newly invoked follower read returning **11**. Both were
requested as linearizable reads. The reads do not overlap, so their results
cannot be explained by reordering concurrent reads.
A write need not have replied for this to be invalid. Once the completed leader
read exposes that write, any subsequently invoked read must respect that
observation.
h2. Deterministic reproduction
1. Enable linearizable reads and select `Read.ReadIndex.Type.REPLIED_INDEX`.
2. Start with a counter value of 0 and initialize the read clients before
introducing the fault.
3. Block `ReplyFlusher.FLUSH` before issuing an increment.
4. Wait until the leader's state machine contains 1, while the increment's
client future remains incomplete.
5. Complete a leader read. It returns 1.
6. After that read completes, invoke a read against a follower that has not
advanced to the exposed write.
7. The pre-fix follower can return 0 because its required read index is still
derived from the older replied index.
The deterministic regression uses 1 then 0 to reproduce the same ordering
failure as the captured 12 then 11 history.
h2. Expected behavior
The follower read must return at least 1, or wait/fail until it can satisfy the
linearizable-read requirement. Correctness must not require releasing the held
write reply first.
h2. Root cause
A leader's state machine can expose a committed write before `ReplyFlusher`
releases that write's reply. A leader query can therefore observe state newer
than the configured replied-index bound. Query completion previously did not
raise the bound used by subsequent read-index requests and follower commit
advertisements.
There is also a role-transition case: a query can start while its server is a
follower, remain pending through promotion, and expose a write after that
server becomes leader. Looking up the leader role only when the query starts
misses this publication requirement.
h2. Proposed fix
Maintain a monotonic `lastReadIndex` bound. On successful query completion,
publish a committed-index bound through the server's current leader state
before exposing the query result. Use the maximum of that bound and the
configured commit/applied/replied index supplier.
Apply publication to both local division reads and client RPC reads. The
demonstrated counterexample uses `REPLIED_INDEX`; the shared wrapper preserves
the bound across configured index modes without claiming that the same
execution was reproduced in every mode.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)