Github user mxm commented on a diff in the pull request: https://github.com/apache/flink/pull/2427#discussion_r76811799 --- Diff: flink-runtime/src/main/java/org/apache/flink/runtime/rpc/resourcemanager/ResourceManager.java --- @@ -116,4 +142,78 @@ public SlotAssignment requestSlot(SlotRequest slotRequest) { return new TaskExecutorRegistrationSuccess(new InstanceID(), 5000); } + + /** + * Callback method when current resourceManager is granted leadership + * + * @param newLeaderSessionID unique leadershipID + */ + void handleGrantLeadership(final UUID newLeaderSessionID) { + runAsync(new Runnable() { + @Override + public void run() { + log.info("ResourceManager {} was granted leadership with leader session ID {}", getAddress(), newLeaderSessionID); + leaderSessionID = newLeaderSessionID; + // confirming the leader session ID might be blocking, + leaderElectionService.confirmLeaderSessionID(newLeaderSessionID); + } + }); + } + + /** + * Callback method when current resourceManager lose leadership. + */ + void handleRevokeLeadership() { + runAsync(new Runnable() { + @Override + public void run() { + log.info("ResourceManager {} was revoked leadership.", getAddress()); + jobMasterGateways.clear(); + leaderSessionID = null; + } + }); + } + + /** + * Callback method when an error happened to current resourceManager on leader election + * @param e + */ + void onLeaderElectionError(final Throwable e) { + runAsync(new Runnable() { + @Override + public void run() { + log.error("ResourceManager received an error from the LeaderElectionService.", e); + // terminate ResourceManager in case of an error + shutDown(); + } + }); + } + + private class ResourceManagerLeaderContender implements LeaderContender { + + @Override + public void grantLeadership(UUID leaderSessionID) { + handleGrantLeadership(leaderSessionID); --- End diff -- I wonder why do you call methods in the main class? Couldn't all code in the methods `handleGrantLeadership`, `revokeLeadership`, `onLeaderElectionError` not simply be implemented in this class? Of course they should still call `runAsync` to execute in the main RPC thread.
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---