szetszwo commented on code in PR #1275:
URL: https://github.com/apache/ratis/pull/1275#discussion_r2193166408
##########
ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerImpl.java:
##########
@@ -819,23 +819,25 @@ private CompletableFuture<RaftClientReply>
appendTransaction(
assertLifeCycleState(LifeCycle.States.RUNNING);
+ final LeaderStateImpl leaderState = role.getLeaderStateNonNull();
+ final PendingRequests.Permit permit =
leaderState.tryAcquirePendingRequest(request.getMessage());
+ if (permit == null) {
+ cacheEntry.failWithException(new ResourceUnavailableException(
+ getMemberId() + ": Failed to acquire a pending write request for " +
request));
+ return cacheEntry.getReplyFuture();
+ }
+
final PendingRequest pending;
synchronized (this) {
final CompletableFuture<RaftClientReply> reply =
checkLeaderState(request, cacheEntry);
if (reply != null) {
+ leaderState.cancelPendingRequest(permit, request.getMessage());
Review Comment:
After this change, we can remove the static `failWithException(..)` method.
```java
@@ -266,14 +267,4 @@ class RetryCacheImpl implements RetryCache {
return CompletableFuture.completedFuture(reply);
}
}
-
- static CompletableFuture<RaftClientReply> failWithException(
- Throwable t, CacheEntry entry) {
- if (entry != null) {
- entry.failWithException(t);
- return entry.getReplyFuture();
- } else {
- return JavaUtils.completeExceptionally(t);
- }
- }
}
```
--
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]