wangyang0918 commented on a change in pull request #14485:
URL: https://github.com/apache/flink/pull/14485#discussion_r548418975



##########
File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/leaderelection/StandaloneLeaderElectionService.java
##########
@@ -44,8 +50,12 @@ public void start(LeaderContender newContender) throws 
Exception {
 
                contender = Preconditions.checkNotNull(newContender);
 
-               // directly grant leadership to the given contender
-               
contender.grantLeadership(HighAvailabilityServices.DEFAULT_LEADER_ID);
+               // Grant leadership in a separate thread
+               leaderElectorExecutor = Executors.newSingleThreadExecutor(
+                       new ExecutorThreadFactory("LeaderElectorExecutor"));
+               CompletableFuture.runAsync(
+                       () -> 
contender.grantLeadership(HighAvailabilityServices.DEFAULT_LEADER_ID),
+                       leaderElectorExecutor);

Review comment:
       Good suggestion. Using the `whenComplete` to ensure the executing order 
could help to manage the changes in a smaller scope.
   
   Only one thing we need to care is that now the `grantLeadership` is 
executing on the `io-executor`, not the `leader-elector-executor`. I think this 
change makes sense.




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

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to