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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to