Class MetaTableLocator

java.lang.Object
org.apache.hadoop.hbase.zookeeper.MetaTableLocator

@Private public final class MetaTableLocator extends Object
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 Details

    • LOG

      private static final org.slf4j.Logger LOG
  • Constructor Details

  • 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

      public static ServerName getMetaRegionLocation(ZKWatcher zkw, int replicaId)
      Gets the meta region location, if available. Does not block.
      Parameters:
      zkw - reference to the ZKWatcher which also contains configuration and operation
      replicaId - the ID of the replica
      Returns:
      server name
    • waitMetaRegionLocation

      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 the ZKWatcher which also contains configuration and operation
      timeout - 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 waiting
      NotAllMetaRegionsOnlineException - 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 the ZKWatcher which also contains configuration and operation
      replicaId - the ID of the replica
      timeout - 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 fails
      NotAllMetaRegionsOnlineException - 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 of hbase:meta in ZooKeeper to the specified server address.
      Parameters:
      zookeeper - zookeeper reference
      serverName - The server hosting hbase: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 of hbase:meta in ZooKeeper to the specified server address.
      Parameters:
      zookeeper - reference to the ZKWatcher which also contains configuration and operation
      serverName - the name of the server
      replicaId - the ID of the replica
      state - 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 the ZKWatcher which also contains configuration and operation
      replicaId - 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 of hbase: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 the ZKWatcher which also contains configuration and constants
      replicaId - the ID of the replica
      timeout - maximum time to wait in millis
      Returns:
      ServerName or null if we timed out.
      Throws:
      InterruptedException - if waiting for the socket operation fails