Class ZKNodeTracker

java.lang.Object
org.apache.hadoop.hbase.zookeeper.ZKListener
org.apache.hadoop.hbase.zookeeper.ZKNodeTracker
Direct Known Subclasses:
ClusterStatusTracker, MasterAddressTracker

@Private public abstract class ZKNodeTracker extends ZKListener
Tracks the availability and value of a single ZooKeeper node.

Utilizes the ZKListener interface to get the necessary ZooKeeper events related to the node.

This is the base class used by trackers in both the Master and RegionServers.

  • Field Details

    • LOG

      protected static final org.slf4j.Logger LOG
    • node

      protected final String node
      Path of node being tracked
    • data

      private byte[] data
      Data of the node being tracked
    • abortable

      protected final Abortable abortable
      Used to abort if a fatal error occurs
    • stopped

      private boolean stopped
  • Constructor Details

    • ZKNodeTracker

      public ZKNodeTracker(ZKWatcher watcher, String node, Abortable abortable)
      Constructs a new ZK node tracker.

      After construction, use start() to kick off tracking.

      Parameters:
      watcher - reference to the ZKWatcher which also contains configuration and constants
      node - path of the node being tracked
      abortable - used to abort if a fatal error occurs
  • Method Details

    • start

      public void start()
      Starts the tracking of the node in ZooKeeper.

      Use blockUntilAvailable() to block until the node is available or getData(boolean) to get the data of the node if it is available.

    • postStart

      protected void postStart()
      Called after start is called. Sub classes could implement this method to load more data on zk.
    • stop

      public void stop()
    • blockUntilAvailable

      public byte[] blockUntilAvailable() throws InterruptedException
      Gets the data of the node, blocking until the node is available.
      Returns:
      data of the node
      Throws:
      InterruptedException - if the waiting thread is interrupted
    • blockUntilAvailable

      public byte[] blockUntilAvailable(long timeout, boolean refresh) throws InterruptedException
      Gets the data of the node, blocking until the node is available or the specified timeout has elapsed.
      Parameters:
      timeout - maximum time to wait for the node data to be available, n milliseconds. Pass 0 for no timeout.
      Returns:
      data of the node
      Throws:
      InterruptedException - if the waiting thread is interrupted
    • getData

      public byte[] getData(boolean refresh)
      Gets the data of the node.

      If the node is currently available, the most up-to-date known version of the data is returned. If the node is not currently available, null is returned.

      Parameters:
      refresh - whether to refresh the data by calling ZK directly.
      Returns:
      data of the node, null if unavailable
    • getNode

      public String getNode()
    • nodeCreated

      public void nodeCreated(String path)
      Description copied from class: ZKListener
      Called when a new node has been created.
      Overrides:
      nodeCreated in class ZKListener
      Parameters:
      path - full path of the new node
    • nodeDeleted

      public void nodeDeleted(String path)
      Description copied from class: ZKListener
      Called when a node has been deleted
      Overrides:
      nodeDeleted in class ZKListener
      Parameters:
      path - full path of the deleted node
    • nodeDataChanged

      public void nodeDataChanged(String path)
      Description copied from class: ZKListener
      Called when an existing node has changed data.
      Overrides:
      nodeDataChanged in class ZKListener
      Parameters:
      path - full path of the updated node
    • checkIfBaseNodeAvailable

      public boolean checkIfBaseNodeAvailable()
      Checks if the baseznode set as per the property 'zookeeper.znode.parent' exists.
      Returns:
      true if baseznode exists. false if doesnot exists.
    • toString

      public String toString()
      Overrides:
      toString in class Object