Package org.apache.druid.discovery
Interface DruidLeaderSelector
- All Known Implementing Classes:
CuratorDruidLeaderSelector
public interface DruidLeaderSelector
Interface for supporting Overlord and Coordinator Leader Elections in TaskMaster and DruidCoordinator
which expect appropriate implementation available in guice annotated with @IndexingService and @Coordinator
respectively.
Usage is as follows:
On lifecycle start:
druidLeaderSelector.registerListener(myListener);
On lifecycle stop:
druidLeaderSelector.unregisterListener();
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionGet ID of current Leader.booleanisLeader()Returns true if this node is elected leader from underlying system's point of view.intImplementation would increment it everytime it becomes leader.voidregisterListener(DruidLeaderSelector.Listener listener) Register the listener for watching leadership notifications.voidUnregisters the listener.
-
Method Details
-
getCurrentLeader
Get ID of current Leader. Returns NULL if it can't find the leader. Note that it is possible for leadership to change right after this call returns, so caller would get wrong leader. This is expected to work even if a listener is not registered. -
isLeader
boolean isLeader()Returns true if this node is elected leader from underlying system's point of view. For example if curator is used to implement this then true would be returned when curator believes this node to be the leader. Note that it is possible for leadership to change right after this call returns, so caller would get wrong status. -
localTerm
int localTerm()Implementation would increment it everytime it becomes leader. This allows users to start a long running task when they become leader and be able to intermittently check that they are still leader from same term when they started. DruidCoordinator class uses it to do intermittent checks and stop the activity as needed. -
registerListener
Register the listener for watching leadership notifications. It should only be called once. -
unregisterListener
void unregisterListener()Unregisters the listener.
-