tillrohrmann commented on a change in pull request #7935: [FLINK-11855] Fix 
race condition in EmbeddedLeaderService#GrantLeadershipCall
URL: https://github.com/apache/flink/pull/7935#discussion_r263483901
 
 

 ##########
 File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/highavailability/nonha/embedded/EmbeddedLeaderService.java
 ##########
 @@ -506,33 +515,28 @@ public void run() {
 
        private static class GrantLeadershipCall implements Runnable {
 
-               private final EmbeddedLeaderElectionService 
leaderElectionService;
+               private final LeaderContender contender;
                private final UUID leaderSessionId;
                private final Logger logger;
 
                GrantLeadershipCall(
-                               EmbeddedLeaderElectionService 
leaderElectionService,
+                               LeaderContender contender,
                                UUID leaderSessionId,
                                Logger logger) {
 
-                       this.leaderElectionService = 
checkNotNull(leaderElectionService);
+                       this.contender = checkNotNull(contender);
                        this.leaderSessionId = checkNotNull(leaderSessionId);
                        this.logger = checkNotNull(logger);
                }
 
                @Override
                public void run() {
-                       leaderElectionService.isLeader = true;
-
-                       final LeaderContender contender = 
leaderElectionService.contender;
-
                        try {
                                contender.grantLeadership(leaderSessionId);
                        }
                        catch (Throwable t) {
                                logger.warn("Error granting leadership to 
contender", t);
                                contender.handleError(t instanceof Exception ? 
(Exception) t : new Exception(t));
-                               leaderElectionService.isLeader = false;
 
 Review comment:
   I kept the flag because if we would remove it, then a user of the 
`EmbeddedLeaderElectionService#hasLeadership` could get a false positive if it 
guessed the current leadership id by chance.
   
   It is true that we don't reset the `isLeader` flat to false in case of a 
failure. The assumption is that the `leaderContender` will stop the leader 
election service in case of a failure.

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to