下面列出了org.apache.hadoop.hbase.zookeeper.ZKUtil#deleteNodeRecursively ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Disable all archiving of files for a given table
* <p>
* Inherently an <b>asynchronous operation</b>.
* @param zooKeeper watcher for the ZK cluster
* @param table name of the table to disable
* @throws KeeperException if an unexpected ZK connection issues occurs
*/
private void disable(ZKWatcher zooKeeper, byte[] table) throws KeeperException {
// ensure the latest state of the archive node is found
zooKeeper.syncOrTimeout(archiveZnode);
// if the top-level archive node is gone, then we are done
if (ZKUtil.checkExists(zooKeeper, archiveZnode) < 0) {
return;
}
// delete the table node, from the archive
String tableNode = this.getTableNode(table);
// make sure the table is the latest version so the delete takes
zooKeeper.syncOrTimeout(tableNode);
LOG.debug("Attempting to delete table node:" + tableNode);
ZKUtil.deleteNodeRecursively(zooKeeper, tableNode);
}
@After
public void after() throws Exception {
try {
TEST_UTIL.getHBaseCluster().waitForActiveAndReadyMaster(10000);
// Some regionserver could fail to delete its znode.
// So shutdown could hang. Let's kill them all instead.
TEST_UTIL.getHBaseCluster().killAll();
// Still need to clean things up
TEST_UTIL.shutdownMiniHBaseCluster();
} finally {
TEST_UTIL.getTestFileSystem().delete(CommonFSUtils.getRootDir(TEST_UTIL.getConfiguration()),
true);
ZKUtil.deleteNodeRecursively(TEST_UTIL.getZooKeeperWatcher(), "/hbase");
}
}
@After
public void tearDown()
throws KeeperException, ZooKeeperConnectionException, IOException {
// Make sure zk is clean before we run the next test.
ZKWatcher zkw = new ZKWatcher(TESTUTIL.getConfiguration(),
"@Before", new Abortable() {
@Override
public void abort(String why, Throwable e) {
throw new RuntimeException(why, e);
}
@Override
public boolean isAborted() {
return false;
}
});
ZKUtil.deleteNodeRecursively(zkw, zkw.getZNodePaths().baseZNode);
zkw.close();
}
@Override
public void removeQueue(ServerName serverName, String queueId) throws ReplicationException {
try {
ZKUtil.deleteNodeRecursively(zookeeper, getQueueNode(serverName, queueId));
} catch (KeeperException e) {
throw new ReplicationException(
"Failed to delete queue (serverName=" + serverName + ", queueId=" + queueId + ")", e);
}
}
@Override
public void removePeerFromHFileRefs(String peerId) throws ReplicationException {
String peerNode = getHFileRefsPeerNode(peerId);
try {
if (ZKUtil.checkExists(zookeeper, peerNode) == -1) {
LOG.debug("Peer {} not found in hfile reference queue.", peerNode);
} else {
LOG.info("Removing peer {} from hfile reference queue.", peerNode);
ZKUtil.deleteNodeRecursively(zookeeper, peerNode);
}
} catch (KeeperException e) {
throw new ReplicationException(
"Failed to remove peer " + peerId + " from hfile reference queue.", e);
}
}
@Override
public void removePeer(String peerId) throws ReplicationException {
try {
ZKUtil.deleteNodeRecursively(zookeeper, getPeerNode(peerId));
} catch (KeeperException e) {
throw new ReplicationException("Could not remove peer with id=" + peerId, e);
}
}
/**
* Disable long-term archival of all hfiles for all tables in the cluster.
* @return <tt>this</tt> for chaining.
* @throws IOException if the number of attempts is exceeded
*/
public HFileArchiveManager disableHFileBackup() throws IOException {
LOG.debug("Disabling backups on all tables.");
try {
ZKUtil.deleteNodeRecursively(this.zooKeeper, archiveZnode);
return this;
} catch (KeeperException e) {
throw new IOException("Unexpected ZK exception!", e);
}
}
@After
public void after() throws Exception {
TEST_UTIL.shutdownMiniHBaseCluster();
TEST_UTIL.getTestFileSystem().delete(CommonFSUtils.getRootDir(TEST_UTIL.getConfiguration()),
true);
ZKUtil.deleteNodeRecursively(TEST_UTIL.getZooKeeperWatcher(), "/hbase");
}
@After
public void tearDown() throws KeeperException, IOException {
ZKUtil.deleteNodeRecursively(zkw, replicationZNode);
}