szetszwo commented on a change in pull request #593:
URL: https://github.com/apache/ratis/pull/593#discussion_r793251236



##########
File path: 
ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerImpl.java
##########
@@ -1009,6 +1018,20 @@ SnapshotManagementRequestHandler 
getSnapshotRequestHandler() {
     return snapshotRequestHandler;
   }
 
+  CompletableFuture<RaftClientReply> 
pauseLeaderElectionAsync(PauseLeaderElectionRequest request) throws IOException 
{
+    LOG.info("{} receive pauseLeaderElection {}", getMemberId(), request);
+    assertLifeCycleState(LifeCycle.States.RUNNING);
+    assertGroup(request.getRequestorId(), request.getRaftGroupId());
+
+    boolean pause = getRole().getLeaderElectionPauseState();
+    if (pause == request.getPause()) {
+      return CompletableFuture.completedFuture(newSuccessReply(request, 
request.getPausedServer()));
+    }
+    synchronized (this) {
+      return pauseLeaderElection.pauseLeaderElectionAsync(request);
+    }
+  }

Review comment:
       We actually could call  
getRole().setLeaderElectionPause(request.getPause()) directly without 
synchronized.
   ```
     CompletableFuture<RaftClientReply> 
setLeaderElectionAsync(LeaderElectionRequest request) throws IOException {
       LOG.info("{} receive setLeaderElection {}", getMemberId(), request);
       assertLifeCycleState(LifeCycle.States.RUNNING);
       assertGroup(request.getRequestorId(), request.getRaftGroupId());
   
       getRole().setLeaderElectionPause(request.getPause());
       return CompletableFuture.completedFuture(newSuccessReply(request));
     }
   ```




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