Package org.apache.hadoop.hbase.master
Class ActiveMasterManager
java.lang.Object
org.apache.hadoop.hbase.zookeeper.ZKListener
org.apache.hadoop.hbase.master.ActiveMasterManager
Handles everything on master-side related to master election. Keeps track of currently active
master and registered backup masters.
Listens and responds to ZooKeeper notifications on the master znodes, both
nodeCreated
and nodeDeleted
.
Contains blocking methods which will hold up backup masters, waiting for the active master to fail.
This class is instantiated in the HMaster constructor and the method #blockUntilBecomingActiveMaster() is called to wait until becoming the active master of the cluster.
-
Field Summary
Modifier and TypeFieldDescription(package private) ServerName
private org.apache.hbase.thirdparty.com.google.common.collect.ImmutableList<ServerName>
(package private) final AtomicBoolean
(package private) final AtomicBoolean
(package private) int
private static final org.slf4j.Logger
(package private) final Server
(package private) final ServerName
Fields inherited from class org.apache.hadoop.hbase.zookeeper.ZKListener
watcher
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescription(package private) boolean
blockUntilBecomingActiveMaster
(int checkInterval, TaskGroup startupTaskGroup) Block until becoming the active master.private void
Fetches the active master's ServerName from zookeeper.int
int
Returns list of registered backup masters.(package private) void
private void
Handle a change in the master node.(package private) boolean
Returns True if cluster has an active master.void
nodeChildrenChanged
(String path) Called when an existing node has a child node added or removed.void
nodeCreated
(String path) Called when a new node has been created.void
nodeDeleted
(String path) Called when a node has been deletedvoid
setInfoPort
(int infoPort) void
stop()
private void
Methods inherited from class org.apache.hadoop.hbase.zookeeper.ZKListener
getWatcher, nodeDataChanged
-
Field Details
-
LOG
-
clusterHasActiveMaster
-
clusterShutDown
-
infoPort
int infoPort -
sn
-
master
-
activeMasterServerName
-
backupMasters
private volatile org.apache.hbase.thirdparty.com.google.common.collect.ImmutableList<ServerName> backupMasters
-
-
Constructor Details
-
ActiveMasterManager
ActiveMasterManager(ZKWatcher watcher, ServerName sn, Server master) throws InterruptedIOException - Parameters:
watcher
- ZK watchersn
- ServerNamemaster
- In an instance of a Master.- Throws:
InterruptedIOException
-
-
Method Details
-
setInfoPort
-
nodeCreated
Description copied from class:ZKListener
Called when a new node has been created.- Overrides:
nodeCreated
in classZKListener
- Parameters:
path
- full path of the new node
-
nodeChildrenChanged
Description copied from class:ZKListener
Called when an existing node has a child node added or removed.- Overrides:
nodeChildrenChanged
in classZKListener
- Parameters:
path
- full path of the node whose children have changed
-
nodeDeleted
Description copied from class:ZKListener
Called when a node has been deleted- Overrides:
nodeDeleted
in classZKListener
- Parameters:
path
- full path of the deleted node
-
handle
-
updateBackupMasters
- Throws:
InterruptedIOException
-
fetchAndSetActiveMasterServerName
Fetches the active master's ServerName from zookeeper. -
getActiveMasterServerName
-
getActiveMasterInfoPort
-
getBackupMasterInfoPort
-
handleMasterNodeChange
Handle a change in the master node. Doesn't matter whether this was called from a nodeCreated or nodeDeleted event because there are no guarantees that the current state of the master node matches the event at the time of our next ZK request.Uses the watchAndCheckExists method which watches the master address node regardless of whether it exists or not. If it does exist (there is an active master), it returns true. Otherwise it returns false.
A watcher is set which guarantees that this method will get called again if there is another change in the master node.
-
blockUntilBecomingActiveMaster
Block until becoming the active master. Method blocks until there is not another active master and our attempt to become the new active master is successful. This also makes sure that we are watching the master znode so will be notified if another master dies.- Parameters:
checkInterval
- the interval to check if the master is stoppedstartupTaskGroup
- the task group for master startup to track the progress- Returns:
- True if no issue becoming active master else false if another master was running or if some other problem (zookeeper, stop flag has been set on this Master)
-
hasActiveMaster
boolean hasActiveMaster()Returns True if cluster has an active master. -
stop
-
getBackupMasters
Returns list of registered backup masters.
-