You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ratis.apache.org by "Elia-Renzoni (via GitHub)" <gi...@apache.org> on 2026/10/20 16:47:17 UTC

[PR] RATIS-2714. Support read-aftew-write consistency across clients [ratis]

Elia-Renzoni opened a new pull request, #1652:
URL: https://github.com/apache/ratis/pull/1652

   ## What changes were proposed in this pull request?
   This PR improves read-after-write consistency by ensuring that clients wait until the latest write has completed. Writes are tracked in `WriteIndexCache` via `latestWriteIndex`, which is updated whenever a write request reaches the leader. Reads use this index as a watermark, so they observe the latest write while avoiding starvation.
   ## What is the link to the Apache JIRA
   https://issues.apache.org/jira/browse/RATIS-2714
   
   ## How was this patch tested?
   This patch was tested via unit tests


-- 
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: issues-unsubscribe@ratis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] RATIS-2714. Support read-after-write consistency across clients [ratis]

Posted by "szetszwo (via GitHub)" <gi...@apache.org>.
szetszwo merged PR #1652:
URL: https://github.com/apache/ratis/pull/1652


-- 
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: issues-unsubscribe@ratis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] RATIS-2714. Support read-after-write consistency across clients [ratis]

Posted by "Elia-Renzoni (via GitHub)" <gi...@apache.org>.
Elia-Renzoni commented on code in PR #1652:
URL: https://github.com/apache/ratis/pull/1652#discussion_r4349113790


##########
ratis-proto/src/main/proto/Raft.proto:
##########
@@ -304,6 +304,7 @@ message ReadRequestTypeProto {
   bool preferNonLinearizable = 1;
   bool readAfterWriteConsistent = 2;
   bool dummy = 3;
+  bool strongReadAfterWrite = 4;

Review Comment:
   Fixed here: 63f18c747c25066b17327329e508efe60cdf5514



##########
ratis-server/src/main/java/org/apache/ratis/server/impl/WriteIndexCache.java:
##########
@@ -27,11 +27,16 @@
 
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.ExecutionException;
+import java.util.concurrent.atomic.AtomicLong;
 import java.util.concurrent.atomic.AtomicReference;
 
-/** Caching the per client write index in order to support read-after-write consistency. */
+/**
+ * Caching the per client write index in order to support read-after-write consistency.
+ * Also track the latest write index of all the clients in order to support strong read-after-write consistency.
+ */
 class WriteIndexCache {
   private final Cache<ClientId, AtomicReference<CompletableFuture<Long>>> cache;
+  private final AtomicLong latestWriteIndex;

Review Comment:
   Fixed here: 63f18c747c25066b17327329e508efe60cdf5514



-- 
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: issues-unsubscribe@ratis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] RATIS-2714. Support read-after-write consistency across clients [ratis]

Posted by "szetszwo (via GitHub)" <gi...@apache.org>.
szetszwo commented on code in PR #1652:
URL: https://github.com/apache/ratis/pull/1652#discussion_r4340022182


##########
ratis-client/src/main/java/org/apache/ratis/client/api/AsyncApi.java:
##########
@@ -70,6 +70,16 @@ default CompletableFuture<RaftClientReply> sendReadOnly(Message message) {
   CompletableFuture<RaftClientReply> sendReadAfterWrite(Message message);
 
 
+  /**
+   * Send the given readonly message asynchronously to the raft service.
+   * The result reflects all the writes, from any client, already accepted by the leader,
+   * including writes that have not completed yet.
+   * This is an alternative to {@link #sendReadAfterWrite(Message)} and cannot be combined with it.
+   * @param message The request message.
+   * @return the reply.
+   */
+  CompletableFuture<RaftClientReply> sendStrongReadAfterWrite(Message message);

Review Comment:
   Let's add a parameter:
   
   ```java
     /**
      * Send the given readonly message asynchronously to the raft service.
      * The result is read-after-write consistent individually or globally.
      *
      * @param message The request message.
      * @param isGlobal When set to false, consistency is maintained within the same client (i.e. read-your-write).
      *                 When set to true, consistency is guaranteed across all clients (i.e. global read-after-write).
      * @return the reply.
      */
     CompletableFuture<RaftClientReply> sendReadAfterWrite(Message message, boolean isGlobal);
   
     /** The same as sendReadAfterWrite(message, false), i.e. read-your-write consistent. */
     default CompletableFuture<RaftClientReply> sendReadAfterWrite(Message message) {
       return sendReadAfterWrite(message, false);
     }
   ```



##########
ratis-proto/src/main/proto/Raft.proto:
##########
@@ -304,6 +304,7 @@ message ReadRequestTypeProto {
   bool preferNonLinearizable = 1;
   bool readAfterWriteConsistent = 2;
   bool dummy = 3;
+  bool strongReadAfterWrite = 4;

Review Comment:
   Let's use `global`.  It may be useful for other cases in the future.



##########
ratis-server/src/main/java/org/apache/ratis/server/impl/WriteIndexCache.java:
##########
@@ -27,11 +27,16 @@
 
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.ExecutionException;
+import java.util.concurrent.atomic.AtomicLong;
 import java.util.concurrent.atomic.AtomicReference;
 
-/** Caching the per client write index in order to support read-after-write consistency. */
+/**
+ * Caching the per client write index in order to support read-after-write consistency.
+ * Also track the latest write index of all the clients in order to support strong read-after-write consistency.
+ */
 class WriteIndexCache {
   private final Cache<ClientId, AtomicReference<CompletableFuture<Long>>> cache;
+  private final AtomicLong latestWriteIndex;

Review Comment:
   We need to use `AtomicReference<CompletableFuture<Long>>` since the write is async:
   
   1. client submitted an async write successfully.
   2. the leader received the write but log index was assigned at that time.
   3. (the same or another ) client reads and get the latestWriteIndex
   
   If we use AtomicLong, the latestWriteIndex may not be updated at Step 3.



-- 
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: issues-unsubscribe@ratis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] RATIS-2714. Support read-after-write consistency across clients [ratis]

Posted by "Elia-Renzoni (via GitHub)" <gi...@apache.org>.
Elia-Renzoni commented on PR #1652:
URL: https://github.com/apache/ratis/pull/1652#issuecomment-6342418690

   > @Elia-Renzoni , thanks for working on this!
   > 
   > * Let's call it "global read-after-write" instead of "strong read-after-write".
   > * Please see the comments inlined and also https://issues.apache.org/jira/secure/attachment/13085711/1652_review.patch
   
   Thanks for your review! I've just updated the PR and should be good now...


-- 
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: issues-unsubscribe@ratis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org