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

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

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

ZKUtil.createNodeIfNotExistsAndWatch介绍

[英]Creates the specified znode to be a persistent node carrying the specified data. Returns true if the node was successfully created, false if the node already existed. If the node is created successfully, a watcher is also set on the node. If the node is not created successfully because it already exists, this method will also set a watcher on the node but return false. If there is another problem, a KeeperException will be thrown.
[中]将指定的znode创建为承载指定数据的持久节点。如果节点已成功创建,则返回true;如果节点已存在,则返回false。如果节点创建成功,也会在节点上设置观察者。如果由于节点已存在而未能成功创建该节点,此方法还将在该节点上设置一个监视程序,但返回false。如果还有其他问题,将抛出KeeperException。

代码示例

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

  1. /**
  2. * Utility method to ensure an ENABLED znode is in place; if not present, we create it.
  3. * @param zookeeper
  4. * @param path Path to znode to check
  5. * @return True if we created the znode.
  6. * @throws NodeExistsException
  7. * @throws KeeperException
  8. */
  9. private static boolean ensurePeerEnabled(final ZooKeeperWatcher zookeeper, final String path)
  10. throws NodeExistsException, KeeperException {
  11. if (ZKUtil.checkExists(zookeeper, path) == -1) {
  12. // There is a race b/w PeerWatcher and ReplicationZookeeper#add method to create the
  13. // peer-state znode. This happens while adding a peer.
  14. // The peer state data is set as "ENABLED" by default.
  15. ZKUtil.createNodeIfNotExistsAndWatch(zookeeper, path,
  16. ReplicationStateZKBase.ENABLED_ZNODE_BYTES);
  17. return true;
  18. }
  19. return false;
  20. }

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

  1. /**
  2. * Add a new peer to this cluster
  3. * @param id peer's identifier
  4. * @param clusterKey ZK ensemble's addresses, client port and root znode
  5. * @throws IllegalArgumentException Thrown when the peer doesn't exist
  6. * @throws IllegalStateException Thrown when a peer already exists, since
  7. * multi-slave isn't supported yet.
  8. */
  9. public void addPeer(String id, String clusterKey) throws IOException {
  10. try {
  11. if (peerExists(id)) {
  12. throw new IllegalArgumentException("Cannot add existing peer");
  13. }
  14. ZKUtil.createWithParents(this.zookeeper, this.peersZNode);
  15. ZKUtil.createAndWatch(this.zookeeper, ZKUtil.joinZNode(this.peersZNode, id),
  16. Bytes.toBytes(clusterKey));
  17. // There is a race b/w PeerWatcher and ReplicationZookeeper#add method to create the
  18. // peer-state znode. This happens while adding a peer.
  19. // The peer state data is set as "ENABLED" by default.
  20. ZKUtil.createNodeIfNotExistsAndWatch(this.zookeeper, getPeerStateNode(id),
  21. Bytes.toBytes(PeerState.ENABLED.name()));
  22. } catch (KeeperException e) {
  23. throw new IOException("Unable to add peer", e);
  24. }
  25. }

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

  1. /**
  2. * start a state tracker to check whether this peer is enabled or not
  3. *
  4. * @param zookeeper zk watcher for the local cluster
  5. * @param peerStateNode path to zk node which stores peer state
  6. * @throws KeeperException
  7. */
  8. public void startStateTracker(ZooKeeperWatcher zookeeper, String peerStateNode)
  9. throws KeeperException {
  10. if (ZKUtil.checkExists(zookeeper, peerStateNode) == -1) {
  11. // There is a race b/w PeerWatcher and ReplicationZookeeper#add method to create the
  12. // peer-state znode. This happens while adding a peer.
  13. // The peer state data is set as "ENABLED" by default.
  14. ZKUtil.createNodeIfNotExistsAndWatch(zookeeper, peerStateNode,
  15. Bytes.toBytes(PeerState.ENABLED.name()));
  16. }
  17. this.peerStateTracker = new PeerStateTracker(peerStateNode, zookeeper,
  18. this);
  19. this.peerStateTracker.start();
  20. this.readPeerStateZnode();
  21. }

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

  1. continue;
  2. ZKUtil.createNodeIfNotExistsAndWatch(this.zookeeper, newClusterZnode,
  3. HConstants.EMPTY_BYTE_ARRAY);
  4. SortedSet<String> logQueue = new TreeSet<String>();

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

  1. continue;
  2. ZKUtil.createNodeIfNotExistsAndWatch(this.zookeeper, newClusterZnode,
  3. HConstants.EMPTY_BYTE_ARRAY);
  4. SortedSet<String> logQueue = new TreeSet<String>();

相关文章