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

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

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

ZKUtil.listChildrenAndWatchForNewChildren介绍

[英]Lists the children znodes of the specified znode. Also sets a watch on the specified znode which will capture a NodeDeleted event on the specified znode as well as NodeChildrenChanged if any children of the specified znode are created or deleted. Returns null if the specified node does not exist. Otherwise returns a list of children of the specified node. If the node exists but it has no children, an empty list will be returned.
[中]列出指定znode的子znode。还将在指定的znode上设置一个监视,该监视将捕获指定znode上的NodeDeleted事件,以及如果创建或删除指定znode的任何子节点,NodeChildrenChanged。如果指定的节点不存在,则返回null。否则返回指定节点的子节点列表。如果节点存在但没有子节点,则返回空列表。

代码示例

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

private void update() {
 try {
  List<String> children =
    ZKUtil.listChildrenAndWatchForNewChildren(watcher,
        watcher.getZNodePaths().masterMaintZNode);
  hasChildren = (children != null && children.size() > 0);
 } catch (KeeperException e) {
  // Ignore the ZK keeper exception
  hasChildren = false;
 }
}

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

/**
 * Get the list of all the region servers from the specified peer
 * @param zkw zk connection to use
 * @return list of region server addresses or an empty list if the slave is unavailable
 */
protected static List<ServerName> fetchSlavesAddresses(ZKWatcher zkw)
  throws KeeperException {
 List<String> children = ZKUtil.listChildrenAndWatchForNewChildren(zkw,
     zkw.getZNodePaths().rsZNode);
 if (children == null) {
  return Collections.emptyList();
 }
 List<ServerName> addresses = new ArrayList<>(children.size());
 for (String child : children) {
  addresses.add(ServerName.parseServerName(child));
 }
 return addresses;
}

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

private List<String> getTaskList() throws InterruptedException {
 List<String> childrenPaths = null;
 long sleepTime = 1000;
 // It will be in loop till it gets the list of children or
 // it will come out if worker thread exited.
 while (!shouldStop) {
  try {
   childrenPaths = ZKUtil.listChildrenAndWatchForNewChildren(watcher,
    watcher.getZNodePaths().splitLogZNode);
   if (childrenPaths != null) {
    return childrenPaths;
   }
  } catch (KeeperException e) {
   LOG.warn("Could not get children of znode " + watcher.getZNodePaths().splitLogZNode, e);
  }
  LOG.debug("Retry listChildren of znode " + watcher.getZNodePaths().splitLogZNode
    + " after sleep for " + sleepTime + "ms!");
  Thread.sleep(sleepTime);
 }
 return childrenPaths;
}

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

/**
 * List all the children of the specified znode, setting a watch for children
 * changes and also setting a watch on every individual child in order to get
 * the NodeCreated and NodeDeleted events.
 * @param zkw zookeeper reference
 * @param znode node to get children of and watch
 * @return list of znode names, null if the node doesn't exist
 * @throws KeeperException if a ZooKeeper operation fails
 */
public static List<String> listChildrenAndWatchThem(ZKWatcher zkw,
  String znode) throws KeeperException {
 List<String> children = listChildrenAndWatchForNewChildren(zkw, znode);
 if (children == null) {
  return null;
 }
 for (String child : children) {
  watchAndCheckExists(zkw, ZNodePaths.joinZNode(znode, child));
 }
 return children;
}

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

private synchronized void refresh() {
 List<String> names;
 try {
  names = ZKUtil.listChildrenAndWatchForNewChildren(watcher, watcher.getZNodePaths().rsZNode);
 } catch (KeeperException e) {

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

ZKWatcher zkw, String baseNode) throws KeeperException {
List<String> nodes =
 ZKUtil.listChildrenAndWatchForNewChildren(zkw, baseNode);
if (nodes != null) {
 List<NodeAndData> newNodes = new ArrayList<>();

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

private void waitForNewProcedures() {
 // watch for new procedues that we need to start subprocedures for
 LOG.debug("Looking for new procedures under znode:'" + zkController.getAcquiredBarrier() + "'");
 List<String> runningProcedures = null;
 try {
  runningProcedures = ZKUtil.listChildrenAndWatchForNewChildren(zkController.getWatcher(),
   zkController.getAcquiredBarrier());
  if (runningProcedures == null) {
   LOG.debug("No running procedures.");
   return;
  }
 } catch (KeeperException e) {
  member.controllerConnectionFailure("General failure when watching for new procedures",
   e, null);
 }
 if (runningProcedures == null) {
  LOG.debug("No running procedures.");
  return;
 }
 for (String procName : runningProcedures) {
  // then read in the procedure information
  String path = ZNodePaths.joinZNode(zkController.getAcquiredBarrier(), procName);
  startNewSubprocedure(path);
 }
}

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

List<RSGroupInfo> retrieveGroupListFromZookeeper() throws IOException {
 String groupBasePath = ZNodePaths.joinZNode(watcher.getZNodePaths().baseZNode, rsGroupZNode);
 List<RSGroupInfo> RSGroupInfoList = Lists.newArrayList();
 // Overwrite any info stored by table, this takes precedence
 try {
  if (ZKUtil.checkExists(watcher, groupBasePath) != -1) {
   List<String> children = ZKUtil.listChildrenAndWatchForNewChildren(watcher, groupBasePath);
   if (children == null) {
    return RSGroupInfoList;
   }
   for (String znode : children) {
    byte[] data = ZKUtil.getData(watcher, ZNodePaths.joinZNode(groupBasePath, znode));
    if (data.length > 0) {
     ProtobufUtil.expectPBMagicPrefix(data);
     ByteArrayInputStream bis =
      new ByteArrayInputStream(data, ProtobufUtil.lengthOfPBMagic(), data.length);
     RSGroupInfoList
      .add(RSGroupProtobufUtil.toGroupInfo(RSGroupProtos.RSGroupInfo.parseFrom(bis)));
    }
   }
   LOG.debug("Read ZK GroupInfo count:" + RSGroupInfoList.size());
  }
 } catch (KeeperException | DeserializationException | InterruptedException e) {
  throw new IOException("Failed to read rsGroupZNode", e);
 }
 return RSGroupInfoList;
}

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

synchronized (this) {
 List<String> servers =
  ZKUtil.listChildrenAndWatchForNewChildren(watcher, watcher.getZNodePaths().rsZNode);
 for (String n : servers) {
  Pair<ServerName, RegionServerInfo> pair = getServerInfo(n);

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

private void watchForAbortedProcedures() {
 LOG.debug("Checking for aborted procedures on node: '" + zkController.getAbortZnode() + "'");
 try {
  // this is the list of the currently aborted procedues
  List<String> children = ZKUtil.listChildrenAndWatchForNewChildren(zkController.getWatcher(),
         zkController.getAbortZnode());
  if (children == null || children.isEmpty()) {
   return;
  }
  for (String node : children) {
   String abortNode = ZNodePaths.joinZNode(zkController.getAbortZnode(), node);
   abort(abortNode);
  }
 } catch (KeeperException e) {
  member.controllerConnectionFailure("Failed to list children for abort node:"
    + zkController.getAbortZnode(), e, null);
 }
}

代码示例来源:origin: org.apache.hbase/hbase-zookeeper

private void update() {
 try {
  List<String> children =
    ZKUtil.listChildrenAndWatchForNewChildren(watcher,
        watcher.getZNodePaths().masterMaintZNode);
  hasChildren = (children != null && children.size() > 0);
 } catch (KeeperException e) {
  // Ignore the ZK keeper exception
  hasChildren = false;
 }
}

代码示例来源:origin: co.cask.hbase/hbase

/**
 * Reset all unassigned znodes.  Called on startup of master.
 * Call {@link #assignAllUserRegions()} after root and meta have been assigned.
 * @throws IOException
 * @throws KeeperException
 */
void cleanoutUnassigned() throws IOException, KeeperException {
 // Cleanup any existing ZK nodes and start watching
 ZKAssign.deleteAllNodes(watcher);
 ZKUtil.listChildrenAndWatchForNewChildren(this.watcher,
  this.watcher.assignmentZNode);
}

代码示例来源:origin: harbby/presto-connectors

/**
 * Get the list of all the region servers from the specified peer
 * @param zkw zk connection to use
 * @return list of region server addresses or an empty list if the slave is unavailable
 */
protected static List<ServerName> fetchSlavesAddresses(ZooKeeperWatcher zkw)
  throws KeeperException {
 List<String> children = ZKUtil.listChildrenAndWatchForNewChildren(zkw, zkw.rsZNode);
 if (children == null) {
  return Collections.emptyList();
 }
 List<ServerName> addresses = new ArrayList<ServerName>(children.size());
 for (String child : children) {
  addresses.add(ServerName.parseServerName(child));
 }
 return addresses;
}

代码示例来源:origin: co.cask.hbase/hbase

/**
 * Blocks until there is at least one node in regions in transition.
 * <p>
 * Used in testing only.
 * @param zkw zk reference
 * @throws KeeperException
 * @throws InterruptedException
 */
public static void blockUntilRIT(ZooKeeperWatcher zkw)
throws KeeperException, InterruptedException {
 while (!ZKUtil.nodeHasChildren(zkw, zkw.assignmentZNode)) {
  List<String> znodes =
   ZKUtil.listChildrenAndWatchForNewChildren(zkw, zkw.assignmentZNode);
  if (znodes == null || znodes.isEmpty()) {
   LOG.debug("No RIT in ZK");
  }
  Thread.sleep(100);
 }
}

代码示例来源:origin: harbby/presto-connectors

/**
 * Blocks until there are no node in regions in transition.
 * <p>
 * Used in testing only.
 * @param zkw zk reference
 * @throws KeeperException
 * @throws InterruptedException
 */
public static void blockUntilNoRIT(ZooKeeperWatcher zkw)
throws KeeperException, InterruptedException {
 while (ZKUtil.nodeHasChildren(zkw, zkw.assignmentZNode)) {
  List<String> znodes =
   ZKUtil.listChildrenAndWatchForNewChildren(zkw, zkw.assignmentZNode);
  if (znodes != null && !znodes.isEmpty()) {
   LOG.debug("Waiting on RIT: " + znodes);
  }
  Thread.sleep(100);
 }
}

代码示例来源:origin: harbby/presto-connectors

/**
 * Blocks until there is at least one node in regions in transition.
 * <p>
 * Used in testing only.
 * @param zkw zk reference
 * @throws KeeperException
 * @throws InterruptedException
 */
public static void blockUntilRIT(ZooKeeperWatcher zkw)
throws KeeperException, InterruptedException {
 while (!ZKUtil.nodeHasChildren(zkw, zkw.assignmentZNode)) {
  List<String> znodes =
   ZKUtil.listChildrenAndWatchForNewChildren(zkw, zkw.assignmentZNode);
  if (znodes == null || znodes.isEmpty()) {
   LOG.debug("No RIT in ZK");
  }
  Thread.sleep(100);
 }
}

代码示例来源:origin: co.cask.hbase/hbase

/**
 * List all the children of the specified znode, setting a watch for children
 * changes and also setting a watch on every individual child in order to get
 * the NodeCreated and NodeDeleted events.
 * @param zkw zookeeper reference
 * @param znode node to get children of and watch
 * @return list of znode names, null if the node doesn't exist
 * @throws KeeperException
 */
public static List<String> listChildrenAndWatchThem(ZooKeeperWatcher zkw,
  String znode) throws KeeperException {
 List<String> children = listChildrenAndWatchForNewChildren(zkw, znode);
 if (children == null) {
  return null;
 }
 for (String child : children) {
  watchAndCheckExists(zkw, joinZNode(znode, child));
 }
 return children;
}

代码示例来源:origin: harbby/presto-connectors

/**
 * List all the children of the specified znode, setting a watch for children
 * changes and also setting a watch on every individual child in order to get
 * the NodeCreated and NodeDeleted events.
 * @param zkw zookeeper reference
 * @param znode node to get children of and watch
 * @return list of znode names, null if the node doesn't exist
 * @throws KeeperException
 */
public static List<String> listChildrenAndWatchThem(ZooKeeperWatcher zkw,
  String znode) throws KeeperException {
 List<String> children = listChildrenAndWatchForNewChildren(zkw, znode);
 if (children == null) {
  return null;
 }
 for (String child : children) {
  watchAndCheckExists(zkw, joinZNode(znode, child));
 }
 return children;
}

代码示例来源:origin: co.cask.hbase/hbase

private void watchForAbortedProcedures() {
 LOG.debug("Checking for aborted procedures on node: '" + zkController.getAbortZnode() + "'");
 try {
  // this is the list of the currently aborted procedues
  for (String node : ZKUtil.listChildrenAndWatchForNewChildren(zkController.getWatcher(),
   zkController.getAbortZnode())) {
   String abortNode = ZKUtil.joinZNode(zkController.getAbortZnode(), node);
   abort(abortNode);
  }
 } catch (KeeperException e) {
  member.controllerConnectionFailure("Failed to list children for abort node:"
    + zkController.getAbortZnode(), new IOException(e));
 }
}

代码示例来源:origin: harbby/presto-connectors

private void watchForAbortedProcedures() {
 LOG.debug("Checking for aborted procedures on node: '" + zkController.getAbortZnode() + "'");
 try {
  // this is the list of the currently aborted procedues
  for (String node : ZKUtil.listChildrenAndWatchForNewChildren(zkController.getWatcher(),
   zkController.getAbortZnode())) {
   String abortNode = ZKUtil.joinZNode(zkController.getAbortZnode(), node);
   abort(abortNode);
  }
 } catch (KeeperException e) {
  member.controllerConnectionFailure("Failed to list children for abort node:"
    + zkController.getAbortZnode(), e, null);
 }
}

相关文章

微信公众号

最新文章

更多