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

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

本文整理了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

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

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

/**
 * @return True if cluster has an active master.
 */
boolean hasActiveMaster() {
 try {
  if (ZKUtil.checkExists(watcher, watcher.getZNodePaths().masterAddressZNode) >= 0) {
   return true;
  }
 }
 catch (KeeperException ke) {
  LOG.info("Received an unexpected KeeperException when checking " +
    "isActiveMaster : "+ ke);
 }
 return false;
}

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

@Override
public boolean isReady() throws InterruptedException {
 int result = -1;
 try {
  result = ZKUtil.checkExists(watcher, watcher.getZNodePaths().splitLogZNode);
 } catch (KeeperException e) {
  // ignore
  LOG.warn("Exception when checking for " + watcher.getZNodePaths().splitLogZNode
    + " ... retrying", e);
 }
 if (result == -1) {
  LOG.info(watcher.getZNodePaths().splitLogZNode
    + " znode does not exist, waiting for master to create");
  Thread.sleep(1000);
 }
 return (result != -1);
}

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

@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);
 }
}

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

/**
 * Set data into node creating node if it doesn't yet exist.
 * Does not set watch.
 *
 * @param zkw zk reference
 * @param znode path of node
 * @param data data to set for node
 * @throws KeeperException if a ZooKeeper operation fails
 */
public static void createSetData(final ZKWatcher zkw, final String znode, final byte [] data)
    throws KeeperException {
 if (checkExists(zkw, znode) == -1) {
  ZKUtil.createWithParents(zkw, znode, data);
 } else {
  ZKUtil.setData(zkw, znode, data);
 }
}

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

@Override
public void addPeerToHFileRefs(String peerId) throws ReplicationException {
 String peerNode = getHFileRefsPeerNode(peerId);
 try {
  if (ZKUtil.checkExists(zookeeper, peerNode) == -1) {
   LOG.info("Adding peer {} to hfile reference queue.", peerId);
   ZKUtil.createWithParents(zookeeper, peerNode);
  }
 } catch (KeeperException e) {
  throw new ReplicationException("Failed to add peer " + peerId + " to hfile reference queue.",
    e);
 }
}

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

/**
 * Checks if the baseznode set as per the property 'zookeeper.znode.parent'
 * exists.
 * @return true if baseznode exists.
 *         false if doesnot exists.
 */
public boolean checkIfBaseNodeAvailable() {
 try {
  if (ZKUtil.checkExists(watcher, watcher.getZNodePaths().baseZNode) == -1) {
   return false;
  }
 } catch (KeeperException e) {
  abortable.abort("Exception while checking if basenode (" + watcher.getZNodePaths().baseZNode
    + ") exists in ZooKeeper.",
   e);
 }
 return true;
}

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

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

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

public static String readClusterIdZNode(ZKWatcher watcher)
 throws KeeperException {
 if (ZKUtil.checkExists(watcher, watcher.getZNodePaths().clusterIdZNode) != -1) {
  byte [] data;
  try {
   data = ZKUtil.getData(watcher, watcher.getZNodePaths().clusterIdZNode);
  } catch (InterruptedException e) {
   Thread.currentThread().interrupt();
   return null;
  }
  if (data != null) {
   try {
    return ClusterId.parseFrom(data).toString();
   } catch (DeserializationException e) {
    throw ZKUtil.convert(e);
   }
  }
 }
 return null;
}

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

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

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

public SplitOrMergeTracker(ZKWatcher watcher, Configuration conf,
              Abortable abortable) {
 try {
  if (ZKUtil.checkExists(watcher, watcher.getZNodePaths().switchZNode) < 0) {
   ZKUtil.createAndFailSilent(watcher, watcher.getZNodePaths().switchZNode);
  }
 } catch (KeeperException e) {
  throw new RuntimeException(e);
 }
 splitZnode = ZNodePaths.joinZNode(watcher.getZNodePaths().switchZNode,
  conf.get("zookeeper.znode.switch.split", "split"));
 mergeZnode = ZNodePaths.joinZNode(watcher.getZNodePaths().switchZNode,
  conf.get("zookeeper.znode.switch.merge", "merge"));
 splitStateTracker = new SwitchStateTracker(watcher, splitZnode, abortable);
 mergeStateTracker = new SwitchStateTracker(watcher, mergeZnode, abortable);
}

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

public void start() {
 try {
  watcher.registerListener(this);
  String parent = ZKUtil.getParent(leaderZNode);
  if (ZKUtil.checkExists(watcher, parent) < 0) {
   ZKUtil.createWithParents(watcher, parent);
  }
 } catch (KeeperException ke) {
  watcher.abort("Unhandled zk exception when starting", ke);
  candidate.stop("Unhandled zk exception starting up: "+ke.getMessage());
 }
}

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

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

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

@Test
public void testDeleteNodeRecursivelyMultiOrSequential() throws Exception {
 String parentZNode1 = "/testdeleteNode1";
 String parentZNode2 = "/testdeleteNode2";
 String parentZNode3 = "/testdeleteNode3";
 createZNodeTree(parentZNode1);
 createZNodeTree(parentZNode2);
 createZNodeTree(parentZNode3);
 ZKUtil.deleteNodeRecursivelyMultiOrSequential(zkw, false, parentZNode1, parentZNode2,
  parentZNode3);
 assertTrue("Parent znode 1 should be deleted.", ZKUtil.checkExists(zkw, parentZNode1) == -1);
 assertTrue("Parent znode 2 should be deleted.", ZKUtil.checkExists(zkw, parentZNode2) == -1);
 assertTrue("Parent znode 3 should be deleted.", ZKUtil.checkExists(zkw, parentZNode3) == -1);
}

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

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

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

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

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

@Before
public void setup() throws Exception {
 TEST_UTIL.startMiniZKCluster();
 Configuration conf = TEST_UTIL.getConfiguration();
 zkw = new ZKWatcher(TEST_UTIL.getConfiguration(),
   "split-log-worker-tests", null);
 ds = new DummyServer(zkw, conf);
 ZKUtil.deleteChildrenRecursively(zkw, zkw.getZNodePaths().baseZNode);
 ZKUtil.createAndFailSilent(zkw, zkw.getZNodePaths().baseZNode);
 assertThat(ZKUtil.checkExists(zkw, zkw.getZNodePaths().baseZNode), not(is(-1)));
 LOG.debug(zkw.getZNodePaths().baseZNode + " created");
 ZKUtil.createAndFailSilent(zkw, zkw.getZNodePaths().splitLogZNode);
 assertThat(ZKUtil.checkExists(zkw, zkw.getZNodePaths().splitLogZNode), not(is(-1)));
 LOG.debug(zkw.getZNodePaths().splitLogZNode + " created");
 ZKUtil.createAndFailSilent(zkw, zkw.getZNodePaths().rsZNode);
 assertThat(ZKUtil.checkExists(zkw, zkw.getZNodePaths().rsZNode), not(is(-1)));
 SplitLogCounters.resetCounters();
 executorService = new ExecutorService("TestSplitLogWorker");
 executorService.startExecutorService(ExecutorType.RS_LOG_REPLAY_OPS, 10);
}

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

@Test
public void testDeleteChildrenRecursivelyMultiOrSequential() throws Exception {
 String parentZNode1 = "/testdeleteChildren1";
 String parentZNode2 = "/testdeleteChildren2";
 String parentZNode3 = "/testdeleteChildren3";
 createZNodeTree(parentZNode1);
 createZNodeTree(parentZNode2);
 createZNodeTree(parentZNode3);
 ZKUtil.deleteChildrenRecursivelyMultiOrSequential(zkw, true, parentZNode1, parentZNode2,
  parentZNode3);
 assertTrue("Wrongly deleted parent znode 1!", ZKUtil.checkExists(zkw, parentZNode1) > -1);
 List<String> children = zkw.getRecoverableZooKeeper().getChildren(parentZNode1, false);
 assertTrue("Failed to delete child znodes of parent znode 1!", 0 == children.size());
 assertTrue("Wrongly deleted parent znode 2!", ZKUtil.checkExists(zkw, parentZNode2) > -1);
 children = zkw.getRecoverableZooKeeper().getChildren(parentZNode2, false);
 assertTrue("Failed to delete child znodes of parent znode 1!", 0 == children.size());
 assertTrue("Wrongly deleted parent znode 3!", ZKUtil.checkExists(zkw, parentZNode3) > -1);
 children = zkw.getRecoverableZooKeeper().getChildren(parentZNode3, false);
 assertTrue("Failed to delete child znodes of parent znode 1!", 0 == children.size());
}

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

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

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

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

相关文章

微信公众号

最新文章

更多