|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.hadoop.hbase.zookeeper.ZooKeeperWrapper
public class ZooKeeperWrapper
Wraps a ZooKeeper instance and adds HBase specific functionality. This class provides methods to: - read/write/delete the root region location in ZooKeeper. - set/check out of safe mode flag. ------------------------------------------ The following STATIC ZNodes are created: ------------------------------------------ - parentZNode : All the HBase directories are hosted under this parent node, default = "/hbase" - rsZNode : This is the directory where the RS's create ephemeral nodes. The master watches these nodes, and their expiry indicates RS death. The default location is "/hbase/rs" ------------------------------------------ The following DYNAMIC ZNodes are created: ------------------------------------------ - rootRegionZNode : Specifies the RS hosting root. - masterElectionZNode : ZNode used for election of the primary master when there are secondaries. All the masters race to write their addresses into this location, the one that succeeds is the primary. Others block. - clusterStateZNode : Determines if the cluster is running. Its default location is "/hbase/shutdown". It always has a value of "up". If present with the valus, cluster is up and running. If deleted, the cluster is shutting down. - rgnsInTransitZNode : All the nodes under this node are names of regions in transition. The first byte of the data for each of these nodes is the event type. This is used to deserialize the rest of the data.
Nested Class Summary | |
---|---|
static class |
ZooKeeperWrapper.ZNodePathAndData
|
Nested classes/interfaces inherited from interface org.apache.zookeeper.Watcher |
---|
org.apache.zookeeper.Watcher.Event |
Field Summary | |
---|---|
String |
clusterStateZNode
|
protected static org.apache.commons.logging.Log |
LOG
|
String |
parentZNode
|
Method Summary | |
---|---|
void |
clearRSDirectory()
Method used to make sure the region server directory is empty. |
void |
close()
Close this ZooKeeper session. |
static ZooKeeperWrapper |
createInstance(org.apache.hadoop.conf.Configuration conf,
String name)
|
void |
createOrUpdateUnassignedRegion(String regionName,
byte[] data)
This method will create a new region in transition entry in ZK with the speficied data if none exists. |
String |
createZNodeIfNotExists(String zNodeName)
|
String |
createZNodeIfNotExists(String zNodeName,
byte[] data,
org.apache.zookeeper.CreateMode createMode,
boolean watch)
|
boolean |
deleteRootRegionLocation()
Delete ZNode containing root region location. |
void |
deleteUnassignedRegion(String regionName)
|
void |
deleteZNode(String znode)
Unrecursive deletion of specified znode |
void |
deleteZNode(String znode,
boolean recursive)
Optionnally recursive deletion of specified znode |
void |
deleteZNode(String zNodeName,
int version)
|
String |
dump()
|
boolean |
ensureExists(String znode)
Make sure this znode exists by creating it if it's missing |
boolean |
exists(String znode,
boolean watch)
|
byte[] |
getData(String parentZNode,
String znode)
|
byte[] |
getDataAndWatch(String parentZNode,
String znode,
org.apache.zookeeper.Watcher watcher)
|
static ZooKeeperWrapper |
getInstance(org.apache.hadoop.conf.Configuration conf,
String name)
|
String |
getMasterElectionZNode()
Get the path of the masterElectionZNode |
String |
getParentZNode()
Get the path of the parent ZNode |
String |
getQuorumServers()
|
String |
getRegionInTransitionZNode()
Get the znode that has all the regions in transition. |
int |
getRSDirectoryCount()
|
String |
getRsZNode()
Get the path of this region server's znode |
String[] |
getServerStats(String server)
Gets the statistics from the given server. |
String[] |
getServerStats(String server,
int timeout)
Gets the statistics from the given server. |
long |
getSessionID()
This is for testing KeeperException.SessionExpiredException. |
byte[] |
getSessionPassword()
This is for testing KeeperException.SessionExpiredException. |
String |
getZNode(String parentZNode,
String znodeName)
|
String |
getZNodePathForHBase(String znodeName)
|
org.apache.zookeeper.ZooKeeper |
getZooKeeper()
|
static String |
getZookeeperClusterKey(org.apache.hadoop.conf.Configuration conf)
Get the key to the ZK ensemble for this configuration without adding a name at the end |
static String |
getZookeeperClusterKey(org.apache.hadoop.conf.Configuration conf,
String name)
Get the key to the ZK ensemble for this configuration and append a name at the end |
boolean |
isConnected()
|
List<String> |
listZnodes(String znode)
List all znodes in the specified path |
List<String> |
listZnodes(String znode,
org.apache.zookeeper.Watcher watcher)
List all znodes in the specified path and set a watcher on each |
void |
process(org.apache.zookeeper.WatchedEvent event)
This is the primary ZK watcher |
HServerAddress |
readMasterAddress(org.apache.zookeeper.Watcher watcher)
Read master address and set a watch on it. |
HServerAddress |
readMasterAddressOrThrow()
Read address of master server. |
HServerAddress |
readRootRegionLocation()
Read location of server storing root region. |
byte[] |
readZNode(String znodeName,
org.apache.zookeeper.data.Stat stat)
|
void |
reconnectToZk()
|
void |
registerListener(org.apache.zookeeper.Watcher watcher)
|
List<HServerAddress> |
scanAddressDirectory(String znode,
org.apache.zookeeper.Watcher watcher)
Scan a directory of address data. |
List<HServerAddress> |
scanRSDirectory()
Scans the regions servers directory |
List<HServerAddress> |
scanRSDirectory(org.apache.zookeeper.Watcher watcher)
Scans the regions servers directory and sets a watch on each znode |
boolean |
setClusterState(boolean up)
Set the cluster state, up or down |
void |
setClusterStateWatch()
Watch the state of the cluster, up or down |
void |
unregisterListener(org.apache.zookeeper.Watcher watcher)
|
boolean |
updateRSLocationGetWatch(HServerInfo info,
org.apache.zookeeper.Watcher watcher)
Update the RS address and set a watcher on the znode |
void |
updateUnassignedRegion(String regionName,
byte[] data)
Given a region name and some data, this method updates the region znode data under the UNASSGINED znode with the latest data. |
List<ZooKeeperWrapper.ZNodePathAndData> |
watchAndGetNewChildren(String znode)
Atomically adds a watch and reads data from the unwatched znodes in the UNASSGINED region. |
boolean |
watchMasterAddress(org.apache.zookeeper.Watcher watcher)
Set a watcher on the master address ZNode. |
void |
watchZNode(String zNodeName)
|
boolean |
writeMasterAddress(HServerAddress address)
Write address of master to ZooKeeper. |
boolean |
writeRootRegionLocation(HServerAddress address)
Write root region location to ZooKeeper. |
boolean |
writeRSLocation(HServerInfo info)
Write in ZK this RS startCode and address. |
boolean |
writeZNode(String znodeName,
byte[] data,
int version,
boolean watch)
|
void |
writeZNode(String parentPath,
String child,
String strData)
Write a znode and fail if it already exists |
void |
writeZNode(String parentPath,
String child,
String strData,
boolean failOnWrite)
Write (and optionally over-write) a znode |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static final org.apache.commons.logging.Log LOG
public final String parentZNode
public final String clusterStateZNode
Method Detail |
---|
public static ZooKeeperWrapper getInstance(org.apache.hadoop.conf.Configuration conf, String name)
public static ZooKeeperWrapper createInstance(org.apache.hadoop.conf.Configuration conf, String name)
public void reconnectToZk() throws IOException
IOException
public void registerListener(org.apache.zookeeper.Watcher watcher)
public void unregisterListener(org.apache.zookeeper.Watcher watcher)
public void process(org.apache.zookeeper.WatchedEvent event)
process
in interface org.apache.zookeeper.Watcher
Watcher.process(org.apache.zookeeper.WatchedEvent)
public String dump()
public String[] getServerStats(String server) throws IOException
server
- The server to get the statistics from.
IOException
- When the socket communication fails.public String[] getServerStats(String server, int timeout) throws IOException
server
- The server to get the statistics from.timeout
- The socket timeout to use.
IOException
- When the socket communication fails.public boolean exists(String znode, boolean watch)
public org.apache.zookeeper.ZooKeeper getZooKeeper()
public long getSessionID()
public byte[] getSessionPassword()
public String getQuorumServers()
public boolean isConnected()
public HServerAddress readRootRegionLocation()
public HServerAddress readMasterAddressOrThrow() throws IOException
IOException
- if there's a problem reading the ZNode.public HServerAddress readMasterAddress(org.apache.zookeeper.Watcher watcher)
watcher
- Watcher to set on master address ZNode if not null.
public void setClusterStateWatch()
watcher
- Watcher to set on cluster state nodepublic boolean setClusterState(boolean up)
up
- True to write the node, false to delete it
public boolean watchMasterAddress(org.apache.zookeeper.Watcher watcher)
watcher
- Watcher to set on master address ZNode.
public boolean ensureExists(String znode)
znode
- full path to znode
public boolean deleteRootRegionLocation()
public void deleteZNode(String znode) throws org.apache.zookeeper.KeeperException, InterruptedException
znode
-
org.apache.zookeeper.KeeperException
InterruptedException
public void deleteZNode(String znode, boolean recursive) throws org.apache.zookeeper.KeeperException, InterruptedException
znode
- recursive
-
org.apache.zookeeper.KeeperException
InterruptedException
public boolean writeRootRegionLocation(HServerAddress address)
address
- HServerAddress to write to ZK.
public boolean writeMasterAddress(HServerAddress address)
address
- HServerAddress of master.
public boolean writeRSLocation(HServerInfo info)
info
- The RS info
public boolean updateRSLocationGetWatch(HServerInfo info, org.apache.zookeeper.Watcher watcher)
info
- The RS infowatcher
- The watcher to put on the znode
public List<HServerAddress> scanRSDirectory()
public List<HServerAddress> scanRSDirectory(org.apache.zookeeper.Watcher watcher)
watcher
- a watch to use for each znode
public void clearRSDirectory()
public int getRSDirectoryCount()
public void close()
public String getZNode(String parentZNode, String znodeName)
public String getZNodePathForHBase(String znodeName)
public String getMasterElectionZNode()
public String getParentZNode()
public List<HServerAddress> scanAddressDirectory(String znode, org.apache.zookeeper.Watcher watcher)
znode
- The parent nodewatcher
- The watcher to put on the found znodes, if not null
public List<String> listZnodes(String znode)
znode
- path to list
public List<String> listZnodes(String znode, org.apache.zookeeper.Watcher watcher)
znode
- path to listwatcher
- watch to set, can be null
public byte[] getData(String parentZNode, String znode)
public byte[] getDataAndWatch(String parentZNode, String znode, org.apache.zookeeper.Watcher watcher)
public void writeZNode(String parentPath, String child, String strData) throws InterruptedException, org.apache.zookeeper.KeeperException
parentPath
- parent path to the new znodechild
- name of the znodestrData
- data to insert
InterruptedException
org.apache.zookeeper.KeeperException
public void writeZNode(String parentPath, String child, String strData, boolean failOnWrite) throws InterruptedException, org.apache.zookeeper.KeeperException
parentPath
- parent path to the new znodechild
- name of the znodestrData
- data to insertfailOnWrite
- true if an exception should be returned if the znode
already exists, false if it should be overwritten
InterruptedException
org.apache.zookeeper.KeeperException
public static String getZookeeperClusterKey(org.apache.hadoop.conf.Configuration conf)
conf
- Configuration to use to build the key
public static String getZookeeperClusterKey(org.apache.hadoop.conf.Configuration conf, String name)
conf
- Configuration to use to build the keyname
- Name that should be appended at the end if not empty or null
public String getRegionInTransitionZNode()
public String getRsZNode()
public void deleteZNode(String zNodeName, int version)
public String createZNodeIfNotExists(String zNodeName)
public void watchZNode(String zNodeName)
public String createZNodeIfNotExists(String zNodeName, byte[] data, org.apache.zookeeper.CreateMode createMode, boolean watch)
public byte[] readZNode(String znodeName, org.apache.zookeeper.data.Stat stat) throws IOException
IOException
public boolean writeZNode(String znodeName, byte[] data, int version, boolean watch) throws IOException
IOException
public void updateUnassignedRegion(String regionName, byte[] data)
regionName
- - encoded name of the regiondata
- - new serialized data to update the region znodepublic void createOrUpdateUnassignedRegion(String regionName, byte[] data)
regionName
- - encoded name of the regiondata
- - serialized data for the region znodepublic void deleteUnassignedRegion(String regionName)
public List<ZooKeeperWrapper.ZNodePathAndData> watchAndGetNewChildren(String znode)
znode
-
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |