szetszwo commented on code in PR #1448:
URL: https://github.com/apache/ratis/pull/1448#discussion_r4097104718
##########
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:
This becomes unused. Please remove it.
##########
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:
On a second thought, should we use Message instead of Supplier?
```java
default CompletableFuture<Message> readOnlyAsync(ClientId clientId,
ReadRequestTypeProto readRequestType,
Message queryMessage) throws IOException {
```
--
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]