ivandika3 opened a new pull request, #1722: URL: https://github.com/apache/ratis/pull/1722
## What changes were proposed in this pull request? Please refer to https://issues.apache.org/jira/browse/RATIS-2846 The leader batch write implementation in RATIS-2403 and the appliedIndex as ReadIndex in RATIS-2379 can both return stale reads. The main wrong assumption is that either RepliedIndex will ensure that all clients can only see the replies up to RepliedIndex, the actual read itself can read the StateMachine state up to AppliedIndex and the subsequent follower read might not see the transactions between the leader's RepliedIndex and the AppliedIndex which triggers the stale reads. For example, we have a counter implementation with REPLIED_INDEX enabled and with the following state State | Leader | Follower -- | -- | -- Applied log index | 11 | 10 Counter value | 1 | 0 This means that the log entry 11 updates the increment the counter from 0 to 1 A possible sequence 1. Leader read: `getReadIndex` return 10, derived from repliedIndex 2. The leader waits for applied index >= 10, but it already has 11, so it immediately queries its state machine and returns counter value 1 (new counter) 3. Subsequent follower read will request for leader's repliedIndex and the leader returns the repliedIndex 10, so getReadIndex returns 10 4. The follower has applied 10 >= repliedIndex 10 and return 0 (**Stale read**) The solution is to have a separate monotonically increasing readIndex attributes which is incremented after every read (i.e. `queryStateMachine`). The leader will take the `max(RepliedIndex, lastReadIndex)` and use that as the effective ReadIndex. Some thoughts - The assumption might be correct if we use MVCC where we can get the snapshot of the state when the StateMachine is at index RepliedIndex. However, since we don't use this mechanism, the bug exists. - This means that the performance improvements of both RATIS-2403 and RATIS-2379 would be reduced depending on how fresh the last successful leader reads. The freshest the last leader reads are, the higher the required ReadIndex and the longer the follower need to wait. This also implies that workloads that only reads from followers should still be able to gain the performance reads where as the workload will frequent leader reads can trigger issues. - The lastReadIndex is quite conservative, a better bound is to have **the highest log index whose effects the query actually observed**, but this requires `StateMachine#query` to return the index that the read is based on which is not trivial. ## What is the link to the Apache JIRA https://issues.apache.org/jira/browse/RATIS-2846 ## How was this patch tested? IT. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
