XComp commented on code in PR #25679:
URL: https://github.com/apache/flink/pull/25679#discussion_r1865897573
##########
flink-runtime/src/main/java/org/apache/flink/runtime/leaderelection/LeaderElection.java:
##########
@@ -39,17 +44,37 @@ public interface LeaderElection extends AutoCloseable {
*
* @param leaderSessionID The new leader session ID
* @param leaderAddress The address of the new leader
+ * @return A future that completes successfully if the confirmation
succeeded or fails
+ * exceptionally with a {@link LeadershipLostException} if the
leadership was revoked in the
+ * meantime.
+ */
+ default CompletableFuture<Void> confirmLeadershipAsLeader(
+ UUID leaderSessionID, String leaderAddress) {
+ checkNotNull(leaderSessionID);
+ checkNotNull(leaderAddress);
+
+ return runAsLeader(
+ leaderSessionID, () -> confirmLeadership(leaderSessionID,
leaderAddress));
+ }
+
+ /**
+ * Runs the actual leadership confirmation. This method should only be
called if the leadership
+ * is acquired. Otherwise, a {@link IllegalStateException} should be
thrown.
*/
void confirmLeadership(UUID leaderSessionID, String leaderAddress);
/**
- * Returns {@code true} if the service's {@link LeaderContender} has the
leadership under the
- * given leader session ID acquired.
+ * Runs the given {@code callback} on the leader election's main thread
only if the associated
+ * {@code leaderSessionId} is still valid.
*
- * @param leaderSessionId identifying the current leader
- * @return true if the associated {@link LeaderContender} is the leader,
otherwise false
+ * @param leaderSessionId The session ID that's associated with the given
{@code callback}.
+ * @param callback The callback that shall be executed as a leader.
+ * @return The future referring to the result of the callback operation.
This future would
+ * complete exceptionally with a {@link LeadershipLostException} if
the leadership wasn't
+ * active anymore.
*/
- boolean hasLeadership(UUID leaderSessionId);
+ CompletableFuture<Void> runAsLeader(
Review Comment:
hm, I guess you're right. That was my misconception here that we want to
ensure leadership beyond the HA which, indeed, is not possible. Let me give it
another try with the async hasLeadership approach 🤔
--
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]