You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2020/12/24 06:50:24 UTC

[GitHub] [flink] wangyang0918 commented on a change in pull request #14485: [FLINK-20648][coordination][k8s] Start leader election service before creating JobMaster

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.




----------------------------------------------------------------
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:
users@infra.apache.org