szetszwo commented on PR #1722:
URL: https://github.com/apache/ratis/pull/1722#issuecomment-7448005349

   @ivandika3 ,
   
   The bug in APPLIED_INDEX and REPLIED_INDEX 
   ---
   State | Leader | Follower
   -- | -- | --
   commitIndex | 20 | 20
   appliedIndex | 11 | 12 (transaction 12: Counter++)
   Counter value | 1 | 2
   
   APPLIED_INDEX actually also has a bug:
   
   1. Client reads from Follower and got Counter==2
   2. Later, the same Client reads from Leader and got Counter==1
   
   The problem with APPLIED_INDEX and REPLIED_INDEX is that Leader's 
(applied|replied) index can be smaller than Follower's.  For commitIndex, it is 
always true that
   - Invariant: Leader's commitIndex >=  Follower's commitIndex
   - Non-invariant: Leader's (applied|replied) index >=  Follower's 
(applied|replied) index
   
   HDFS Visible Length
   ---
   The problem is similar to the visible length problem (HDFS-265) in HDFS -- 
when a block is being written, datanodes may have different visible lengths.  
After a client read from a datanode and saw length n bytes, if it switches to 
another datanode, it must see at least n bytes.  HDFS uses acked length
   
   <img width="483" height="38" alt="image" 
src="https://github.com/user-attachments/assets/b9d1c771-2c8c-4c66-be28-510e3d047ba9";
 />
   
   - [HDFS-265](https://issues.apache.org/jira/browse/HDFS-265) (page 5 in 
[appendDesign3.pdf](https://issues.apache.org/jira/secure/attachment/12445209/appendDesign3.pdf))
   - BR - byte received
   - BA - byte acked, which is the visible length.  Since BA_i < BR_k for any i 
and k, client can switch to any other datanode and it must already has enough 
bytes.
   
   When a client first reads from a Dn, the Dn will serves up to its BA.  But 
when the client switches to another Dn, it will provide the length L it already 
saw.  Then, the new Dn will serve up to max(BA, L).
   - Dn0: BA=10, BR=20
   - Dn1: BA=12, BR=18
   - Dn2: BA=15, BR=16
   
   Client read from Dn0, it will get 10 bytes.  When it switches to Dn2, it can 
read max(15, 10) = 15 byte.  When it switches again to Dn1, it still can read 
max(12, 15) = 15 bytes.
   
   Fix in Ratis
   ---
   - Same client case: 
   How about the client has to provide the minIndex when switching servers?  
i.e. Client reads from server 1, it will receive the reply with the 
appliedIndex.  If the client switches to server 2, it will provide the 
appliedIndex as the minIndex.  Server 2 will wait until the minIndex to applied 
before replying.
   
   - Multi-client case:
   Even the solution here (Leader updating readIndex = max(commitIndex, 
readIndex)) cannot fix it.  The following example still breaks linearizability.
      1. Client A reads from Follower and got counter==2.
      2. Client A tells Client B to read.
      3. Client B reads from Leader and got counter==1.  (NOT LINEARIZABLE)
   
   However, the multi-client cases may not be required for many of the 
applications.  How about we fix the same client case and document it that 
multi-client case won't work for APPLIED_INDEX and REPLIED_INDEX?
   


-- 
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]

Reply via email to