Class TableHFileArchiveTracker
java.lang.Object
org.apache.hadoop.hbase.zookeeper.ZKListener
org.apache.hadoop.hbase.backup.example.TableHFileArchiveTracker
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 Summary
Modifier and TypeFieldDescriptionprivate String
static final String
private static final org.slf4j.Logger
private HFileArchiveTableMonitor
private boolean
Fields inherited from class org.apache.hadoop.hbase.zookeeper.ZKListener
watcher
-
Constructor Summary
ModifierConstructorDescriptionprivate
TableHFileArchiveTracker
(ZKWatcher watcher, HFileArchiveTableMonitor monitor) -
Method Summary
Modifier and TypeMethodDescriptionprivate void
addAndReWatchTable
(String tableZnode) Add this table to the tracker and then read a watch on that node.private void
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).private void
Remove the currently archived tables.static TableHFileArchiveTracker
create
(org.apache.hadoop.conf.Configuration conf) Create an archive tracker for the passed in serverprivate static TableHFileArchiveTracker
create
(ZKWatcher zkw, HFileArchiveTableMonitor monitor) Create an archive tracker with the special passed in table monitor.final HFileArchiveTableMonitor
Returns the tracker for which tables should be archived.boolean
keepHFiles
(String tableName) Determine if the given table should or should not allow its hfiles to be deletedvoid
nodeChildrenChanged
(String path) Called when an existing node has a child node added or removed.void
nodeCreated
(String path) Called when a new node has been created.void
nodeDeleted
(String path) Called when a node has been deletedprivate void
safeStopTrackingTable
(String tableZnode) Stop tracking a table.void
start()
Start monitoring for archive updatesvoid
stop()
Stop this tracker and the passed zookeeperprivate void
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 archiveMethods inherited from class org.apache.hadoop.hbase.zookeeper.ZKListener
getWatcher, nodeDataChanged
-
Field Details
-
LOG
-
HFILE_ARCHIVE_ZNODE_PARENT
- See Also:
-
monitor
-
archiveHFileZNode
-
stopped
-
-
Constructor Details
-
TableHFileArchiveTracker
-
-
Method Details
-
start
Start monitoring for archive updates- Throws:
org.apache.zookeeper.KeeperException
- on failure to find/create nodes
-
nodeCreated
Description copied from class:ZKListener
Called when a new node has been created.- Overrides:
nodeCreated
in classZKListener
- Parameters:
path
- full path of the new node
-
nodeChildrenChanged
Description copied from class:ZKListener
Called when an existing node has a child node added or removed.- Overrides:
nodeChildrenChanged
in classZKListener
- Parameters:
path
- full path of the node whose children have changed
-
addAndReWatchTable
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
Stop tracking a table. Ensures that the table doesn't exist, but if it does, it attempts to add the table back viaaddAndReWatchTable(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
Description copied from class:ZKListener
Called when a node has been deleted- Overrides:
nodeDeleted
in classZKListener
- Parameters:
path
- full path of the deleted node
-
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
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
Remove the currently archived tables.Does some intelligent checking to make sure we don't prematurely create an archive tracker.
-
keepHFiles
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 occursZooKeeperConnectionException
- 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 trackmonitor
- 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
Stop this tracker and the passed zookeeper
-