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

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

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

ZKUtil.getDataNoWatch介绍

[英]Get the data at the specified znode without setting a watch. Returns the data if the node exists. Returns null if the node does not exist. Sets the stats of the node in the passed Stat object. Pass a null stat if not interested.
[中]在不设置手表的情况下,在指定的znode获取数据。如果节点存在,则返回数据。如果节点不存在,则返回null。在传递的Stat对象中设置节点的stats。如果不感兴趣,则传递空状态。

代码示例

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

  1. @VisibleForTesting
  2. protected int getQueuesZNodeCversion() throws KeeperException {
  3. Stat stat = new Stat();
  4. ZKUtil.getDataNoWatch(this.zookeeper, this.queuesZNode, stat);
  5. return stat.getCversion();
  6. }

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

  1. @VisibleForTesting
  2. protected int getHFileRefsZNodeCversion() throws ReplicationException {
  3. Stat stat = new Stat();
  4. try {
  5. ZKUtil.getDataNoWatch(zookeeper, hfileRefsZNode, stat);
  6. } catch (KeeperException e) {
  7. throw new ReplicationException("Failed to get stat of replication hfile references node.", e);
  8. }
  9. return stat.getCversion();
  10. }

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

  1. private int getZNodeDataVersion(String znode) throws KeeperException {
  2. Stat stat = new Stat();
  3. ZKUtil.getDataNoWatch(ZKW, znode, stat);
  4. return stat.getVersion();
  5. }

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

  1. /**
  2. * delete the master znode if its content is same as the parameter
  3. * @param zkw must not be null
  4. * @param content must not be null
  5. */
  6. public static boolean deleteIfEquals(ZKWatcher zkw, final String content) {
  7. if (content == null){
  8. throw new IllegalArgumentException("Content must not be null");
  9. }
  10. try {
  11. Stat stat = new Stat();
  12. byte[] data = ZKUtil.getDataNoWatch(zkw, zkw.getZNodePaths().masterAddressZNode, stat);
  13. ServerName sn = ProtobufUtil.parseServerNameFrom(data);
  14. if (sn != null && content.equals(sn.toString())) {
  15. return (ZKUtil.deleteNode(zkw, zkw.getZNodePaths().masterAddressZNode, stat.getVersion()));
  16. }
  17. } catch (KeeperException e) {
  18. LOG.warn("Can't get or delete the master znode", e);
  19. } catch (DeserializationException e) {
  20. LOG.warn("Can't get or delete the master znode", e);
  21. }
  22. return false;
  23. }
  24. }

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

  1. if ((data = ZKUtil.getDataNoWatch(watcher, path, stat)) == null) {
  2. SplitLogCounters.tot_wkr_failed_to_grab_task_no_data.increment();
  3. return false;

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

  1. /**
  2. * Return the {lastPushedSequenceId, ZNodeDataVersion} pair. if ZNodeDataVersion is -1, it means
  3. * that the ZNode does not exist.
  4. */
  5. @VisibleForTesting
  6. protected Pair<Long, Integer> getLastSequenceIdWithVersion(String encodedRegionName,
  7. String peerId) throws KeeperException {
  8. Stat stat = new Stat();
  9. String path = getSerialReplicationRegionPeerNode(encodedRegionName, peerId);
  10. byte[] data = ZKUtil.getDataNoWatch(zookeeper, path, stat);
  11. if (data == null) {
  12. // ZNode does not exist, so just return version -1 to indicate that no node exist.
  13. return Pair.newPair(HConstants.NO_SEQNUM, -1);
  14. }
  15. try {
  16. return Pair.newPair(ZKUtil.parseWALPositionFrom(data), stat.getVersion());
  17. } catch (DeserializationException de) {
  18. LOG.warn("Failed to parse log position (region=" + encodedRegionName + ", peerId=" + peerId
  19. + "), data=" + Bytes.toStringBinary(data));
  20. }
  21. return Pair.newPair(HConstants.NO_SEQNUM, stat.getVersion());
  22. }

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

  1. /**
  2. * Create a bunch of znodes in a hierarchy, try deleting one that has childs (it will fail), then
  3. * delete it recursively, then delete the last znode
  4. */
  5. @Test
  6. public void testZNodeDeletes() throws Exception {
  7. ZKUtil.createWithParents(ZKW, "/l1/l2/l3/l4");
  8. try {
  9. ZKUtil.deleteNode(ZKW, "/l1/l2");
  10. fail("We should not be able to delete if znode has childs");
  11. } catch (KeeperException ex) {
  12. assertNotNull(ZKUtil.getDataNoWatch(ZKW, "/l1/l2/l3/l4", null));
  13. }
  14. ZKUtil.deleteNodeRecursively(ZKW, "/l1/l2");
  15. // make sure it really is deleted
  16. assertNull(ZKUtil.getDataNoWatch(ZKW, "/l1/l2/l3/l4", null));
  17. // do the same delete again and make sure it doesn't crash
  18. ZKUtil.deleteNodeRecursively(ZKW, "/l1/l2");
  19. ZKUtil.deleteNode(ZKW, "/l1");
  20. assertNull(ZKUtil.getDataNoWatch(ZKW, "/l1/l2", null));
  21. }

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

  1. /**
  2. * Gets the current data in the unassigned node for the specified region name
  3. * or fully-qualified path.
  4. *
  5. * <p>Returns null if the region does not currently have a node.
  6. *
  7. * <p>Does not set a watch.
  8. *
  9. * @param zkw zk reference
  10. * @param pathOrRegionName fully-specified path or region name
  11. * @param stat object to store node info into on getData call
  12. * @return znode content
  13. * @throws KeeperException if unexpected zookeeper exception
  14. */
  15. public static byte [] getDataNoWatch(ZooKeeperWatcher zkw,
  16. String pathOrRegionName, Stat stat)
  17. throws KeeperException {
  18. String node = getPath(zkw, pathOrRegionName);
  19. return ZKUtil.getDataNoWatch(zkw, node, stat);
  20. }

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

  1. @VisibleForTesting
  2. protected int getQueuesZNodeCversion() throws KeeperException {
  3. Stat stat = new Stat();
  4. ZKUtil.getDataNoWatch(this.zookeeper, this.queuesZNode, stat);
  5. return stat.getCversion();
  6. }

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

  1. @Override public int getQueuesZNodeCversion() throws KeeperException {
  2. try {
  3. Stat stat = new Stat();
  4. ZKUtil.getDataNoWatch(this.zookeeper, this.queuesZNode, stat);
  5. return stat.getCversion();
  6. } catch (KeeperException e) {
  7. this.abortable.abort("Failed to get stat of replication rs node", e);
  8. throw e;
  9. }
  10. }
  11. }

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

  1. @VisibleForTesting
  2. protected int getHFileRefsZNodeCversion() throws ReplicationException {
  3. Stat stat = new Stat();
  4. try {
  5. ZKUtil.getDataNoWatch(zookeeper, hfileRefsZNode, stat);
  6. } catch (KeeperException e) {
  7. throw new ReplicationException("Failed to get stat of replication hfile references node.", e);
  8. }
  9. return stat.getCversion();
  10. }

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

  1. /**
  2. * Gets the current data in the unassigned node for the specified region name
  3. * or fully-qualified path.
  4. *
  5. * <p>Returns null if the region does not currently have a node.
  6. *
  7. * <p>Does not set a watch.
  8. *
  9. * @param zkw zk reference
  10. * @param pathOrRegionName fully-specified path or region name
  11. * @param stat object to store node info into on getData call
  12. * @return data for the unassigned node or null if node does not exist
  13. * @throws KeeperException if unexpected zookeeper exception
  14. */
  15. public static RegionTransitionData getDataNoWatch(ZooKeeperWatcher zkw,
  16. String pathOrRegionName, Stat stat)
  17. throws KeeperException {
  18. String node = pathOrRegionName.startsWith("/") ?
  19. pathOrRegionName : getNodeName(zkw, pathOrRegionName);
  20. byte [] data = ZKUtil.getDataNoWatch(zkw, node, stat);
  21. if (data == null) {
  22. return null;
  23. }
  24. return RegionTransitionData.fromBytes(data);
  25. }

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

  1. private int getZNodeDataVersion(String znode) throws KeeperException {
  2. Stat stat = new Stat();
  3. ZKUtil.getDataNoWatch(ZKW, znode, stat);
  4. return stat.getVersion();
  5. }

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

  1. /**
  2. * delete the master znode if its content is same as the parameter
  3. * @param zkw must not be null
  4. * @param content must not be null
  5. */
  6. public static boolean deleteIfEquals(ZKWatcher zkw, final String content) {
  7. if (content == null){
  8. throw new IllegalArgumentException("Content must not be null");
  9. }
  10. try {
  11. Stat stat = new Stat();
  12. byte[] data = ZKUtil.getDataNoWatch(zkw, zkw.getZNodePaths().masterAddressZNode, stat);
  13. ServerName sn = ProtobufUtil.parseServerNameFrom(data);
  14. if (sn != null && content.equals(sn.toString())) {
  15. return (ZKUtil.deleteNode(zkw, zkw.getZNodePaths().masterAddressZNode, stat.getVersion()));
  16. }
  17. } catch (KeeperException e) {
  18. LOG.warn("Can't get or delete the master znode", e);
  19. } catch (DeserializationException e) {
  20. LOG.warn("Can't get or delete the master znode", e);
  21. }
  22. return false;
  23. }
  24. }

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

  1. /**
  2. * Update state as to indicate that a lock is held
  3. * @param createdZNode The lock znode
  4. * @throws IOException If an unrecoverable ZooKeeper error occurs
  5. */
  6. protected void updateAcquiredLock(String createdZNode) throws IOException {
  7. Stat stat = new Stat();
  8. byte[] data = null;
  9. Exception ex = null;
  10. try {
  11. data = ZKUtil.getDataNoWatch(zkWatcher, createdZNode, stat);
  12. } catch (KeeperException e) {
  13. LOG.warn("Cannot getData for znode:" + createdZNode, e);
  14. ex = e;
  15. }
  16. if (data == null) {
  17. LOG.error("Can't acquire a lock on a non-existent node " + createdZNode);
  18. throw new IllegalStateException("ZNode " + createdZNode +
  19. "no longer exists!", ex);
  20. }
  21. AcquiredLock newLock = new AcquiredLock(createdZNode, stat.getVersion());
  22. if (!acquiredLock.compareAndSet(null, newLock)) {
  23. LOG.error("The lock " + fullyQualifiedZNode +
  24. " has already been acquired by another process!");
  25. throw new IllegalStateException(fullyQualifiedZNode +
  26. " is held by another process");
  27. }
  28. }

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

  1. /**
  2. * Return the last failed RS name under /hbase/recovering-regions/encodedRegionName
  3. * @param encodedRegionName
  4. * @throws KeeperException
  5. */
  6. private String getLastFailedRSFromZK(String encodedRegionName) throws KeeperException {
  7. String result = null;
  8. long maxZxid = 0;
  9. ZooKeeperWatcher zkw = this.getZooKeeper();
  10. String nodePath = ZKUtil.joinZNode(zkw.recoveringRegionsZNode, encodedRegionName);
  11. List<String> failedServers = ZKUtil.listChildrenNoWatch(zkw, nodePath);
  12. if (failedServers == null || failedServers.isEmpty()) {
  13. return result;
  14. }
  15. for (String failedServer : failedServers) {
  16. String rsPath = ZKUtil.joinZNode(nodePath, failedServer);
  17. Stat stat = new Stat();
  18. ZKUtil.getDataNoWatch(zkw, rsPath, stat);
  19. if (maxZxid < stat.getCzxid()) {
  20. maxZxid = stat.getCzxid();
  21. result = failedServer;
  22. }
  23. }
  24. return result;
  25. }

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

  1. /**
  2. * delete the master znode if its content is same as the parameter
  3. * @param zkw must not be null
  4. * @param content must not be null
  5. */
  6. public static boolean deleteIfEquals(ZooKeeperWatcher zkw, final String content) {
  7. if (content == null){
  8. throw new IllegalArgumentException("Content must not be null");
  9. }
  10. try {
  11. Stat stat = new Stat();
  12. byte[] data = ZKUtil.getDataNoWatch(zkw, zkw.getMasterAddressZNode(), stat);
  13. ServerName sn = ServerName.parseFrom(data);
  14. if (sn != null && content.equals(sn.toString())) {
  15. return (ZKUtil.deleteNode(zkw, zkw.getMasterAddressZNode(), stat.getVersion()));
  16. }
  17. } catch (KeeperException e) {
  18. LOG.warn("Can't get or delete the master znode", e);
  19. } catch (DeserializationException e) {
  20. LOG.warn("Can't get or delete the master znode", e);
  21. }
  22. return false;
  23. }
  24. }

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

  1. /**
  2. * Return the {lastPushedSequenceId, ZNodeDataVersion} pair. if ZNodeDataVersion is -1, it means
  3. * that the ZNode does not exist.
  4. */
  5. @VisibleForTesting
  6. protected Pair<Long, Integer> getLastSequenceIdWithVersion(String encodedRegionName,
  7. String peerId) throws KeeperException {
  8. Stat stat = new Stat();
  9. String path = getSerialReplicationRegionPeerNode(encodedRegionName, peerId);
  10. byte[] data = ZKUtil.getDataNoWatch(zookeeper, path, stat);
  11. if (data == null) {
  12. // ZNode does not exist, so just return version -1 to indicate that no node exist.
  13. return Pair.newPair(HConstants.NO_SEQNUM, -1);
  14. }
  15. try {
  16. return Pair.newPair(ZKUtil.parseWALPositionFrom(data), stat.getVersion());
  17. } catch (DeserializationException de) {
  18. LOG.warn("Failed to parse log position (region=" + encodedRegionName + ", peerId=" + peerId
  19. + "), data=" + Bytes.toStringBinary(data));
  20. }
  21. return Pair.newPair(HConstants.NO_SEQNUM, stat.getVersion());
  22. }

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

  1. /**
  2. * Create a bunch of znodes in a hierarchy, try deleting one that has childs (it will fail), then
  3. * delete it recursively, then delete the last znode
  4. */
  5. @Test
  6. public void testZNodeDeletes() throws Exception {
  7. ZKUtil.createWithParents(ZKW, "/l1/l2/l3/l4");
  8. try {
  9. ZKUtil.deleteNode(ZKW, "/l1/l2");
  10. fail("We should not be able to delete if znode has childs");
  11. } catch (KeeperException ex) {
  12. assertNotNull(ZKUtil.getDataNoWatch(ZKW, "/l1/l2/l3/l4", null));
  13. }
  14. ZKUtil.deleteNodeRecursively(ZKW, "/l1/l2");
  15. // make sure it really is deleted
  16. assertNull(ZKUtil.getDataNoWatch(ZKW, "/l1/l2/l3/l4", null));
  17. // do the same delete again and make sure it doesn't crash
  18. ZKUtil.deleteNodeRecursively(ZKW, "/l1/l2");
  19. ZKUtil.deleteNode(ZKW, "/l1");
  20. assertNull(ZKUtil.getDataNoWatch(ZKW, "/l1/l2", null));
  21. }

代码示例来源:origin: com.aliyun.hbase/alihbase-zookeeper

  1. /**
  2. * Create a bunch of znodes in a hierarchy, try deleting one that has childs (it will fail), then
  3. * delete it recursively, then delete the last znode
  4. */
  5. @Test
  6. public void testZNodeDeletes() throws Exception {
  7. ZKUtil.createWithParents(ZKW, "/l1/l2/l3/l4");
  8. try {
  9. ZKUtil.deleteNode(ZKW, "/l1/l2");
  10. fail("We should not be able to delete if znode has childs");
  11. } catch (KeeperException ex) {
  12. assertNotNull(ZKUtil.getDataNoWatch(ZKW, "/l1/l2/l3/l4", null));
  13. }
  14. ZKUtil.deleteNodeRecursively(ZKW, "/l1/l2");
  15. // make sure it really is deleted
  16. assertNull(ZKUtil.getDataNoWatch(ZKW, "/l1/l2/l3/l4", null));
  17. // do the same delete again and make sure it doesn't crash
  18. ZKUtil.deleteNodeRecursively(ZKW, "/l1/l2");
  19. ZKUtil.deleteNode(ZKW, "/l1");
  20. assertNull(ZKUtil.getDataNoWatch(ZKW, "/l1/l2", null));
  21. }

相关文章