szetszwo commented on code in PR #1624:
URL: https://github.com/apache/ratis/pull/1624#discussion_r4167818225
##########
ratis-client/src/main/java/org/apache/ratis/client/impl/RaftClientImpl.java:
##########
@@ -362,6 +367,8 @@ RaftClientReply handleReply(RaftClientRequest request,
RaftClientReply reply) {
if (request.isToLeader() && reply != null) {
if (!request.getType().isReadOnly()) {
repliedCallIds.add(reply.getCallId());
+ } else {
+ repliedCallIds.removeSent(request.getCallId());
Review Comment:
If we removeSent, the corresponding reply id set will be ignored. Let's
don't put it to `sent` at the first place.
(below is revised)
```diff
@@ -290,7 +292,7 @@ public final class RaftClientImpl implements RaftClient {
b.setServerId(server);
} else {
b.setLeaderId(getLeaderId())
- .setRepliedCallIds(repliedCallIds.get(callId));
+ .setRepliedCallIds(type.isReadOnly() ? repliedCallIds.getAndReset()
: repliedCallIds.get(callId));
}
if (TraceUtils.isEnabled()) {
b.setSpanContext(TraceUtils.injectContextToProto());
```
BTW, let's also improve the code a little bit:
```diff
+++
b/ratis-client/src/main/java/org/apache/ratis/client/impl/RaftClientImpl.java
@@ -155,13 +155,15 @@ public final class RaftClientImpl implements
RaftClient {
/** @return the replied callIds for the given callId. */
Iterable<Long> get(long callId) {
- final Supplier<Set<Long>> supplier =
MemoizedSupplier.valueOf(this::getAndReset);
- final Set<Long> set =
Collections.unmodifiableSet(sent.computeIfAbsent(callId, cid ->
supplier.get()));
+ final Set<Long> set =
Collections.unmodifiableSet(sent.computeIfAbsent(callId, cid -> getAndReset()));
LOG.debug("{}: get {} returns {}", name, callId, set);
return set;
}
- private synchronized Set<Long> getAndReset() {
+ synchronized Set<Long> getAndReset() {
+ if (replied.isEmpty()) {
+ return Collections.emptySet();
+ }
final Set<Long> previous = replied;
replied = new TreeSet<>();
return previous;
```
--
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]