Class TableHFileArchiveTracker

java.lang.Object
org.apache.hadoop.hbase.zookeeper.ZKListener
org.apache.hadoop.hbase.backup.example.TableHFileArchiveTracker

@Private public final class TableHFileArchiveTracker extends ZKListener
Track HFile archiving state changes in ZooKeeper. Keeps track of the tables whose HFiles should be kept in the archive.

start() needs to be called to start monitoring for tables to archive.

  • Field Details

  • Constructor Details

  • Method Details

    • start

      public void start() throws org.apache.zookeeper.KeeperException
      Start monitoring for archive updates
      Throws:
      org.apache.zookeeper.KeeperException - on failure to find/create nodes
    • 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
    • nodeChildrenChanged

      public void nodeChildrenChanged(String path)
      Description copied from class: ZKListener
      Called when an existing node has a child node added or removed.
      Overrides:
      nodeChildrenChanged in class ZKListener
      Parameters:
      path - full path of the node whose children have changed
    • addAndReWatchTable

      private void addAndReWatchTable(String tableZnode) throws org.apache.zookeeper.KeeperException
      Add this table to the tracker and then read a watch on that node.

      Handles situation where table is deleted in the time between the update and resetting the watch by deleting the table via safeStopTrackingTable(String)

      Parameters:
      tableZnode - full zookeeper path to the table to be added
      Throws:
      org.apache.zookeeper.KeeperException - if an unexpected zk exception occurs
    • safeStopTrackingTable

      private void safeStopTrackingTable(String tableZnode) throws org.apache.zookeeper.KeeperException
      Stop tracking a table. Ensures that the table doesn't exist, but if it does, it attempts to add the table back via addAndReWatchTable(String) - its a 'safe' removal.
      Parameters:
      tableZnode - full zookeeper path to the table to be added
      Throws:
      org.apache.zookeeper.KeeperException - if an unexpected zk exception occurs
    • 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
    • checkEnabledAndUpdate

      private void checkEnabledAndUpdate()
      Sets the watch on the top-level archive znode, and then updates the monitor with the current tables that should be archived (and ensures that those nodes are watched as well).
    • updateWatchedTables

      private void updateWatchedTables() throws org.apache.zookeeper.KeeperException
      Read the list of children under the archive znode as table names and then sets those tables to the list of tables that we should archive
      Throws:
      org.apache.zookeeper.KeeperException - if there is an unexpected zk exception
    • clearTables

      private void clearTables()
      Remove the currently archived tables.

      Does some intelligent checking to make sure we don't prematurely create an archive tracker.

    • keepHFiles

      public boolean keepHFiles(String tableName)
      Determine if the given table should or should not allow its hfiles to be deleted
      Parameters:
      tableName - name of the table to check
      Returns:
      true if its store files should be retained, false otherwise
    • getMonitor

      Returns the tracker for which tables should be archived.
    • create

      public static TableHFileArchiveTracker create(org.apache.hadoop.conf.Configuration conf) throws ZooKeeperConnectionException, IOException
      Create an archive tracker for the passed in server
      Parameters:
      conf - to read for zookeeper connection information
      Returns:
      ZooKeeper tracker to monitor for this server if this server should archive hfiles for a given table
      Throws:
      IOException - If a unexpected exception occurs
      ZooKeeperConnectionException - if we can't reach zookeeper
    • create

      Create an archive tracker with the special passed in table monitor. Should only be used in special cases (e.g. testing)
      Parameters:
      zkw - Watcher for the ZooKeeper cluster that we should track
      monitor - Monitor for which tables need hfile archiving
      Returns:
      ZooKeeper tracker to monitor for this server if this server should archive hfiles for a given table
    • getZooKeeperWatcher

    • stop

      public void stop()
      Stop this tracker and the passed zookeeper