org.apache.hadoop.hbase.zookeeper.ZKUtil.checkExists()方法的使用及代码示例

x33g5p2x  于2022-02-05 转载在 其他  
字(12.0k)|赞(0)|评价(0)|浏览(158)

本文整理了Java中org.apache.hadoop.hbase.zookeeper.ZKUtil.checkExists()方法的一些代码示例,展示了ZKUtil.checkExists()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZKUtil.checkExists()方法的具体详情如下:
包路径:org.apache.hadoop.hbase.zookeeper.ZKUtil
类名称:ZKUtil
方法名:checkExists

ZKUtil.checkExists介绍

[英]Check if the specified node exists. Sets no watches.
[中]检查指定的节点是否存在。没有手表。

代码示例

代码示例来源:origin: apache/hbase

  1. /**
  2. * Check to see if the table is currently marked for archiving
  3. * @param table name of the table to check
  4. * @return <tt>true</tt> if the archive znode for that table exists, <tt>false</tt> if not
  5. * @throws KeeperException if an unexpected zookeeper error occurs
  6. */
  7. public boolean isArchivingEnabled(byte[] table) throws KeeperException {
  8. String tableNode = this.getTableNode(table);
  9. return ZKUtil.checkExists(zooKeeper, tableNode) >= 0;
  10. }

代码示例来源:origin: apache/hbase

  1. /**
  2. * @return True if cluster has an active master.
  3. */
  4. boolean hasActiveMaster() {
  5. try {
  6. if (ZKUtil.checkExists(watcher, watcher.getZNodePaths().masterAddressZNode) >= 0) {
  7. return true;
  8. }
  9. }
  10. catch (KeeperException ke) {
  11. LOG.info("Received an unexpected KeeperException when checking " +
  12. "isActiveMaster : "+ ke);
  13. }
  14. return false;
  15. }

代码示例来源:origin: apache/hbase

  1. @Override
  2. public boolean isReady() throws InterruptedException {
  3. int result = -1;
  4. try {
  5. result = ZKUtil.checkExists(watcher, watcher.getZNodePaths().splitLogZNode);
  6. } catch (KeeperException e) {
  7. // ignore
  8. LOG.warn("Exception when checking for " + watcher.getZNodePaths().splitLogZNode
  9. + " ... retrying", e);
  10. }
  11. if (result == -1) {
  12. LOG.info(watcher.getZNodePaths().splitLogZNode
  13. + " znode does not exist, waiting for master to create");
  14. Thread.sleep(1000);
  15. }
  16. return (result != -1);
  17. }

代码示例来源:origin: apache/hbase

  1. @Override
  2. public void removePeerFromHFileRefs(String peerId) throws ReplicationException {
  3. String peerNode = getHFileRefsPeerNode(peerId);
  4. try {
  5. if (ZKUtil.checkExists(zookeeper, peerNode) == -1) {
  6. LOG.debug("Peer {} not found in hfile reference queue.", peerNode);
  7. } else {
  8. LOG.info("Removing peer {} from hfile reference queue.", peerNode);
  9. ZKUtil.deleteNodeRecursively(zookeeper, peerNode);
  10. }
  11. } catch (KeeperException e) {
  12. throw new ReplicationException(
  13. "Failed to remove peer " + peerId + " from hfile reference queue.", e);
  14. }
  15. }

代码示例来源:origin: apache/hbase

  1. /**
  2. * Set data into node creating node if it doesn't yet exist.
  3. * Does not set watch.
  4. *
  5. * @param zkw zk reference
  6. * @param znode path of node
  7. * @param data data to set for node
  8. * @throws KeeperException if a ZooKeeper operation fails
  9. */
  10. public static void createSetData(final ZKWatcher zkw, final String znode, final byte [] data)
  11. throws KeeperException {
  12. if (checkExists(zkw, znode) == -1) {
  13. ZKUtil.createWithParents(zkw, znode, data);
  14. } else {
  15. ZKUtil.setData(zkw, znode, data);
  16. }
  17. }

代码示例来源:origin: apache/hbase

  1. @Override
  2. public void addPeerToHFileRefs(String peerId) throws ReplicationException {
  3. String peerNode = getHFileRefsPeerNode(peerId);
  4. try {
  5. if (ZKUtil.checkExists(zookeeper, peerNode) == -1) {
  6. LOG.info("Adding peer {} to hfile reference queue.", peerId);
  7. ZKUtil.createWithParents(zookeeper, peerNode);
  8. }
  9. } catch (KeeperException e) {
  10. throw new ReplicationException("Failed to add peer " + peerId + " to hfile reference queue.",
  11. e);
  12. }
  13. }

代码示例来源:origin: apache/hbase

  1. /**
  2. * Checks if the baseznode set as per the property 'zookeeper.znode.parent'
  3. * exists.
  4. * @return true if baseznode exists.
  5. * false if doesnot exists.
  6. */
  7. public boolean checkIfBaseNodeAvailable() {
  8. try {
  9. if (ZKUtil.checkExists(watcher, watcher.getZNodePaths().baseZNode) == -1) {
  10. return false;
  11. }
  12. } catch (KeeperException e) {
  13. abortable.abort("Exception while checking if basenode (" + watcher.getZNodePaths().baseZNode
  14. + ") exists in ZooKeeper.",
  15. e);
  16. }
  17. return true;
  18. }

代码示例来源:origin: apache/hbase

  1. /**
  2. * Stop tracking a table. Ensures that the table doesn't exist, but if it does, it attempts to add
  3. * the table back via {@link #addAndReWatchTable(String)} - its a 'safe' removal.
  4. * @param tableZnode full zookeeper path to the table to be added
  5. * @throws KeeperException if an unexpected zk exception occurs
  6. */
  7. private void safeStopTrackingTable(String tableZnode) throws KeeperException {
  8. getMonitor().removeTable(ZKUtil.getNodeName(tableZnode));
  9. // if the table exists, then add and rewatch it
  10. if (ZKUtil.checkExists(watcher, tableZnode) >= 0) {
  11. addAndReWatchTable(tableZnode);
  12. }
  13. }

代码示例来源:origin: apache/hbase

  1. public static String readClusterIdZNode(ZKWatcher watcher)
  2. throws KeeperException {
  3. if (ZKUtil.checkExists(watcher, watcher.getZNodePaths().clusterIdZNode) != -1) {
  4. byte [] data;
  5. try {
  6. data = ZKUtil.getData(watcher, watcher.getZNodePaths().clusterIdZNode);
  7. } catch (InterruptedException e) {
  8. Thread.currentThread().interrupt();
  9. return null;
  10. }
  11. if (data != null) {
  12. try {
  13. return ClusterId.parseFrom(data).toString();
  14. } catch (DeserializationException e) {
  15. throw ZKUtil.convert(e);
  16. }
  17. }
  18. }
  19. return null;
  20. }

代码示例来源:origin: apache/hbase

  1. /**
  2. * Verify that the prepare, commit and abort nodes for the operation are removed from zookeeper
  3. */
  4. private void verifyZooKeeperClean(String operationName, ZKWatcher watcher,
  5. ZKProcedureUtil controller) throws Exception {
  6. String prepare = ZKProcedureUtil.getAcquireBarrierNode(controller, operationName);
  7. String commit = ZKProcedureUtil.getReachedBarrierNode(controller, operationName);
  8. String abort = ZKProcedureUtil.getAbortNode(controller, operationName);
  9. assertEquals("Didn't delete prepare node", -1, ZKUtil.checkExists(watcher, prepare));
  10. assertEquals("Didn't delete commit node", -1, ZKUtil.checkExists(watcher, commit));
  11. assertEquals("Didn't delete abort node", -1, ZKUtil.checkExists(watcher, abort));
  12. }

代码示例来源:origin: apache/hbase

  1. public SplitOrMergeTracker(ZKWatcher watcher, Configuration conf,
  2. Abortable abortable) {
  3. try {
  4. if (ZKUtil.checkExists(watcher, watcher.getZNodePaths().switchZNode) < 0) {
  5. ZKUtil.createAndFailSilent(watcher, watcher.getZNodePaths().switchZNode);
  6. }
  7. } catch (KeeperException e) {
  8. throw new RuntimeException(e);
  9. }
  10. splitZnode = ZNodePaths.joinZNode(watcher.getZNodePaths().switchZNode,
  11. conf.get("zookeeper.znode.switch.split", "split"));
  12. mergeZnode = ZNodePaths.joinZNode(watcher.getZNodePaths().switchZNode,
  13. conf.get("zookeeper.znode.switch.merge", "merge"));
  14. splitStateTracker = new SwitchStateTracker(watcher, splitZnode, abortable);
  15. mergeStateTracker = new SwitchStateTracker(watcher, mergeZnode, abortable);
  16. }

代码示例来源:origin: apache/hbase

  1. public void start() {
  2. try {
  3. watcher.registerListener(this);
  4. String parent = ZKUtil.getParent(leaderZNode);
  5. if (ZKUtil.checkExists(watcher, parent) < 0) {
  6. ZKUtil.createWithParents(watcher, parent);
  7. }
  8. } catch (KeeperException ke) {
  9. watcher.abort("Unhandled zk exception when starting", ke);
  10. candidate.stop("Unhandled zk exception starting up: "+ke.getMessage());
  11. }
  12. }

代码示例来源:origin: apache/hbase

  1. private static void waitUntilZnodeAvailable(int replicaId) throws Exception {
  2. String znode = util.getZooKeeperWatcher().getZNodePaths().getZNodeForReplica(replicaId);
  3. int i = 0;
  4. while (i < 1000) {
  5. if (ZKUtil.checkExists(util.getZooKeeperWatcher(), znode) == -1) {
  6. Thread.sleep(100);
  7. i++;
  8. } else break;
  9. }
  10. if (i == 1000) throw new IOException("znode for meta replica " + replicaId + " not available");
  11. }

代码示例来源:origin: apache/hbase

  1. @Test
  2. public void testDeleteNodeRecursivelyMultiOrSequential() throws Exception {
  3. String parentZNode1 = "/testdeleteNode1";
  4. String parentZNode2 = "/testdeleteNode2";
  5. String parentZNode3 = "/testdeleteNode3";
  6. createZNodeTree(parentZNode1);
  7. createZNodeTree(parentZNode2);
  8. createZNodeTree(parentZNode3);
  9. ZKUtil.deleteNodeRecursivelyMultiOrSequential(zkw, false, parentZNode1, parentZNode2,
  10. parentZNode3);
  11. assertTrue("Parent znode 1 should be deleted.", ZKUtil.checkExists(zkw, parentZNode1) == -1);
  12. assertTrue("Parent znode 2 should be deleted.", ZKUtil.checkExists(zkw, parentZNode2) == -1);
  13. assertTrue("Parent znode 3 should be deleted.", ZKUtil.checkExists(zkw, parentZNode3) == -1);
  14. }

代码示例来源:origin: apache/hbase

  1. /**
  2. * Verifies that for the given root node, it should delete all the nodes recursively using
  3. * multi-update api.
  4. */
  5. @Test
  6. public void testDeleteNodeRecursivelyMulti() throws Exception {
  7. String parentZNode = "/testdeleteNodeRecursivelyMulti";
  8. createZNodeTree(parentZNode);
  9. ZKUtil.deleteNodeRecursively(zkw, parentZNode);
  10. assertTrue("Parent znode should be deleted.", ZKUtil.checkExists(zkw, parentZNode) == -1);
  11. }

代码示例来源:origin: apache/hbase

  1. @Test
  2. public void testTaskErr() throws Exception {
  3. LOG.info("TestTaskErr - cleanup task node once in ERR state");
  4. conf.setInt("hbase.splitlog.max.resubmit", 0);
  5. slm = new SplitLogManager(master, conf);
  6. TaskBatch batch = new TaskBatch();
  7. String tasknode = submitTaskAndWait(batch, "foo/1");
  8. final ServerName worker1 = ServerName.valueOf("worker1,1,1");
  9. SplitLogTask slt = new SplitLogTask.Err(worker1);
  10. ZKUtil.setData(zkw, tasknode, slt.toByteArray());
  11. synchronized (batch) {
  12. while (batch.installed != batch.error) {
  13. batch.wait();
  14. }
  15. }
  16. waitForCounter(tot_mgr_task_deleted, 0, 1, to/2);
  17. assertTrue(ZKUtil.checkExists(zkw, tasknode) == -1);
  18. conf.setInt("hbase.splitlog.max.resubmit", ZKSplitLogManagerCoordination.DEFAULT_MAX_RESUBMIT);
  19. }

代码示例来源:origin: apache/hbase

  1. @Before
  2. public void setup() throws Exception {
  3. TEST_UTIL.startMiniZKCluster();
  4. Configuration conf = TEST_UTIL.getConfiguration();
  5. zkw = new ZKWatcher(TEST_UTIL.getConfiguration(),
  6. "split-log-worker-tests", null);
  7. ds = new DummyServer(zkw, conf);
  8. ZKUtil.deleteChildrenRecursively(zkw, zkw.getZNodePaths().baseZNode);
  9. ZKUtil.createAndFailSilent(zkw, zkw.getZNodePaths().baseZNode);
  10. assertThat(ZKUtil.checkExists(zkw, zkw.getZNodePaths().baseZNode), not(is(-1)));
  11. LOG.debug(zkw.getZNodePaths().baseZNode + " created");
  12. ZKUtil.createAndFailSilent(zkw, zkw.getZNodePaths().splitLogZNode);
  13. assertThat(ZKUtil.checkExists(zkw, zkw.getZNodePaths().splitLogZNode), not(is(-1)));
  14. LOG.debug(zkw.getZNodePaths().splitLogZNode + " created");
  15. ZKUtil.createAndFailSilent(zkw, zkw.getZNodePaths().rsZNode);
  16. assertThat(ZKUtil.checkExists(zkw, zkw.getZNodePaths().rsZNode), not(is(-1)));
  17. SplitLogCounters.resetCounters();
  18. executorService = new ExecutorService("TestSplitLogWorker");
  19. executorService.startExecutorService(ExecutorType.RS_LOG_REPLAY_OPS, 10);
  20. }

代码示例来源:origin: apache/hbase

  1. @Test
  2. public void testDeleteChildrenRecursivelyMultiOrSequential() throws Exception {
  3. String parentZNode1 = "/testdeleteChildren1";
  4. String parentZNode2 = "/testdeleteChildren2";
  5. String parentZNode3 = "/testdeleteChildren3";
  6. createZNodeTree(parentZNode1);
  7. createZNodeTree(parentZNode2);
  8. createZNodeTree(parentZNode3);
  9. ZKUtil.deleteChildrenRecursivelyMultiOrSequential(zkw, true, parentZNode1, parentZNode2,
  10. parentZNode3);
  11. assertTrue("Wrongly deleted parent znode 1!", ZKUtil.checkExists(zkw, parentZNode1) > -1);
  12. List<String> children = zkw.getRecoverableZooKeeper().getChildren(parentZNode1, false);
  13. assertTrue("Failed to delete child znodes of parent znode 1!", 0 == children.size());
  14. assertTrue("Wrongly deleted parent znode 2!", ZKUtil.checkExists(zkw, parentZNode2) > -1);
  15. children = zkw.getRecoverableZooKeeper().getChildren(parentZNode2, false);
  16. assertTrue("Failed to delete child znodes of parent znode 1!", 0 == children.size());
  17. assertTrue("Wrongly deleted parent znode 3!", ZKUtil.checkExists(zkw, parentZNode3) > -1);
  18. children = zkw.getRecoverableZooKeeper().getChildren(parentZNode3, false);
  19. assertTrue("Failed to delete child znodes of parent znode 1!", 0 == children.size());
  20. }

代码示例来源:origin: apache/hbase

  1. /**
  2. * Verifies that for the given root node, it should delete all the child nodes
  3. * recursively using multi-update api.
  4. */
  5. @Test
  6. public void testdeleteChildrenRecursivelyMulti() throws Exception {
  7. String parentZNode = "/testRootMulti";
  8. createZNodeTree(parentZNode);
  9. ZKUtil.deleteChildrenRecursivelyMultiOrSequential(zkw, true, parentZNode);
  10. assertTrue("Wrongly deleted parent znode!",
  11. ZKUtil.checkExists(zkw, parentZNode) > -1);
  12. List<String> children = zkw.getRecoverableZooKeeper().getChildren(
  13. parentZNode, false);
  14. assertTrue("Failed to delete child znodes!", 0 == children.size());
  15. }

代码示例来源:origin: apache/hbase

  1. @Test
  2. public void testTaskDone() throws Exception {
  3. LOG.info("TestTaskDone - cleanup task node once in DONE state");
  4. slm = new SplitLogManager(master, conf);
  5. TaskBatch batch = new TaskBatch();
  6. String tasknode = submitTaskAndWait(batch, "foo/1");
  7. final ServerName worker1 = ServerName.valueOf("worker1,1,1");
  8. SplitLogTask slt = new SplitLogTask.Done(worker1);
  9. ZKUtil.setData(zkw, tasknode, slt.toByteArray());
  10. synchronized (batch) {
  11. while (batch.installed != batch.done) {
  12. batch.wait();
  13. }
  14. }
  15. waitForCounter(tot_mgr_task_deleted, 0, 1, to/2);
  16. assertTrue(ZKUtil.checkExists(zkw, tasknode) == -1);
  17. }

相关文章