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

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

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

ZKUtil.listChildrenNoWatch介绍

[英]Lists the children of the specified znode without setting any watches. Sets no watches at all, this method is best effort. Returns an empty list if the node has no children. Returns null if the parent node itself does not exist.
[中]列出指定znode的子节点,但不设置任何手表。完全不设置手表,这种方法是最好的。如果节点没有子节点,则返回空列表。如果父节点本身不存在,则返回null。

代码示例

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

private List<String> getAllPeersFromHFileRefsQueue0() throws KeeperException {
 List<String> children = ZKUtil.listChildrenNoWatch(zookeeper, hfileRefsZNode);
 return children != null ? children : Collections.emptyList();
}

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

private List<ServerName> getListOfReplicators0() throws KeeperException {
 List<String> children = ZKUtil.listChildrenNoWatch(zookeeper, queuesZNode);
 if (children == null) {
  children = Collections.emptyList();
 }
 return children.stream().map(ServerName::parseServerName).collect(toList());
}

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

@Override
public List<String> listPeerIds() throws ReplicationException {
 try {
  List<String> children = ZKUtil.listChildrenNoWatch(zookeeper, peersZNode);
  return children != null ? children : Collections.emptyList();
 } catch (KeeperException e) {
  throw new ReplicationException("Cannot get the list of peers", e);
 }
}

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

private List<String> getReplicableHFiles0(String peerId) throws KeeperException {
 List<String> children = ZKUtil.listChildrenNoWatch(this.zookeeper,
   getHFileRefsPeerNode(peerId));
 return children != null ? children : Collections.emptyList();
}

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

/**
 * Get the znodes corresponding to the meta replicas from ZK
 * @return list of znodes
 * @throws KeeperException if a ZooKeeper operation fails
 */
public List<String> getMetaReplicaNodes() throws KeeperException {
 List<String> childrenOfBaseNode = ZKUtil.listChildrenNoWatch(this, znodePaths.baseZNode);
 List<String> metaReplicaNodes = new ArrayList<>(2);
 if (childrenOfBaseNode != null) {
  String pattern = conf.get("zookeeper.znode.metaserver","meta-region-server");
  for (String child : childrenOfBaseNode) {
   if (child.startsWith(pattern)) {
    metaReplicaNodes.add(child);
   }
  }
 }
 return metaReplicaNodes;
}

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

private List<String> getWALsInQueue0(ServerName serverName, String queueId)
  throws KeeperException {
 List<String> children = ZKUtil.listChildrenNoWatch(zookeeper, getQueueNode(serverName,
   queueId));
 return children != null ? children : Collections.emptyList();
}

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

private List<String> getAllQueues0(ServerName serverName) throws KeeperException {
 List<String> children = ZKUtil.listChildrenNoWatch(zookeeper, getRsNode(serverName));
 return children != null ? children : Collections.emptyList();
}

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

private List<String> getRegionServersInZK(final ZKWatcher zkw)
throws KeeperException {
 return ZKUtil.listChildrenNoWatch(zkw, zkw.getZNodePaths().rsZNode);
}

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

private static void appendHFileRefsZnodes(ZKWatcher zkw, String hfileRefsZnode,
                     StringBuilder sb) throws KeeperException {
 sb.append("\n").append(hfileRefsZnode).append(": ");
 for (String peerIdZnode : ZKUtil.listChildrenNoWatch(zkw, hfileRefsZnode)) {
  String znodeToProcess = ZNodePaths.joinZNode(hfileRefsZnode, peerIdZnode);
  sb.append("\n").append(znodeToProcess).append(": ");
  List<String> peerHFileRefsZnodes = ZKUtil.listChildrenNoWatch(zkw, znodeToProcess);
  int size = peerHFileRefsZnodes.size();
  for (int i = 0; i < size; i++) {
   sb.append(peerHFileRefsZnodes.get(i));
   if (i != size - 1) {
    sb.append(", ");
   }
  }
 }
}

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

/**
 * This function calculates how many splitters this RS should create based on expected average
 * tasks per RS and the hard limit upper bound(maxConcurrentTasks) set by configuration. <br>
 * At any given time, a RS allows spawn MIN(Expected Tasks/RS, Hard Upper Bound)
 * @param numTasks total number of split tasks available
 * @return number of tasks this RS can grab
 */
private int getNumExpectedTasksPerRS(int numTasks) {
 // at lease one RS(itself) available
 int availableRSs = 1;
 try {
  List<String> regionServers =
    ZKUtil.listChildrenNoWatch(watcher, watcher.getZNodePaths().rsZNode);
  availableRSs = Math.max(availableRSs, (regionServers == null) ? 0 : regionServers.size());
 } catch (KeeperException e) {
  // do nothing
  LOG.debug("getAvailableRegionServers got ZooKeeper exception", e);
 }
 int expectedTasksPerRS = (numTasks / availableRSs) + ((numTasks % availableRSs == 0) ? 0 : 1);
 return Math.max(1, expectedTasksPerRS); // at least be one
}

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

/**
 * Helper method to print the current state of the ZK tree.
 * @see #logZKTree(String)
 * @throws KeeperException if an unexpected exception occurs
 */
protected void logZKTree(String root, String prefix) throws KeeperException {
 List<String> children = ZKUtil.listChildrenNoWatch(watcher, root);
 if (children == null) return;
 for (String child : children) {
  LOG.debug(prefix + child);
  String node = ZNodePaths.joinZNode(root.equals("/") ? "" : root, child);
  logZKTree(node, prefix + "---");
 }
}

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

@Override
public int remainingTasksInCoordination() {
 int count = 0;
 try {
  List<String> tasks = ZKUtil.listChildrenNoWatch(watcher,
      watcher.getZNodePaths().splitLogZNode);
  if (tasks != null) {
   int listSize = tasks.size();
   for (int i = 0; i < listSize; i++) {
    if (!ZKSplitLog.isRescanNode(tasks.get(i))) {
     count++;
    }
   }
  }
 } catch (KeeperException ke) {
  LOG.warn("Failed to check remaining tasks", ke);
  count = -1;
 }
 return count;
}

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

/**
 * Helper method to print the current state of the ZK tree.
 * @see #logZKTree(ZKWatcher, String)
 * @throws KeeperException if an unexpected exception occurs
 */
protected static void logZKTree(ZKWatcher zkw, String root, String prefix)
  throws KeeperException {
 List<String> children = ZKUtil.listChildrenNoWatch(zkw, root);
 if (children == null) {
  return;
 }
 for (String child : children) {
  LOG.debug(prefix + child);
  String node = ZNodePaths.joinZNode(root.equals("/") ? "" : root, child);
  logZKTree(zkw, node, prefix + "---");
 }
}

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

private List<ServerName> getOnlineRS() throws IOException {
 if (masterServices != null) {
  return masterServices.getServerManager().getOnlineServersList();
 }
 LOG.debug("Reading online RS from zookeeper");
 List<ServerName> servers = new LinkedList<>();
 try {
  for (String el : ZKUtil.listChildrenNoWatch(watcher, watcher.getZNodePaths().rsZNode)) {
   servers.add(ServerName.parseServerName(el));
  }
 } catch (KeeperException e) {
  throw new IOException("Failed to retrieve server list from zookeeper", e);
 }
 return servers;
}

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

private static void appendPeersZnodes(ZKWatcher zkw, String peersZnode,
                   StringBuilder sb) throws KeeperException {
 int pblen = ProtobufUtil.lengthOfPBMagic();
 sb.append("\n").append(peersZnode).append(": ");
 for (String peerIdZnode : ZKUtil.listChildrenNoWatch(zkw, peersZnode)) {
  String znodeToProcess = ZNodePaths.joinZNode(peersZnode, peerIdZnode);
  byte[] data;
  try {
   data = ZKUtil.getData(zkw, znodeToProcess);
  } catch (InterruptedException e) {
   zkw.interruptedException(e);
   return;
  }
  // parse the data of the above peer znode.
  try {
   ReplicationProtos.ReplicationPeer.Builder builder =
    ReplicationProtos.ReplicationPeer.newBuilder();
   ProtobufUtil.mergeFrom(builder, data, pblen, data.length - pblen);
   String clusterKey = builder.getClusterkey();
   sb.append("\n").append(znodeToProcess).append(": ").append(clusterKey);
   // add the peer-state.
   appendPeerState(zkw, znodeToProcess, sb);
  } catch (IOException ipbe) {
   LOG.warn("Got Exception while parsing peer: " + znodeToProcess, ipbe);
  }
 }
}

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

private static void appendPeerState(ZKWatcher zkw, String znodeToProcess, StringBuilder sb)
    throws KeeperException, InvalidProtocolBufferException {
 String peerState = zkw.getConfiguration().get("zookeeper.znode.replication.peers.state",
  "peer-state");
 int pblen = ProtobufUtil.lengthOfPBMagic();
 for (String child : ZKUtil.listChildrenNoWatch(zkw, znodeToProcess)) {
  if (!child.equals(peerState)) {
   continue;
  }
  String peerStateZnode = ZNodePaths.joinZNode(znodeToProcess, child);
  sb.append("\n").append(peerStateZnode).append(": ");
  byte[] peerStateData;
  try {
   peerStateData = ZKUtil.getData(zkw, peerStateZnode);
   ReplicationProtos.ReplicationState.Builder builder =
     ReplicationProtos.ReplicationState.newBuilder();
   ProtobufUtil.mergeFrom(builder, peerStateData, pblen, peerStateData.length - pblen);
   sb.append(builder.getState().name());
  } catch (IOException ipbe) {
   LOG.warn("Got Exception while parsing peer: " + znodeToProcess, ipbe);
  } catch (InterruptedException e) {
   zkw.interruptedException(e);
   return;
  }
 }
}

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

private static void resetAcls(final ZKWatcher zkw, final String znode,
               final boolean eraseAcls) throws Exception {
 List<String> children = ZKUtil.listChildrenNoWatch(zkw, znode);
 if (children != null) {
  for (String child: children) {
   resetAcls(zkw, ZNodePaths.joinZNode(znode, child), eraseAcls);
  }
 }
 ZooKeeper zk = zkw.getRecoverableZooKeeper().getZooKeeper();
 if (eraseAcls) {
  LOG.info(" - erase ACLs for " + znode);
  zk.setACL(znode, ZooDefs.Ids.OPEN_ACL_UNSAFE, -1);
 } else {
  LOG.info(" - set ACLs for " + znode);
  zk.setACL(znode, ZKUtil.createACL(zkw, znode, true), -1);
 }
}

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

/**
  * Get a list of all the other region servers in this cluster and set a watch
  * @return a list of server nanes
  */
 private List<String> getRegisteredRegionServers(boolean watch) {
  List<String> result = null;
  try {
   if (watch) {
    result = ZKUtil.listChildrenAndWatchThem(this.zookeeper,
        this.zookeeper.getZNodePaths().rsZNode);
   } else {
    result = ZKUtil.listChildrenNoWatch(this.zookeeper, this.zookeeper.getZNodePaths().rsZNode);
   }
  } catch (KeeperException e) {
   this.abortable.abort("Get list of registered region servers", e);
  }
  return result;
 }
}

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

@Test(expected = KeeperException.SystemErrorException.class)
 public void testInterruptedDuringAction()
   throws ZooKeeperConnectionException, IOException, KeeperException, InterruptedException {
  final RecoverableZooKeeper recoverableZk = Mockito.mock(RecoverableZooKeeper.class);
  ZKWatcher zkw = new ZKWatcher(HBaseConfiguration.create(), "unittest", null) {
   @Override
   public RecoverableZooKeeper getRecoverableZooKeeper() {
    return recoverableZk;
   }
  };
  Mockito.doThrow(new InterruptedException()).when(recoverableZk)
    .getChildren(zkw.getZNodePaths().baseZNode, null);
  ZKUtil.listChildrenNoWatch(zkw, zkw.getZNodePaths().baseZNode);
 }
}

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

@Test
 public void testRegionServerHostnameReportedToMaster() throws Exception {
  TEST_UTIL.getConfiguration().setBoolean(HRegionServer.RS_HOSTNAME_DISABLE_MASTER_REVERSEDNS_KEY,
  true);
  StartMiniClusterOption option = StartMiniClusterOption.builder()
    .numMasters(NUM_MASTERS).numRegionServers(NUM_RS).numDataNodes(NUM_RS).build();
  TEST_UTIL.startMiniCluster(option);
  boolean tablesOnMaster = LoadBalancer.isTablesOnMaster(TEST_UTIL.getConfiguration());
  int expectedRS = NUM_RS + (tablesOnMaster? 1: 0);
  try (ZKWatcher zkw = TEST_UTIL.getZooKeeperWatcher()) {
   List<String> servers = ZKUtil.listChildrenNoWatch(zkw, zkw.getZNodePaths().rsZNode);
   assertEquals(expectedRS, servers.size());
  }
 }
}

相关文章

微信公众号

最新文章

更多