Class DefaultLeaderElectionService
java.lang.Object
org.apache.flink.runtime.leaderelection.DefaultLeaderElectionService
- All Implemented Interfaces:
AutoCloseable,LeaderElectionDriver.Listener,LeaderElectionService
public class DefaultLeaderElectionService
extends Object
implements LeaderElectionService, LeaderElectionDriver.Listener, AutoCloseable
Default implementation for leader election service. Composed with different
LeaderElectionDriver, we could perform a leader election for the contender, and then persist the
leader information to various storage.
DefaultLeaderElectionService handles a single LeaderContender.
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultLeaderElectionService(LeaderElectionDriverFactory leaderElectionDriverFactory) DefaultLeaderElectionService(LeaderElectionDriverFactory leaderElectionDriverFactory, org.apache.flink.runtime.rpc.FatalErrorHandler fallbackErrorHandler) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()protected CompletableFuture<Void>confirmLeadershipAsync(String componentId, UUID leaderSessionID, String leaderAddress) createLeaderElection(String componentId) Creates a newLeaderElectioninstance that is registered to thisLeaderElectionServiceinstance.getLeaderSessionID(String componentId) Returns the current leader session ID for the givencomponentIdornull, if the session wasn't confirmed.protected CompletableFuture<Boolean>hasLeadershipAsync(String componentId, UUID leaderSessionId) voidNotifies the listener if an error occurred.voidonGrantLeadership(UUID leaderSessionID) Callback that is called once the driver obtains the leadership.voidonLeaderInformationChange(String componentId, LeaderInformation leaderInformation) Notifies the listener about a changed leader information for the given component.voidonLeaderInformationChange(LeaderInformationRegister changedLeaderInformation) Notifies the listener about all currently known leader information.voidCallback that is called once the driver loses the leadership.protected voidregister(String componentId, LeaderContender contender) protected final void
-
Constructor Details
-
DefaultLeaderElectionService
-
DefaultLeaderElectionService
@VisibleForTesting public DefaultLeaderElectionService(LeaderElectionDriverFactory leaderElectionDriverFactory, org.apache.flink.runtime.rpc.FatalErrorHandler fallbackErrorHandler)
-
-
Method Details
-
createLeaderElection
Description copied from interface:LeaderElectionServiceCreates a newLeaderElectioninstance that is registered to thisLeaderElectionServiceinstance.- Specified by:
createLeaderElectionin interfaceLeaderElectionService- Parameters:
componentId- a unique identifier that refers to the stored leader information that the newly createdLeaderElectionmanages.
-
register
- Throws:
Exception
-
remove
- Throws:
Exception
-
close
- Specified by:
closein interfaceAutoCloseable- Throws:
Exception
-
confirmLeadershipAsync
protected CompletableFuture<Void> confirmLeadershipAsync(String componentId, UUID leaderSessionID, String leaderAddress) -
hasLeadershipAsync
-
getLeaderSessionID
Returns the current leader session ID for the givencomponentIdornull, if the session wasn't confirmed. -
onGrantLeadership
Description copied from interface:LeaderElectionDriver.ListenerCallback that is called once the driver obtains the leadership.- Specified by:
onGrantLeadershipin interfaceLeaderElectionDriver.Listener
-
onRevokeLeadership
public void onRevokeLeadership()Description copied from interface:LeaderElectionDriver.ListenerCallback that is called once the driver loses the leadership.- Specified by:
onRevokeLeadershipin interfaceLeaderElectionDriver.Listener
-
onLeaderInformationChange
Description copied from interface:LeaderElectionDriver.ListenerNotifies the listener about a changed leader information for the given component.- Specified by:
onLeaderInformationChangein interfaceLeaderElectionDriver.Listener- Parameters:
componentId- identifying the component whose leader information has changedleaderInformation- new leader information
-
onLeaderInformationChange
Description copied from interface:LeaderElectionDriver.ListenerNotifies the listener about all currently known leader information.- Specified by:
onLeaderInformationChangein interfaceLeaderElectionDriver.Listener
-
onError
Description copied from interface:LeaderElectionDriver.ListenerNotifies the listener if an error occurred.- Specified by:
onErrorin interfaceLeaderElectionDriver.Listener
-