Repository navigation
Conversation
|
Thanks @ivandika3 for all the context in: I'm concerned that Ratis can no longer enforce any of these. The returned Long also exposes a log index that callers might misuse (as it is just a number not a proto). The root cause in RATIS-2831 is that For example, replace the API to |
|
@ivandika3 also part of the reason that we had the public API discussion is because the context is spread over different JIRA without a clear grouping: https://issues.apache.org/jira/browse/RATIS-2509 It would be better if you can build a parent JIRA to state the ultimate goal and convert the JIRAs to sub-tasks. |
|
Thanks @amaliujia for further reviews.
Yes, this is a valid concern since now the job of doing linearizable read is in the application and therefore can be misused by the application. However, this seems to be the way other systems like etcd implemented it so there is a precedence. The javadoc already specifies the guarantees of this API. I understand that this issue breaks the Raft encapsulation (althought internal logic like the actual readindex propagation and waiting for application is still handled by Ratis), but I believe this is the current best way to be flexible and improves the performance profile.
The current OM read already checks the cache which will be invalidated if it's already been applied to RocksDB. There should not be any extra logic needed to handle this. For snapshot install, even the previous readOnlyAsync does not handle cases where there is a snapshot install in
Yes, misuse is possible, but changing it to protobuf does not really enforces anything and can introduce additional serde overhead.
I have thought about passing an executor and this would technically work. However, this requires us to create and manage another ReadIndex executor (or we can reuse one of the Ratis executors). This has an overhead of handing off to another set of executors instead of actually running it in the RPC threads, such as the handoff overhead, Java async scheduling, low level things like cache locality. Another issue is that this executor needs to be sized accordingly (e.g. we have to size it to the number RPC threads). Finally, we need some kind of special thread local propagation between the caller thread and the executor threads (like apache/ozone#11257 in Ozone). In Ozone OM, the OM leader simply reads from the local read without handing off anything and this makes the read performance of leader read superior than anything that has to go through Ratis. I wanted to close this gap as much as possible. Hope this clarifies. |
@amaliujia Thanks, I have raised RATIS-2836 to include all the linearizable read performance works. |
|
Thanks for the clarification! IMO the right direction is still having the Ratis deal with the tough work directly when possible. Looping @szetszwo to see if there are other solutions or which technical direction we should go. |
@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 --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 --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);
}
@Overridediff --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);
} |
|
Thanks @szetszwo for the suggestion. Using serverExecutor makes sense as a default, I'll add back the readOnlyAsync with executor integration. The concern is still whether the performance of using readOnlyAsync will be on-par with using readIndexAsync due to the executor handoff and if using serverExecutor whether sharing the executor with appendEntries and transferLeadership will affect performance. I'm still benchmarking on OM with readIndexAsync so the performance comparison with readOnlyAsync will be done later. I also added Javadoc to indicate that these APIs are experimental and subject for removal. |
szetszwo
left a comment
There was a problem hiding this comment.
@ivandika3 , thanks for the update!
In RaftServer, there are 4 overloaded readOnlyAsync and 2 readIndexAsync methods now. It seems too many. If we cannot decide the right API, how about we add them later? Otherwise, the bad API is very hard to be removed later.
We may just add public methods in RaftServerImpl and use them for testing. Once we have decided the right API, we can add them to RaftServer.
What changes were proposed in this pull request?
Generated-by: GPT 6.1 Sol
Please see https://issues.apache.org/jira/browse/RATIS-2831
What is the link to the Apache JIRA
https://issues.apache.org/jira/browse/RATIS-2831
How was this patch tested?
UT. Did a benchmark on the follower read for the ReadIndex batching implementation (RATIS-2524, WIP) and the regression due to the coupling between the ReadIndex and the actual query disappeared and the ReadIndex batching performance is now considerably improved than without batching.