nandakumar131 commented on code in PR #1275:
URL: https://github.com/apache/ratis/pull/1275#discussion_r2194246207


##########
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:
   > When reply != null, the server is no longer the leader. So, we don't have 
to cancal the permit.
   
   Yeah, makes sense.
   We create new `LeaderStateImpl` when a node becomes leader, this will create 
new `PendingRequests`. There is no need for clean-up as the old one is not 
reused.



-- 
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]

Reply via email to