Class MetaTableLocator
java.lang.Object
org.apache.hadoop.hbase.zookeeper.MetaTableLocator
Utility class to perform operation (get/wait for/verify/set/delete) on znode in ZooKeeper which
keeps hbase:meta region server location.
Stateless class with a bunch of static methods. Doesn't manage resources passed in (e.g.
Connection, ZKWatcher etc).
Meta region location is set by
RegionServerServices
. This class doesn't use ZK
watchers, rather accesses ZK directly.
TODO: rewrite using RPC calls to master to find out about hbase:meta.-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprivate static ServerName
blockUntilAvailable
(ZKWatcher zkw, int replicaId, long timeout) Wait until the meta region is available and is not in transition.static void
deleteMetaLocation
(ZKWatcher zookeeper) Deletes the location ofhbase:meta
in ZooKeeper.static void
deleteMetaLocation
(ZKWatcher zookeeper, int replicaId) static ServerName
Gets the meta region location, if available.static ServerName
getMetaRegionLocation
(ZKWatcher zkw, int replicaId) Gets the meta region location, if available.static RegionState
Load the meta region state from the meta server ZNode.static RegionState
getMetaRegionState
(ZKWatcher zkw, int replicaId) Load the meta region state from the meta region server ZNode.static void
setMetaLocation
(ZKWatcher zookeeper, ServerName serverName, int replicaId, RegionState.State state) Sets the location ofhbase:meta
in ZooKeeper to the specified server address.static void
setMetaLocation
(ZKWatcher zookeeper, ServerName serverName, RegionState.State state) Sets the location ofhbase:meta
in ZooKeeper to the specified server address.private static ServerName
waitMetaRegionLocation
(ZKWatcher zkw, int replicaId, long timeout) Gets the meta region location, if available, and waits for up to the specified timeout if not immediately available.static ServerName
waitMetaRegionLocation
(ZKWatcher zkw, long timeout) Gets the meta region location, if available, and waits for up to the specified timeout if not immediately available.
-
Field Details
-
LOG
-
-
Constructor Details
-
MetaTableLocator
private MetaTableLocator()
-
-
Method Details
-
getMetaRegionLocation
Gets the meta region location, if available. Does not block.- Parameters:
zkw
- zookeeper connection to use- Returns:
- server name or null if we failed to get the data.
-
getMetaRegionLocation
Gets the meta region location, if available. Does not block.- Parameters:
zkw
- reference to theZKWatcher
which also contains configuration and operationreplicaId
- the ID of the replica- Returns:
- server name
-
waitMetaRegionLocation
public static ServerName waitMetaRegionLocation(ZKWatcher zkw, long timeout) throws InterruptedException, NotAllMetaRegionsOnlineException Gets the meta region location, if available, and waits for up to the specified timeout if not immediately available. Given the zookeeper notification could be delayed, we will try to get the latest data.- Parameters:
zkw
- reference to theZKWatcher
which also contains configuration and operationtimeout
- maximum time to wait, in millis- Returns:
- server name for server hosting meta region formatted as per
ServerName
, or null if none available - Throws:
InterruptedException
- if interrupted while waitingNotAllMetaRegionsOnlineException
- if a meta or root region is not online
-
waitMetaRegionLocation
private static ServerName waitMetaRegionLocation(ZKWatcher zkw, int replicaId, long timeout) throws InterruptedException, NotAllMetaRegionsOnlineException Gets the meta region location, if available, and waits for up to the specified timeout if not immediately available. Given the zookeeper notification could be delayed, we will try to get the latest data.- Parameters:
zkw
- reference to theZKWatcher
which also contains configuration and operationreplicaId
- the ID of the replicatimeout
- maximum time to wait, in millis- Returns:
- server name for server hosting meta region formatted as per
ServerName
, or null if none available - Throws:
InterruptedException
- if waiting for the socket operation failsNotAllMetaRegionsOnlineException
- if a meta or root region is not online
-
setMetaLocation
public static void setMetaLocation(ZKWatcher zookeeper, ServerName serverName, RegionState.State state) throws org.apache.zookeeper.KeeperException Sets the location ofhbase:meta
in ZooKeeper to the specified server address.- Parameters:
zookeeper
- zookeeper referenceserverName
- The server hostinghbase:meta
state
- The region transition state- Throws:
org.apache.zookeeper.KeeperException
- unexpected zookeeper exception
-
setMetaLocation
public static void setMetaLocation(ZKWatcher zookeeper, ServerName serverName, int replicaId, RegionState.State state) throws org.apache.zookeeper.KeeperException Sets the location ofhbase:meta
in ZooKeeper to the specified server address.- Parameters:
zookeeper
- reference to theZKWatcher
which also contains configuration and operationserverName
- the name of the serverreplicaId
- the ID of the replicastate
- the state of the region- Throws:
org.apache.zookeeper.KeeperException
- if a ZooKeeper operation fails
-
getMetaRegionState
public static RegionState getMetaRegionState(ZKWatcher zkw) throws org.apache.zookeeper.KeeperException Load the meta region state from the meta server ZNode.- Throws:
org.apache.zookeeper.KeeperException
-
getMetaRegionState
public static RegionState getMetaRegionState(ZKWatcher zkw, int replicaId) throws org.apache.zookeeper.KeeperException Load the meta region state from the meta region server ZNode.- Parameters:
zkw
- reference to theZKWatcher
which also contains configuration and operationreplicaId
- the ID of the replica- Throws:
org.apache.zookeeper.KeeperException
- if a ZooKeeper operation fails
-
deleteMetaLocation
public static void deleteMetaLocation(ZKWatcher zookeeper) throws org.apache.zookeeper.KeeperException Deletes the location ofhbase:meta
in ZooKeeper.- Parameters:
zookeeper
- zookeeper reference- Throws:
org.apache.zookeeper.KeeperException
- unexpected zookeeper exception
-
deleteMetaLocation
public static void deleteMetaLocation(ZKWatcher zookeeper, int replicaId) throws org.apache.zookeeper.KeeperException - Throws:
org.apache.zookeeper.KeeperException
-
blockUntilAvailable
private static ServerName blockUntilAvailable(ZKWatcher zkw, int replicaId, long timeout) throws InterruptedException Wait until the meta region is available and is not in transition.- Parameters:
zkw
- reference to theZKWatcher
which also contains configuration and constantsreplicaId
- the ID of the replicatimeout
- maximum time to wait in millis- Returns:
- ServerName or null if we timed out.
- Throws:
InterruptedException
- if waiting for the socket operation fails
-