zentol 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_r263479048
##########
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:
The flag is no longer reset if the grant fails.
I'm wondering whether we need this flag at all. It's only being used in
`EmbeddedLeaderElectionService#hasLeadership`, but shouldn't the
`leaderSessionId` be sufficient for checking that? This seems especially true
now that `updateLeader` updates both `isLeader` and `currentLeaderSessionId`
right after another.
----------------------------------------------------------------
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