XComp commented on code in PR #22380:
URL: https://github.com/apache/flink/pull/22380#discussion_r1169826770
##########
flink-runtime/src/main/java/org/apache/flink/runtime/leaderelection/DefaultLeaderElectionService.java:
##########
@@ -77,22 +100,48 @@ public
DefaultLeaderElectionService(LeaderElectionDriverFactory leaderElectionDr
this.leaderElectionDriver = null;
this.confirmedLeaderInformation = LeaderInformation.empty();
+ }
- this.running = false;
+ /**
+ * Starts the leader election process. This method has to be called before
registering a {@link
+ * LeaderContender}.
+ */
+ public void startLeaderElectionBackend() throws Exception {
+ synchronized (lock) {
+ Preconditions.checkState(
+ leaderContender == null,
+ "No LeaderContender should have been registered, yet.");
+
+ leaderElectionDriver =
+ leaderElectionDriverFactory.createLeaderElectionDriver(
+ this, new LeaderElectionFatalErrorHandler());
+
+ LOG.info("Instantiating DefaultLeaderElectionService with {}.",
leaderElectionDriver);
+ }
}
@Override
public final void start(LeaderContender contender) throws Exception {
checkNotNull(contender, "Contender must not be null.");
- Preconditions.checkState(leaderContender == null, "Contender was
already set.");
synchronized (lock) {
- running = true;
+ Preconditions.checkState(
+ leaderContender == null,
+ "Only one LeaderContender is allowed to be registered to
this service.");
+ Preconditions.checkState(
+ leaderElectionDriver != null,
+ "The DefaultLeaderElectionService should have established
a connection to the backend before it's started.");
+
leaderContender = contender;
- leaderElectionDriver =
- leaderElectionDriverFactory.createLeaderElectionDriver(
- this, new LeaderElectionFatalErrorHandler());
- LOG.info("Starting DefaultLeaderElectionService with {}.",
leaderElectionDriver);
+
+ LOG.info(
+ "LeaderContender {} has been registered for {}.",
+ contender.getDescription(),
+ leaderElectionDriver);
+
+ if (hasLeadership()) {
+ notifyLeaderContenderOfLeadership();
Review Comment:
args, that's a good catch - I haven't thought about it in that way. I was
planning to include a `singleThreadExecutor` similarly to what we have in
`DefaultMultipleComponentLeaderElectionService` but hoped that it could be done
in a separate PR. But it looks like I have to integrate that one in here as
well. :roll_eyes: I'm going to work on it.
--
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]