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

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

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

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

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

@VisibleForTesting
protected int getHFileRefsZNodeCversion() throws ReplicationException {
 Stat stat = new Stat();
 try {
  ZKUtil.getDataNoWatch(zookeeper, hfileRefsZNode, stat);
 } catch (KeeperException e) {
  throw new ReplicationException("Failed to get stat of replication hfile references node.", e);
 }
 return stat.getCversion();
}

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

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

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

/**
  * delete the master znode if its content is same as the parameter
  * @param zkw must not be null
  * @param content must not be null
  */
 public static boolean deleteIfEquals(ZKWatcher zkw, final String content) {
  if (content == null){
   throw new IllegalArgumentException("Content must not be null");
  }

  try {
   Stat stat = new Stat();
   byte[] data = ZKUtil.getDataNoWatch(zkw, zkw.getZNodePaths().masterAddressZNode, stat);
   ServerName sn = ProtobufUtil.parseServerNameFrom(data);
   if (sn != null && content.equals(sn.toString())) {
    return (ZKUtil.deleteNode(zkw, zkw.getZNodePaths().masterAddressZNode, stat.getVersion()));
   }
  } catch (KeeperException e) {
   LOG.warn("Can't get or delete the master znode", e);
  } catch (DeserializationException e) {
   LOG.warn("Can't get or delete the master znode", e);
  }

  return false;
 }
}

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

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

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

/**
 * Return the {lastPushedSequenceId, ZNodeDataVersion} pair. if ZNodeDataVersion is -1, it means
 * that the ZNode does not exist.
 */
@VisibleForTesting
protected Pair<Long, Integer> getLastSequenceIdWithVersion(String encodedRegionName,
  String peerId) throws KeeperException {
 Stat stat = new Stat();
 String path = getSerialReplicationRegionPeerNode(encodedRegionName, peerId);
 byte[] data = ZKUtil.getDataNoWatch(zookeeper, path, stat);
 if (data == null) {
  // ZNode does not exist, so just return version -1 to indicate that no node exist.
  return Pair.newPair(HConstants.NO_SEQNUM, -1);
 }
 try {
  return Pair.newPair(ZKUtil.parseWALPositionFrom(data), stat.getVersion());
 } catch (DeserializationException de) {
  LOG.warn("Failed to parse log position (region=" + encodedRegionName + ", peerId=" + peerId
    + "), data=" + Bytes.toStringBinary(data));
 }
 return Pair.newPair(HConstants.NO_SEQNUM, stat.getVersion());
}

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

/**
 * Create a bunch of znodes in a hierarchy, try deleting one that has childs (it will fail), then
 * delete it recursively, then delete the last znode
 */
@Test
public void testZNodeDeletes() throws Exception {
 ZKUtil.createWithParents(ZKW, "/l1/l2/l3/l4");
 try {
  ZKUtil.deleteNode(ZKW, "/l1/l2");
  fail("We should not be able to delete if znode has childs");
 } catch (KeeperException ex) {
  assertNotNull(ZKUtil.getDataNoWatch(ZKW, "/l1/l2/l3/l4", null));
 }
 ZKUtil.deleteNodeRecursively(ZKW, "/l1/l2");
 // make sure it really is deleted
 assertNull(ZKUtil.getDataNoWatch(ZKW, "/l1/l2/l3/l4", null));
 // do the same delete again and make sure it doesn't crash
 ZKUtil.deleteNodeRecursively(ZKW, "/l1/l2");
 ZKUtil.deleteNode(ZKW, "/l1");
 assertNull(ZKUtil.getDataNoWatch(ZKW, "/l1/l2", null));
}

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

/**
 * Gets the current data in the unassigned node for the specified region name
 * or fully-qualified path.
 *
 * <p>Returns null if the region does not currently have a node.
 *
 * <p>Does not set a watch.
 *
 * @param zkw zk reference
 * @param pathOrRegionName fully-specified path or region name
 * @param stat object to store node info into on getData call
 * @return znode content
 * @throws KeeperException if unexpected zookeeper exception
 */
public static byte [] getDataNoWatch(ZooKeeperWatcher zkw,
  String pathOrRegionName, Stat stat)
throws KeeperException {
 String node = getPath(zkw, pathOrRegionName);
 return ZKUtil.getDataNoWatch(zkw, node, stat);
}

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

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

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

@Override public int getQueuesZNodeCversion() throws KeeperException {
  try {
   Stat stat = new Stat();
   ZKUtil.getDataNoWatch(this.zookeeper, this.queuesZNode, stat);
   return stat.getCversion();
  } catch (KeeperException e) {
   this.abortable.abort("Failed to get stat of replication rs node", e);
   throw e;
  }
 }
}

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

@VisibleForTesting
protected int getHFileRefsZNodeCversion() throws ReplicationException {
 Stat stat = new Stat();
 try {
  ZKUtil.getDataNoWatch(zookeeper, hfileRefsZNode, stat);
 } catch (KeeperException e) {
  throw new ReplicationException("Failed to get stat of replication hfile references node.", e);
 }
 return stat.getCversion();
}

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

/**
 * Gets the current data in the unassigned node for the specified region name
 * or fully-qualified path.
 *
 * <p>Returns null if the region does not currently have a node.
 *
 * <p>Does not set a watch.
 *
 * @param zkw zk reference
 * @param pathOrRegionName fully-specified path or region name
 * @param stat object to store node info into on getData call
 * @return data for the unassigned node or null if node does not exist
 * @throws KeeperException if unexpected zookeeper exception
 */
public static RegionTransitionData getDataNoWatch(ZooKeeperWatcher zkw,
  String pathOrRegionName, Stat stat)
throws KeeperException {
 String node = pathOrRegionName.startsWith("/") ?
   pathOrRegionName : getNodeName(zkw, pathOrRegionName);
 byte [] data = ZKUtil.getDataNoWatch(zkw, node, stat);
 if (data == null) {
  return null;
 }
 return RegionTransitionData.fromBytes(data);
}

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

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

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

/**
  * delete the master znode if its content is same as the parameter
  * @param zkw must not be null
  * @param content must not be null
  */
 public static boolean deleteIfEquals(ZKWatcher zkw, final String content) {
  if (content == null){
   throw new IllegalArgumentException("Content must not be null");
  }

  try {
   Stat stat = new Stat();
   byte[] data = ZKUtil.getDataNoWatch(zkw, zkw.getZNodePaths().masterAddressZNode, stat);
   ServerName sn = ProtobufUtil.parseServerNameFrom(data);
   if (sn != null && content.equals(sn.toString())) {
    return (ZKUtil.deleteNode(zkw, zkw.getZNodePaths().masterAddressZNode, stat.getVersion()));
   }
  } catch (KeeperException e) {
   LOG.warn("Can't get or delete the master znode", e);
  } catch (DeserializationException e) {
   LOG.warn("Can't get or delete the master znode", e);
  }

  return false;
 }
}

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

/**
 * Update state as to indicate that a lock is held
 * @param createdZNode The lock znode
 * @throws IOException If an unrecoverable ZooKeeper error occurs
 */
protected void updateAcquiredLock(String createdZNode) throws IOException {
 Stat stat = new Stat();
 byte[] data = null;
 Exception ex = null;
 try {
  data = ZKUtil.getDataNoWatch(zkWatcher, createdZNode, stat);
 } catch (KeeperException e) {
  LOG.warn("Cannot getData for znode:" + createdZNode, e);
  ex = e;
 }
 if (data == null) {
  LOG.error("Can't acquire a lock on a non-existent node " + createdZNode);
  throw new IllegalStateException("ZNode " + createdZNode +
    "no longer exists!", ex);
 }
 AcquiredLock newLock = new AcquiredLock(createdZNode, stat.getVersion());
 if (!acquiredLock.compareAndSet(null, newLock)) {
  LOG.error("The lock " + fullyQualifiedZNode +
    " has already been acquired by another process!");
  throw new IllegalStateException(fullyQualifiedZNode +
    " is held by another process");
 }
}

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

/**
 * Return the last failed RS name under /hbase/recovering-regions/encodedRegionName
 * @param encodedRegionName
 * @throws KeeperException
 */
private String getLastFailedRSFromZK(String encodedRegionName) throws KeeperException {
 String result = null;
 long maxZxid = 0;
 ZooKeeperWatcher zkw = this.getZooKeeper();
 String nodePath = ZKUtil.joinZNode(zkw.recoveringRegionsZNode, encodedRegionName);
 List<String> failedServers = ZKUtil.listChildrenNoWatch(zkw, nodePath);
 if (failedServers == null || failedServers.isEmpty()) {
  return result;
 }
 for (String failedServer : failedServers) {
  String rsPath = ZKUtil.joinZNode(nodePath, failedServer);
  Stat stat = new Stat();
  ZKUtil.getDataNoWatch(zkw, rsPath, stat);
  if (maxZxid < stat.getCzxid()) {
   maxZxid = stat.getCzxid();
   result = failedServer;
  }
 }
 return result;
}

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

/**
  * delete the master znode if its content is same as the parameter
  * @param zkw must not be null
  * @param content must not be null
  */
 public static boolean deleteIfEquals(ZooKeeperWatcher zkw, final String content) {
  if (content == null){
   throw new IllegalArgumentException("Content must not be null");
  }

  try {
   Stat stat = new Stat();
   byte[] data = ZKUtil.getDataNoWatch(zkw, zkw.getMasterAddressZNode(), stat);
   ServerName sn = ServerName.parseFrom(data);
   if (sn != null && content.equals(sn.toString())) {
    return (ZKUtil.deleteNode(zkw, zkw.getMasterAddressZNode(), stat.getVersion()));
   }
  } catch (KeeperException e) {
   LOG.warn("Can't get or delete the master znode", e);
  } catch (DeserializationException e) {
   LOG.warn("Can't get or delete the master znode", e);
  }

  return false;
 }
}

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

/**
 * Return the {lastPushedSequenceId, ZNodeDataVersion} pair. if ZNodeDataVersion is -1, it means
 * that the ZNode does not exist.
 */
@VisibleForTesting
protected Pair<Long, Integer> getLastSequenceIdWithVersion(String encodedRegionName,
  String peerId) throws KeeperException {
 Stat stat = new Stat();
 String path = getSerialReplicationRegionPeerNode(encodedRegionName, peerId);
 byte[] data = ZKUtil.getDataNoWatch(zookeeper, path, stat);
 if (data == null) {
  // ZNode does not exist, so just return version -1 to indicate that no node exist.
  return Pair.newPair(HConstants.NO_SEQNUM, -1);
 }
 try {
  return Pair.newPair(ZKUtil.parseWALPositionFrom(data), stat.getVersion());
 } catch (DeserializationException de) {
  LOG.warn("Failed to parse log position (region=" + encodedRegionName + ", peerId=" + peerId
    + "), data=" + Bytes.toStringBinary(data));
 }
 return Pair.newPair(HConstants.NO_SEQNUM, stat.getVersion());
}

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

/**
 * Create a bunch of znodes in a hierarchy, try deleting one that has childs (it will fail), then
 * delete it recursively, then delete the last znode
 */
@Test
public void testZNodeDeletes() throws Exception {
 ZKUtil.createWithParents(ZKW, "/l1/l2/l3/l4");
 try {
  ZKUtil.deleteNode(ZKW, "/l1/l2");
  fail("We should not be able to delete if znode has childs");
 } catch (KeeperException ex) {
  assertNotNull(ZKUtil.getDataNoWatch(ZKW, "/l1/l2/l3/l4", null));
 }
 ZKUtil.deleteNodeRecursively(ZKW, "/l1/l2");
 // make sure it really is deleted
 assertNull(ZKUtil.getDataNoWatch(ZKW, "/l1/l2/l3/l4", null));
 // do the same delete again and make sure it doesn't crash
 ZKUtil.deleteNodeRecursively(ZKW, "/l1/l2");
 ZKUtil.deleteNode(ZKW, "/l1");
 assertNull(ZKUtil.getDataNoWatch(ZKW, "/l1/l2", null));
}

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

/**
 * Create a bunch of znodes in a hierarchy, try deleting one that has childs (it will fail), then
 * delete it recursively, then delete the last znode
 */
@Test
public void testZNodeDeletes() throws Exception {
 ZKUtil.createWithParents(ZKW, "/l1/l2/l3/l4");
 try {
  ZKUtil.deleteNode(ZKW, "/l1/l2");
  fail("We should not be able to delete if znode has childs");
 } catch (KeeperException ex) {
  assertNotNull(ZKUtil.getDataNoWatch(ZKW, "/l1/l2/l3/l4", null));
 }
 ZKUtil.deleteNodeRecursively(ZKW, "/l1/l2");
 // make sure it really is deleted
 assertNull(ZKUtil.getDataNoWatch(ZKW, "/l1/l2/l3/l4", null));
 // do the same delete again and make sure it doesn't crash
 ZKUtil.deleteNodeRecursively(ZKW, "/l1/l2");
 ZKUtil.deleteNode(ZKW, "/l1");
 assertNull(ZKUtil.getDataNoWatch(ZKW, "/l1/l2", null));
}

相关文章

微信公众号

最新文章

更多