Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1054,6 +1054,9 @@ private CompletableFuture<Long> getReadIndex(RaftClientRequest request, LeaderSt
return writeIndexCache.getWriteIndexFuture(request).thenCompose(leader::getReadIndex);
}

private final ExecutorService readAsyncExecutor = ConcurrentUtils.newThreadPoolWithMax(false,
Math.max(2, Runtime.getRuntime().availableProcessors()), "ReadAsync");

private CompletableFuture<RaftClientReply> readAsync(RaftClientRequest request) {
if (request.getType().getRead().getPreferNonLinearizable()
|| readOption == RaftServerConfigKeys.Read.Option.DEFAULT) {
Expand Down Expand Up @@ -1087,7 +1090,8 @@ private CompletableFuture<RaftClientReply> readAsync(RaftClientRequest request)

return replyFuture
.thenCompose(readIndex -> getReadRequests().waitToAdvance(readIndex))
.thenCompose(readIndex -> queryStateMachine(request))
.thenComposeAsync(ignored -> stateMachine.query(request.getMessage()), readAsyncExecutor)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@symious , Since it is calling stateMachine.query(..), the StateMachine implementation could choose to run it with its own executor. If we use an executor here, then the stateMachine has no choice and is forced to run it with Ratis executor. So I suggest not to make this change.

.thenCompose(reply -> processQueryFuture(CompletableFuture.completedFuture(reply), request))
.exceptionally(e -> readException2Reply(request, e));
} else {
throw new IllegalStateException("Unexpected read option: " + readOption);
Expand Down
Loading