|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.hadoop.hbase.zookeeper.ZKUtil
public class ZKUtil
Internal HBase utility class for ZooKeeper.
Contains only static methods and constants.
Methods all throw KeeperException if there is an unexpected
zookeeper exception, so callers of these methods must handle appropriately.
If ZK is required for the operation, the server will need to be aborted.
| Nested Class Summary | |
|---|---|
static class |
ZKUtil.NodeAndData
Simple class to hold a node path and node data. |
| Constructor Summary | |
|---|---|
ZKUtil()
|
|
| Method Summary | |
|---|---|
static void |
applyClusterKeyToConf(org.apache.hadoop.conf.Configuration conf,
java.lang.String key)
Apply the settings in the given key to the given configuration, this is used to communicate with distant clusters |
static void |
asyncCreate(ZooKeeperWatcher zkw,
java.lang.String znode,
byte[] data,
org.apache.zookeeper.AsyncCallback.StringCallback cb,
java.lang.Object ctx)
Async creates the specified node with the specified data. |
static int |
checkExists(ZooKeeperWatcher zkw,
java.lang.String znode)
Check if the specified node exists. |
static org.apache.zookeeper.ZooKeeper |
connect(org.apache.hadoop.conf.Configuration conf,
java.lang.String ensemble,
org.apache.zookeeper.Watcher watcher)
|
static org.apache.zookeeper.ZooKeeper |
connect(org.apache.hadoop.conf.Configuration conf,
java.lang.String ensemble,
org.apache.zookeeper.Watcher watcher,
java.lang.String descriptor)
|
static org.apache.zookeeper.ZooKeeper |
connect(org.apache.hadoop.conf.Configuration conf,
org.apache.zookeeper.Watcher watcher)
Creates a new connection to ZooKeeper, pulling settings and ensemble config from the specified configuration object using methods from ZKConfig. |
static void |
createAndFailSilent(ZooKeeperWatcher zkw,
java.lang.String znode)
Creates the specified node, if the node does not exist. |
static int |
createAndWatch(ZooKeeperWatcher zkw,
java.lang.String znode,
byte[] data)
Creates the specified node with the specified data and watches it. |
static boolean |
createEphemeralNodeAndWatch(ZooKeeperWatcher zkw,
java.lang.String znode,
byte[] data)
Set the specified znode to be an ephemeral node carrying the specified data. |
static boolean |
createNodeIfNotExistsAndWatch(ZooKeeperWatcher zkw,
java.lang.String znode,
byte[] data)
Creates the specified znode to be a persistent node carrying the specified data. |
static void |
createSetData(ZooKeeperWatcher zkw,
java.lang.String znode,
byte[] data)
Set data into node creating node if it doesn't yet exist. |
static void |
createWithParents(ZooKeeperWatcher zkw,
java.lang.String znode)
Creates the specified node and all parent nodes required for it to exist. |
static void |
deleteChildrenRecursively(ZooKeeperWatcher zkw,
java.lang.String node)
Delete all the children of the specified node but not the node itself. |
static void |
deleteNode(ZooKeeperWatcher zkw,
java.lang.String node)
Delete the specified node. |
static boolean |
deleteNode(ZooKeeperWatcher zkw,
java.lang.String node,
int version)
Delete the specified node with the specified version. |
static void |
deleteNodeFailSilent(ZooKeeperWatcher zkw,
java.lang.String node)
Deletes the specified node. |
static void |
deleteNodeRecursively(ZooKeeperWatcher zkw,
java.lang.String node)
Delete the specified node and all of it's children. |
static java.lang.String |
dump(ZooKeeperWatcher zkw)
|
static byte[] |
getData(ZooKeeperWatcher zkw,
java.lang.String znode)
Get znode data. |
static byte[] |
getDataAndWatch(ZooKeeperWatcher zkw,
java.lang.String znode)
Get the data at the specified znode and set a watch. |
static HServerAddress |
getDataAsAddress(ZooKeeperWatcher zkw,
java.lang.String znode)
Get the data at the specified znode, deserialize it as an HServerAddress, and set a watch. |
static byte[] |
getDataNoWatch(ZooKeeperWatcher zkw,
java.lang.String znode,
org.apache.zookeeper.data.Stat stat)
Get the data at the specified znode without setting a watch. |
static java.lang.String |
getNodeName(HServerInfo serverInfo)
Get the unique node-name for the specified regionserver. |
static java.lang.String |
getNodeName(java.lang.String path)
Get the name of the current node from the specified fully-qualified path. |
static int |
getNumberOfChildren(ZooKeeperWatcher zkw,
java.lang.String znode)
Get the number of children of the specified node. |
static java.lang.String |
getParent(java.lang.String node)
Returns the full path of the immediate parent of the specified node. |
static java.lang.String[] |
getServerStats(java.lang.String server)
Gets the statistics from the given server. |
static java.lang.String[] |
getServerStats(java.lang.String server,
int timeout)
Gets the statistics from the given server. |
static java.lang.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 java.lang.String |
getZooKeeperClusterKey(org.apache.hadoop.conf.Configuration conf,
java.lang.String name)
Get the key to the ZK ensemble for this configuration and append a name at the end |
static java.lang.String |
joinZNode(java.lang.String prefix,
java.lang.String suffix)
Join the prefix znode name with the suffix znode name to generate a proper full znode name. |
static java.util.List<HServerAddress> |
listChildrenAndGetAsAddresses(ZooKeeperWatcher zkw,
java.lang.String znode)
Lists the children of the specified znode, retrieving the data of each child as a server address. |
static java.util.List<java.lang.String> |
listChildrenAndWatchForNewChildren(ZooKeeperWatcher zkw,
java.lang.String znode)
Lists the children znodes of the specified znode. |
static java.util.List<java.lang.String> |
listChildrenAndWatchThem(ZooKeeperWatcher zkw,
java.lang.String znode)
List all the children of the specified znode, setting a watch for children changes and also setting a watch on every individual child in order to get the NodeCreated and NodeDeleted events. |
static java.util.List<java.lang.String> |
listChildrenNoWatch(ZooKeeperWatcher zkw,
java.lang.String znode)
Lists the children of the specified znode without setting any watches. |
static boolean |
nodeHasChildren(ZooKeeperWatcher zkw,
java.lang.String znode)
Checks if the specified znode has any children. |
static boolean |
setAddressAndWatch(ZooKeeperWatcher zkw,
java.lang.String znode,
HServerAddress address)
Set the specified znode to be an ephemeral node carrying the specified server address. |
static void |
setData(ZooKeeperWatcher zkw,
java.lang.String znode,
byte[] data)
Sets the data of the existing znode to be the specified data. |
static boolean |
setData(ZooKeeperWatcher zkw,
java.lang.String znode,
byte[] data,
int expectedVersion)
Sets the data of the existing znode to be the specified data. |
static java.lang.String[] |
transformClusterKey(java.lang.String key)
Separate the given key into the three configurations it should contain: hbase.zookeeper.quorum, hbase.zookeeper.client.port and zookeeper.znode.parent |
static void |
updateExistingNodeData(ZooKeeperWatcher zkw,
java.lang.String znode,
byte[] data,
int expectedVersion)
Update the data of an existing node with the expected version to have the specified data. |
static boolean |
watchAndCheckExists(ZooKeeperWatcher zkw,
java.lang.String znode)
Watch the specified znode for delete/create/change events. |
static java.util.List<ZKUtil.NodeAndData> |
watchAndGetNewChildren(ZooKeeperWatcher zkw,
java.lang.String baseNode)
Atomically add watches and read data from all unwatched unassigned nodes. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public ZKUtil()
| Method Detail |
|---|
public static org.apache.zookeeper.ZooKeeper connect(org.apache.hadoop.conf.Configuration conf,
org.apache.zookeeper.Watcher watcher)
throws java.io.IOException
ZKConfig.
Sets the connection status monitoring watcher to the specified watcher.
conf - configuration to pull ensemble and other settings fromwatcher - watcher to monitor connection changes
java.io.IOException - if unable to connect to zk or config problem
public static org.apache.zookeeper.ZooKeeper connect(org.apache.hadoop.conf.Configuration conf,
java.lang.String ensemble,
org.apache.zookeeper.Watcher watcher)
throws java.io.IOException
java.io.IOException
public static org.apache.zookeeper.ZooKeeper connect(org.apache.hadoop.conf.Configuration conf,
java.lang.String ensemble,
org.apache.zookeeper.Watcher watcher,
java.lang.String descriptor)
throws java.io.IOException
java.io.IOException
public static java.lang.String joinZNode(java.lang.String prefix,
java.lang.String suffix)
prefix - beginning of znode namesuffix - ending of znode name
public static java.lang.String getParent(java.lang.String node)
node - path to get parent of
public static java.lang.String getNodeName(HServerInfo serverInfo)
serverInfo - server information
public static java.lang.String getNodeName(java.lang.String path)
path - fully-qualified path
public static java.lang.String getZooKeeperClusterKey(org.apache.hadoop.conf.Configuration conf)
conf - Configuration to use to build the key
public static java.lang.String getZooKeeperClusterKey(org.apache.hadoop.conf.Configuration conf,
java.lang.String name)
conf - Configuration to use to build the keyname - Name that should be appended at the end if not empty or null
public static void applyClusterKeyToConf(org.apache.hadoop.conf.Configuration conf,
java.lang.String key)
throws java.io.IOException
conf - configuration object to configurekey - string that contains the 3 required configuratins
java.io.IOException
public static java.lang.String[] transformClusterKey(java.lang.String key)
throws java.io.IOException
key -
java.io.IOException
public static boolean watchAndCheckExists(ZooKeeperWatcher zkw,
java.lang.String znode)
throws org.apache.zookeeper.KeeperException
zkw - zk referenceznode - path of node to watch
org.apache.zookeeper.KeeperException - if unexpected zookeeper exception
public static int checkExists(ZooKeeperWatcher zkw,
java.lang.String znode)
throws org.apache.zookeeper.KeeperException
zkw - zk referenceznode - path of node to watch
org.apache.zookeeper.KeeperException - if unexpected zookeeper exception
public static java.util.List<java.lang.String> listChildrenAndWatchForNewChildren(ZooKeeperWatcher zkw,
java.lang.String znode)
throws org.apache.zookeeper.KeeperException
zkw - zk referenceznode - path of node to list and watch children of
org.apache.zookeeper.KeeperException - if unexpected zookeeper exception
public static java.util.List<java.lang.String> listChildrenAndWatchThem(ZooKeeperWatcher zkw,
java.lang.String znode)
throws org.apache.zookeeper.KeeperException
zkw - zookeeper referenceznode - node to get children of and watch
org.apache.zookeeper.KeeperException
public static java.util.List<HServerAddress> listChildrenAndGetAsAddresses(ZooKeeperWatcher zkw,
java.lang.String znode)
throws org.apache.zookeeper.KeeperException
zkw - zookeeper referenceznode - node to get children of as addresses
org.apache.zookeeper.KeeperException - if unexpected zookeeper exception
public static java.util.List<java.lang.String> listChildrenNoWatch(ZooKeeperWatcher zkw,
java.lang.String znode)
throws org.apache.zookeeper.KeeperException
zkw - zookeeper referenceznode - node to get children of as addresses
org.apache.zookeeper.KeeperException - if unexpected zookeeper exception
public static java.util.List<ZKUtil.NodeAndData> watchAndGetNewChildren(ZooKeeperWatcher zkw,
java.lang.String baseNode)
throws org.apache.zookeeper.KeeperException
This works because master is the only person deleting nodes.
org.apache.zookeeper.KeeperException
public static boolean nodeHasChildren(ZooKeeperWatcher zkw,
java.lang.String znode)
throws org.apache.zookeeper.KeeperException
zkw - zk referenceznode - path of node to check for children of
org.apache.zookeeper.KeeperException - if unexpected zookeeper exception
public static int getNumberOfChildren(ZooKeeperWatcher zkw,
java.lang.String znode)
throws org.apache.zookeeper.KeeperException
zkw - zk referenceznode - path of node to count children of
org.apache.zookeeper.KeeperException - if unexpected zookeeper exception
public static byte[] getData(ZooKeeperWatcher zkw,
java.lang.String znode)
throws org.apache.zookeeper.KeeperException
org.apache.zookeeper.KeeperException
public static byte[] getDataAndWatch(ZooKeeperWatcher zkw,
java.lang.String znode)
throws org.apache.zookeeper.KeeperException
zkw - zk referenceznode - path of node
org.apache.zookeeper.KeeperException - if unexpected zookeeper exception
public static byte[] getDataNoWatch(ZooKeeperWatcher zkw,
java.lang.String znode,
org.apache.zookeeper.data.Stat stat)
throws org.apache.zookeeper.KeeperException
zkw - zk referenceznode - path of nodestat - node status to set if node exists
org.apache.zookeeper.KeeperException - if unexpected zookeeper exception
public static HServerAddress getDataAsAddress(ZooKeeperWatcher zkw,
java.lang.String znode)
throws org.apache.zookeeper.KeeperException
zkw - zk referenceznode - path of node
org.apache.zookeeper.KeeperException - if unexpected zookeeper exception
public static void updateExistingNodeData(ZooKeeperWatcher zkw,
java.lang.String znode,
byte[] data,
int expectedVersion)
throws org.apache.zookeeper.KeeperException
zkw - zk referenceznode - data - expectedVersion -
org.apache.zookeeper.KeeperException - if unexpected zookeeper exception
KeeperException.BadVersionException - if version mismatch
public static boolean setAddressAndWatch(ZooKeeperWatcher zkw,
java.lang.String znode,
HServerAddress address)
throws org.apache.zookeeper.KeeperException
zkw - zk referenceznode - path of nodeaddress - server address
org.apache.zookeeper.KeeperException - if unexpected zookeeper exception
public static boolean setData(ZooKeeperWatcher zkw,
java.lang.String znode,
byte[] data,
int expectedVersion)
throws org.apache.zookeeper.KeeperException,
org.apache.zookeeper.KeeperException.NoNodeException
If the node does not exist, a KeeperException.NoNodeException will be thrown.
If their is a version mismatch, method returns null.
No watches are set but setting data will trigger other watchers of this node.
If there is another problem, a KeeperException will be thrown.
zkw - zk referenceznode - path of nodedata - data to set for nodeexpectedVersion - version expected when setting data
org.apache.zookeeper.KeeperException - if unexpected zookeeper exception
org.apache.zookeeper.KeeperException.NoNodeException
public static void createSetData(ZooKeeperWatcher zkw,
java.lang.String znode,
byte[] data)
throws org.apache.zookeeper.KeeperException
zkw - zk referenceznode - path of nodedata - data to set for node
org.apache.zookeeper.KeeperException
public static void setData(ZooKeeperWatcher zkw,
java.lang.String znode,
byte[] data)
throws org.apache.zookeeper.KeeperException,
org.apache.zookeeper.KeeperException.NoNodeException
If the node does not exist, a KeeperException.NoNodeException will be thrown.
No watches are set but setting data will trigger other watchers of this node.
If there is another problem, a KeeperException will be thrown.
zkw - zk referenceznode - path of nodedata - data to set for node
org.apache.zookeeper.KeeperException - if unexpected zookeeper exception
org.apache.zookeeper.KeeperException.NoNodeException
public static boolean createEphemeralNodeAndWatch(ZooKeeperWatcher zkw,
java.lang.String znode,
byte[] data)
throws org.apache.zookeeper.KeeperException
zkw - zk referenceznode - path of nodedata - data of node
org.apache.zookeeper.KeeperException - if unexpected zookeeper exception
public static boolean createNodeIfNotExistsAndWatch(ZooKeeperWatcher zkw,
java.lang.String znode,
byte[] data)
throws org.apache.zookeeper.KeeperException
zkw - zk referenceznode - path of nodedata - data of node
org.apache.zookeeper.KeeperException - if unexpected zookeeper exception
public static int createAndWatch(ZooKeeperWatcher zkw,
java.lang.String znode,
byte[] data)
throws org.apache.zookeeper.KeeperException,
org.apache.zookeeper.KeeperException.NodeExistsException
Throws an exception if the node already exists.
The node created is persistent and open access.
Returns the version number of the created node if successful.
zkw - zk referenceznode - path of node to createdata - data of node to create
org.apache.zookeeper.KeeperException - if unexpected zookeeper exception
KeeperException.NodeExistsException - if node already exists
public static void asyncCreate(ZooKeeperWatcher zkw,
java.lang.String znode,
byte[] data,
org.apache.zookeeper.AsyncCallback.StringCallback cb,
java.lang.Object ctx)
throws org.apache.zookeeper.KeeperException,
org.apache.zookeeper.KeeperException.NodeExistsException
Throws an exception if the node already exists.
The node created is persistent and open access.
zkw - zk referenceznode - path of node to createdata - data of node to createcb - ctx -
org.apache.zookeeper.KeeperException - if unexpected zookeeper exception
KeeperException.NodeExistsException - if node already exists
public static void createAndFailSilent(ZooKeeperWatcher zkw,
java.lang.String znode)
throws org.apache.zookeeper.KeeperException
zkw - zk referenceznode - path of node
org.apache.zookeeper.KeeperException - if unexpected zookeeper exception
public static void createWithParents(ZooKeeperWatcher zkw,
java.lang.String znode)
throws org.apache.zookeeper.KeeperException
zkw - zk referenceznode - path of node
org.apache.zookeeper.KeeperException - if unexpected zookeeper exception
public static void deleteNode(ZooKeeperWatcher zkw,
java.lang.String node)
throws org.apache.zookeeper.KeeperException
org.apache.zookeeper.KeeperException
public static boolean deleteNode(ZooKeeperWatcher zkw,
java.lang.String node,
int version)
throws org.apache.zookeeper.KeeperException
org.apache.zookeeper.KeeperException
public static void deleteNodeFailSilent(ZooKeeperWatcher zkw,
java.lang.String node)
throws org.apache.zookeeper.KeeperException
zkw - node -
org.apache.zookeeper.KeeperException
public static void deleteNodeRecursively(ZooKeeperWatcher zkw,
java.lang.String node)
throws org.apache.zookeeper.KeeperException
org.apache.zookeeper.KeeperException
public static void deleteChildrenRecursively(ZooKeeperWatcher zkw,
java.lang.String node)
throws org.apache.zookeeper.KeeperException
org.apache.zookeeper.KeeperExceptionpublic static java.lang.String dump(ZooKeeperWatcher zkw)
public static java.lang.String[] getServerStats(java.lang.String server)
throws java.io.IOException
server - The server to get the statistics from.
java.io.IOException - When the socket communication fails.
public static java.lang.String[] getServerStats(java.lang.String server,
int timeout)
throws java.io.IOException
server - The server to get the statistics from.timeout - The socket timeout to use.
java.io.IOException - When the socket communication fails.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||