szetszwo commented on code in PR #1448:
URL: https://github.com/apache/ratis/pull/1448#discussion_r4100536986
##########
ratis-server-api/src/main/java/org/apache/ratis/server/RaftServer.java:
##########
@@ -142,6 +146,33 @@ default RaftGroup getGroup() {
/** @return the {@link StateMachine} for this division. */
StateMachine getStateMachine();
+ /**
+ * Execute a local read-only query after applying the configured
+ * {@link RaftServerConfigKeys.Read.Option} consistency checks.
+ *
+ * <p>This API is intended for embedded users that already have a local
+ * server division and want to avoid serializing application read requests
+ * and responses through {@link org.apache.ratis.protocol.Message}. Remote
+ * clients should continue to use
+ * {@link
org.apache.ratis.client.api.AsyncApi#sendReadOnly(org.apache.ratis.protocol.Message)}.
+ */
+ default <T> CompletableFuture<T>
readOnlyAsync(Supplier<CompletableFuture<T>> query) throws IOException {
+ return readOnlyAsync(ClientId.randomId(),
ReadRequestTypeProto.getDefaultInstance(), query);
+ }
+
+ /**
+ * Execute a local read-only query after applying the configured
+ * {@link RaftServerConfigKeys.Read.Option} consistency checks.
+ *
+ * <p>The {@code clientId} and {@code readRequestType} identify the read
+ * semantics. In particular, callers requesting read-after-write
+ * consistency must use the same client ID as their prior writes.
+ */
+ default <T> CompletableFuture<T> readOnlyAsync(ClientId clientId,
ReadRequestTypeProto readRequestType,
+ Supplier<CompletableFuture<T>> query) throws IOException {
Review Comment:
Message and Supplier actually are almost the same since they both are
interface. Indeed, Message is more flexible in this PR since we never call any
methods in Message. The StateMachine can choose to do what even it wants. We
may simulate a Supplier as below:
```java
static class OmReadOzoneMessage implements Message {
CompletableFuture<Message> getReply() {
return ...
}
@Override
public ByteString getContent() {
throw new UnsupportedOperationException();
}
}
//StateMachine implementation
public CompletableFuture<Message> query(Message request) {
if (request instanceof OmReadOzoneMessage) {
return ((OmReadOzoneMessage)request).getReply();
}
...
}
```
##########
ratis-server/src/main/java/org/apache/ratis/server/impl/WriteIndexCache.java:
##########
@@ -58,8 +59,13 @@ void add(ClientId key, CompletableFuture<Long> current) {
}
CompletableFuture<Long> getWriteIndexFuture(RaftClientRequest request) {
- if (request != null &&
request.getType().getRead().getReadAfterWriteConsistent()) {
- final AtomicReference<CompletableFuture<Long>> ref =
cache.getIfPresent(request.getClientId());
+ return request != null ? getWriteIndexFuture(request.getClientId(),
request.getType().getRead())
+ : CompletableFuture.completedFuture(null);
+ }
Review Comment:
Message and Supplier actually are almost the same since they both are
interface. Indeed, Message is more flexible in this PR since we never call any
methods in Message. The StateMachine can choose to do what even it wants. We
may simulate a Supplier as below:
```java
static class OmReadOzoneMessage implements Message {
CompletableFuture<Message> getReply() {
return ...
}
@Override
public ByteString getContent() {
throw new UnsupportedOperationException();
}
}
//StateMachine implementation
public CompletableFuture<Message> query(Message request) {
if (request instanceof OmReadOzoneMessage) {
return ((OmReadOzoneMessage)request).getReply();
}
...
}
```
--
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]