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

   > ... However, this requires us to create and manage another ReadIndex 
executor (or we can reuse one of the Ratis executors). ...
   
   @ivandika3 , Ratis use serverExecutor for handling client requests.  We may 
use it when application does not pass it.  Please see if below would work?
   ```diff
   diff --git 
a/ratis-server-api/src/main/java/org/apache/ratis/server/RaftServer.java 
b/ratis-server-api/src/main/java/org/apache/ratis/server/RaftServer.java
   index 7d4cba962..8beb73e90 100644
   --- a/ratis-server-api/src/main/java/org/apache/ratis/server/RaftServer.java
   +++ b/ratis-server-api/src/main/java/org/apache/ratis/server/RaftServer.java
   @@ -25,6 +25,8 @@ import java.util.Collection;
    import java.util.Objects;
    import java.util.Optional;
    import java.util.concurrent.CompletableFuture;
   +import java.util.concurrent.Executor;
   +
    import org.apache.ratis.conf.Parameters;
    import org.apache.ratis.conf.RaftProperties;
    import org.apache.ratis.proto.RaftProtos.CommitInfoProto;
   @@ -156,8 +158,8 @@ public interface RaftServer extends Closeable, 
RpcType.Get,
         * application request bytes.  Remote clients should continue to use
         * {@link org.apache.ratis.client.api.AsyncApi#sendReadOnly(Message)}.
         */
   -    default CompletableFuture<Message> readOnlyAsync(Message queryMessage) 
throws IOException {
   -      return readOnlyAsync(ClientId.randomId(), 
ReadRequestTypeProto.getDefaultInstance(), queryMessage);
   +    default CompletableFuture<Message> readOnlyAsync(Message queryMessage, 
Executor executor) throws IOException {
   +      return readOnlyAsync(ClientId.randomId(), 
ReadRequestTypeProto.getDefaultInstance(), queryMessage, executor);
        }
    
        /**
   @@ -169,7 +171,7 @@ public interface RaftServer extends Closeable, 
RpcType.Get,
         * consistency must use the same client ID as their prior writes.
         */
        default CompletableFuture<Message> readOnlyAsync(ClientId clientId, 
ReadRequestTypeProto readRequestType,
   -        Message queryMessage) throws IOException {
   +        Message queryMessage, Executor executor) throws IOException {
          throw new UnsupportedOperationException("readOnlyAsync is not 
supported");
        }
    
   ```
   ```diff
   diff --git 
a/ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerImpl.java 
b/ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerImpl.java
   index cb9818e45..9752b8a90 100644
   --- 
a/ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerImpl.java
   +++ 
b/ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerImpl.java
   @@ -125,6 +125,7 @@ import java.util.Set;
    import java.util.concurrent.CompletableFuture;
    import java.util.concurrent.CompletionException;
    import java.util.concurrent.ExecutionException;
   +import java.util.concurrent.Executor;
    import java.util.concurrent.ExecutorService;
    import java.util.concurrent.ThreadLocalRandom;
    import java.util.concurrent.TimeUnit;
   @@ -1175,8 +1176,9 @@ class RaftServerImpl implements RaftServer.Division,
    
      @Override
      public CompletableFuture<Message> readOnlyAsync(ClientId clientId, 
ReadRequestTypeProto readRequestType,
   -      Message queryMessage) throws IOException {
   -    return readRequestHandler.readOnlyAsync(clientId, readRequestType, 
queryMessage);
   +      Message queryMessage, Executor executor) throws IOException {
   +    return readRequestHandler.readOnlyAsync(clientId, readRequestType, 
queryMessage,
   +        executor != null ? executor : serverExecutor);
      }
    
      @Override
   ```
   ```diff
   diff --git 
a/ratis-server/src/main/java/org/apache/ratis/server/impl/ReadRequestHandler.java
 
b/ratis-server/src/main/java/org/apache/ratis/server/impl/ReadRequestHandler.java
   index aaaa92b26..c3b025ec0 100644
   --- 
a/ratis-server/src/main/java/org/apache/ratis/server/impl/ReadRequestHandler.java
   +++ 
b/ratis-server/src/main/java/org/apache/ratis/server/impl/ReadRequestHandler.java
   @@ -47,6 +47,7 @@ import java.io.IOException;
    import java.util.Objects;
    import java.util.concurrent.CompletableFuture;
    import java.util.concurrent.CompletionException;
   +import java.util.concurrent.Executor;
    
    import static 
org.apache.ratis.server.impl.ServerProtoUtils.toReadIndexReplyProto;
    import static 
org.apache.ratis.server.impl.ServerProtoUtils.toReadIndexRequestProto;
   @@ -142,7 +143,7 @@ class ReadRequestHandler {
      }
    
      CompletableFuture<Message> readOnlyAsync(ClientId clientId, 
ReadRequestTypeProto readRequestType,
   -      Message queryMessage) throws IOException {
   +      Message queryMessage, Executor executor) throws IOException {
        Objects.requireNonNull(clientId, "clientId == null");
        Objects.requireNonNull(readRequestType, "readRequestType == null");
        Objects.requireNonNull(queryMessage, "queryMessage == null");
   @@ -160,7 +161,7 @@ class ReadRequestHandler {
          return getReadIndex(clientId, readRequestType, leader)
              .thenCompose(readIndex -> 
state.getReadRequests().waitToAdvance(readIndex,
                  () -> getReadExceptionIfInstallingSnapshot("local read")))
   -          .thenCompose(readIndex -> stateMachine.query(queryMessage));
   +          .thenComposeAsync(readIndex -> stateMachine.query(queryMessage), 
executor);
        } else {
          throw new IllegalStateException("Unexpected read option: " + 
readOption);
        }
   ```


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