szetszwo commented on code in PR #743:
URL: https://github.com/apache/ratis/pull/743#discussion_r973945411


##########
ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerImpl.java:
##########
@@ -912,16 +916,56 @@ ReadRequests getReadRequests() {
     return getState().getReadRequests();
   }
 
-  private CompletableFuture<ReadIndexReplyProto> sendReadIndexAsync() {
+  private CompletableFuture<Long> getReadIndexFromLeaderAsync() {
     final ReadIndexRequestProto request = 
ServerProtoUtils.toReadIndexRequestProto(
         getMemberId(),  getInfo().getLeaderId());
     try {
-      return getServerRpc().async().readIndexAsync(request);
+      return getServerRpc().async().readIndexAsync(request).thenApply(reply -> 
{
+        if (reply.getServerReply().getSuccess()) {
+            return reply.getReadIndex();
+          } else {
+            throw new CompletionException(new ReadException(getId() +
+                ": Failed to get read index from the leader: " + reply));
+          }
+      });
     } catch (IOException e) {
       return JavaUtils.completeExceptionally(e);
     }
   }
 
+  private CompletableFuture<Long> readIndexWithRetry() {
+    CompletableFuture<Long> f;
+
+    final LeaderStateImpl leader = role.getLeaderState().orElse(null);
+    if (leader != null) {
+      f = sendReadIndexWithRetry(leader::getReadIndex);
+    } else {
+      f = sendReadIndexWithRetry(this::getReadIndexFromLeaderAsync);
+    }

Review Comment:
   It should also check if the server is leader at during retry.



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