org.apache.hadoop.hbase.zookeeper
Class ZooKeeperWrapper

java.lang.Object
  extended by org.apache.hadoop.hbase.zookeeper.ZooKeeperWrapper
All Implemented Interfaces:
HConstants

public class ZooKeeperWrapper
extends Object
implements HConstants

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.


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.apache.hadoop.hbase.HConstants
HConstants.Modify
 
Field Summary
 String clusterStateZNode
           
protected static org.apache.commons.logging.Log LOG
           
 
Fields inherited from interface org.apache.hadoop.hbase.HConstants
ALL_VERSIONS, CATALOG_FAMILY, CATALOG_FAMILY_STR, CATALOG_HISTORIAN_FAMILY, CLUSTER_DISTRIBUTED, CLUSTER_IS_DISTRIBUTED, CLUSTER_IS_LOCAL, DEFAULT_HOST, DEFAULT_MASTER_INFOPORT, DEFAULT_MASTER_PORT, DEFAULT_MAX_FILE_SIZE, DEFAULT_REGION_SERVER_CLASS, DEFAULT_REGIONSERVER_INFOPORT, DEFAULT_REGIONSERVER_PORT, DEFAULT_SIZE_RESERVATION_BLOCK, DEFAULT_ZOOKEEPER_PAUSE, DEFAULT_ZOOKEEPER_RETRIES, EMPTY_BYTE_ARRAY, EMPTY_END_ROW, EMPTY_START_ROW, FILE_SYSTEM_VERSION, FOREVER, HBASE_CLIENT_RETRIES_NUMBER_KEY, HBASE_DIR, HREGION_COMPACTIONDIR_NAME, HREGION_LOGDIR_NAME, HREGION_OLDLOGFILE_NAME, IN_MEMORY, LAST_ROW, LATEST_TIMESTAMP, LATEST_TIMESTAMP_BYTES, MAJOR_COMPACTION_PERIOD, MASTER_PORT, MAX_ROW_LENGTH, MAXIMUM_VALUE_LENGTH, META_ROW_DELIMITER, META_TABLE_NAME, NAME, NINES, REGION_SERVER_CLASS, REGION_SERVER_IMPL, REGIONINFO_QUALIFIER, REGIONSERVER_PORT, RETRY_BACKOFF, ROOT_TABLE_NAME, SERVER_QUALIFIER, SPLITA_QUALIFIER, SPLITB_QUALIFIER, STARTCODE_QUALIFIER, THREAD_WAKE_FREQUENCY, UTF8_ENCODING, VERSION_FILE_NAME, VERSIONS, WEEK_IN_SECONDS, ZERO_L, ZEROES, ZOOKEEPER_CONFIG_NAME, ZOOKEEPER_PAUSE, ZOOKEEPER_QUORUM, ZOOKEEPER_RETRIES
 
Constructor Summary
ZooKeeperWrapper(HBaseConfiguration conf, org.apache.zookeeper.Watcher watcher)
          Create a ZooKeeperWrapper.
 
Method Summary
 boolean checkOutOfSafeMode()
          Check if we're out of safe mode.
 void clearRSDirectory()
          Method used to make sure the region server directory is empty.
 void close()
          Close this ZooKeeper session.
 boolean deleteRootRegionLocation()
          Delete ZNode containing root region location.
 String dump()
           
 String getMasterElectionZNode()
          Get the path of the masterElectionZNode
 String getQuorumServers()
           
 long getSessionID()
          This is for testing KeeperException.SessionExpiredException.
 byte[] getSessionPassword()
          This is for testing KeeperException.SessionExpiredException.
 org.apache.zookeeper.ZooKeeper getZooKeeper()
           
 boolean isConnected()
           
 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.
 List<HServerAddress> scanRSDirectory()
          Scans the regions servers directory
 boolean setClusterState(boolean up)
          Set the cluster state, up or down
 void setClusterStateWatch(org.apache.zookeeper.Watcher watcher)
          Watch the state of the cluster, up or down
 boolean updateRSLocationGetWatch(HServerInfo info, org.apache.zookeeper.Watcher watcher)
          Update the RS address and set a watcher on the znode
 boolean watchMasterAddress(org.apache.zookeeper.Watcher watcher)
          Set a watcher on the master address ZNode.
 boolean writeMasterAddress(HServerAddress address)
          Write address of master to ZooKeeper.
 boolean writeOutOfSafeMode()
          Create ephemeral ZNode signifying that we're out of safe mode.
 boolean writeRootRegionLocation(HServerAddress address)
          Write root region location to ZooKeeper.
 boolean writeRSLocation(HServerInfo info)
          Write in ZK this RS startCode and address.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG

protected static final org.apache.commons.logging.Log LOG

clusterStateZNode

public final String clusterStateZNode
Constructor Detail

ZooKeeperWrapper

public ZooKeeperWrapper(HBaseConfiguration conf,
                        org.apache.zookeeper.Watcher watcher)
                 throws IOException
Create a ZooKeeperWrapper.

Parameters:
conf - HBaseConfiguration to read settings from.
watcher - ZooKeeper watcher to register.
Throws:
IOException - If a connection error occurs.
Method Detail

dump

public String dump()
Returns:
String dump of everything in ZooKeeper.

getZooKeeper

public org.apache.zookeeper.ZooKeeper getZooKeeper()
Returns:
ZooKeeper used by this wrapper.

getSessionID

public long getSessionID()
This is for testing KeeperException.SessionExpiredException. See HBASE-1232.

Returns:
long session ID of this ZooKeeper session.

getSessionPassword

public byte[] getSessionPassword()
This is for testing KeeperException.SessionExpiredException. See HBASE-1232.

Returns:
byte[] password of this ZooKeeper session.

getQuorumServers

public String getQuorumServers()
Returns:
host:port list of quorum servers.

isConnected

public boolean isConnected()
Returns:
true if currently connected to ZooKeeper, false otherwise.

readRootRegionLocation

public HServerAddress readRootRegionLocation()
Read location of server storing root region.

Returns:
HServerAddress pointing to server serving root region or null if there was a problem reading the ZNode.

readMasterAddressOrThrow

public HServerAddress readMasterAddressOrThrow()
                                        throws IOException
Read address of master server.

Returns:
HServerAddress of master server.
Throws:
IOException - if there's a problem reading the ZNode.

readMasterAddress

public HServerAddress readMasterAddress(org.apache.zookeeper.Watcher watcher)
Read master address and set a watch on it.

Parameters:
watcher - Watcher to set on master address ZNode if not null.
Returns:
HServerAddress of master or null if there was a problem reading the ZNode. The watcher is set only if the result is not null.

setClusterStateWatch

public void setClusterStateWatch(org.apache.zookeeper.Watcher watcher)
Watch the state of the cluster, up or down

Parameters:
watcher - Watcher to set on cluster state node

setClusterState

public boolean setClusterState(boolean up)
Set the cluster state, up or down

Parameters:
up - True to write the node, false to delete it
Returns:
true if it worked, else it's false

watchMasterAddress

public boolean watchMasterAddress(org.apache.zookeeper.Watcher watcher)
Set a watcher on the master address ZNode. The watcher will be set unless an exception occurs with ZooKeeper.

Parameters:
watcher - Watcher to set on master address ZNode.
Returns:
true if watcher was set, false otherwise.

deleteRootRegionLocation

public boolean deleteRootRegionLocation()
Delete ZNode containing root region location.

Returns:
true if operation succeeded, false otherwise.

writeRootRegionLocation

public boolean writeRootRegionLocation(HServerAddress address)
Write root region location to ZooKeeper. If address is null, delete ZNode. containing root region location.

Parameters:
address - HServerAddress to write to ZK.
Returns:
true if operation succeeded, false otherwise.

writeMasterAddress

public boolean writeMasterAddress(HServerAddress address)
Write address of master to ZooKeeper.

Parameters:
address - HServerAddress of master.
Returns:
true if operation succeeded, false otherwise.

checkOutOfSafeMode

public boolean checkOutOfSafeMode()
Check if we're out of safe mode. Being out of safe mode is signified by an ephemeral ZNode existing in ZooKeeper.

Returns:
true if we're out of safe mode, false otherwise.

writeOutOfSafeMode

public boolean writeOutOfSafeMode()
Create ephemeral ZNode signifying that we're out of safe mode.

Returns:
true if ephemeral ZNode created successfully, false otherwise.

writeRSLocation

public boolean writeRSLocation(HServerInfo info)
Write in ZK this RS startCode and address. Ensures that the full path exists.

Parameters:
info - The RS info
Returns:
true if the location was written, false if it failed

updateRSLocationGetWatch

public boolean updateRSLocationGetWatch(HServerInfo info,
                                        org.apache.zookeeper.Watcher watcher)
Update the RS address and set a watcher on the znode

Parameters:
info - The RS info
watcher - The watcher to put on the znode
Returns:
true if the update is done, false if it failed

scanRSDirectory

public List<HServerAddress> scanRSDirectory()
Scans the regions servers directory

Returns:
A list of server addresses

clearRSDirectory

public void clearRSDirectory()
Method used to make sure the region server directory is empty.


close

public void close()
Close this ZooKeeper session.


getMasterElectionZNode

public String getMasterElectionZNode()
Get the path of the masterElectionZNode

Returns:
the path to masterElectionZNode


Copyright © 2009 The Apache Software Foundation