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

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

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

ZKUtil.createEphemeralNodeAndWatch介绍

[英]Set the specified znode to be an ephemeral node carrying the specified data. 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. If there is another problem, a KeeperException will be thrown.
[中]将指定的znode设置为携带指定数据的临时节点。如果节点创建成功,也会在节点上设置观察者。如果由于节点已存在而未能成功创建该节点,则此方法还将在该节点上设置观察者。如果还有其他问题,将抛出KeeperException。

代码示例

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

  1. /**
  2. * Set master address into the <code>master</code> znode or into the backup
  3. * subdirectory of backup masters; switch off the passed in <code>znode</code>
  4. * path.
  5. * @param zkw The ZKWatcher to use.
  6. * @param znode Where to create the znode; could be at the top level or it
  7. * could be under backup masters
  8. * @param master ServerName of the current master must not be null.
  9. * @return true if node created, false if not; a watch is set in both cases
  10. * @throws KeeperException if a ZooKeeper operation fails
  11. */
  12. public static boolean setMasterAddress(final ZKWatcher zkw,
  13. final String znode, final ServerName master, int infoPort)
  14. throws KeeperException {
  15. return ZKUtil.createEphemeralNodeAndWatch(zkw, znode, toByteArray(master, infoPort));
  16. }

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

  1. return createEphemeralNodeAndWatch(zkw, znode, data);

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

  1. while (!candidate.isStopped()) {
  2. try {
  3. if (ZKUtil.createEphemeralNodeAndWatch(watcher, leaderZNode, nodeId)) {

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

  1. do {
  2. try {
  3. hbckZodeCreated = ZKUtil.createEphemeralNodeAndWatch(zkw, hbckEphemeralNodePath, null);
  4. if (hbckZodeCreated) {
  5. break;

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

  1. private void createMyEphemeralNode() throws KeeperException, IOException {
  2. RegionServerInfo.Builder rsInfo = RegionServerInfo.newBuilder();
  3. rsInfo.setInfoPort(infoServer != null ? infoServer.getPort() : -1);
  4. rsInfo.setVersionInfo(ProtobufUtil.getVersionInfo());
  5. byte[] data = ProtobufUtil.prependPBMagic(rsInfo.build().toByteArray());
  6. ZKUtil.createEphemeralNodeAndWatch(this.zooKeeper, getMyEphemeralNodePath(), data);
  7. }

代码示例来源:origin: XiaoMi/themis

  1. private void createMyEphemeralNode() throws Exception {
  2. createAliveParentNode();
  3. ZKUtil.createEphemeralNodeAndWatch(this.watcher, aliveClientPath, Bytes.toBytes(clientNameStr));
  4. }

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

  1. private void createMyEphemeralNode() throws KeeperException {
  2. ZKUtil.createEphemeralNodeAndWatch(this.zooKeeper, getMyEphemeralNodePath(),
  3. HConstants.EMPTY_BYTE_ARRAY);
  4. }

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

  1. /**
  2. * Set master address into the <code>master</code> znode or into the backup
  3. * subdirectory of backup masters; switch off the passed in <code>znode</code>
  4. * path.
  5. * @param zkw The ZKWatcher to use.
  6. * @param znode Where to create the znode; could be at the top level or it
  7. * could be under backup masters
  8. * @param master ServerName of the current master must not be null.
  9. * @return true if node created, false if not; a watch is set in both cases
  10. * @throws KeeperException if a ZooKeeper operation fails
  11. */
  12. public static boolean setMasterAddress(final ZKWatcher zkw,
  13. final String znode, final ServerName master, int infoPort)
  14. throws KeeperException {
  15. return ZKUtil.createEphemeralNodeAndWatch(zkw, znode, toByteArray(master, infoPort));
  16. }

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

  1. /**
  2. * Set master address into the <code>master</code> znode or into the backup
  3. * subdirectory of backup masters; switch off the passed in <code>znode</code>
  4. * path.
  5. * @param zkw The ZooKeeperWatcher to use.
  6. * @param znode Where to create the znode; could be at the top level or it
  7. * could be under backup masters
  8. * @param master ServerName of the current master must not be null.
  9. * @return true if node created, false if not; a watch is set in both cases
  10. * @throws KeeperException
  11. */
  12. public static boolean setMasterAddress(final ZooKeeperWatcher zkw,
  13. final String znode, final ServerName master, int infoPort)
  14. throws KeeperException {
  15. return ZKUtil.createEphemeralNodeAndWatch(zkw, znode, toByteArray(master, infoPort));
  16. }

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

  1. if(!watchAndCheckExists(zkw, znode)) {
  2. return createEphemeralNodeAndWatch(zkw, znode, data);

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

  1. return createEphemeralNodeAndWatch(zkw, znode, data);

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

  1. while (!candidate.isStopped()) {
  2. try {
  3. if (ZKUtil.createEphemeralNodeAndWatch(watcher, leaderZNode, nodeId)) {

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

  1. while (!candidate.isStopped()) {
  2. try {
  3. if (ZKUtil.createEphemeralNodeAndWatch(watcher, leaderZNode, nodeId)) {

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

  1. return createEphemeralNodeAndWatch(zkw, znode, data);

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

  1. /**
  2. * Creates a new ephemeral node in the SPLITTING state for the specified region.
  3. * Create it ephemeral in case regionserver dies mid-split.
  4. *
  5. * <p>Does not transition nodes from other states. If a node already exists
  6. * for this region, a {@link NodeExistsException} will be thrown.
  7. *
  8. * @param zkw zk reference
  9. * @param region region to be created as offline
  10. * @param serverName server event originates from
  11. * @return Version of znode created.
  12. * @throws KeeperException
  13. * @throws IOException
  14. */
  15. void createNodeSplitting(final ZooKeeperWatcher zkw, final HRegionInfo region,
  16. final ServerName serverName) throws KeeperException, IOException {
  17. LOG.debug(zkw.prefix("Creating ephemeral node for " +
  18. region.getEncodedName() + " in SPLITTING state"));
  19. RegionTransitionData data =
  20. new RegionTransitionData(EventType.RS_ZK_REGION_SPLITTING,
  21. region.getRegionName(), serverName);
  22. String node = ZKAssign.getNodeName(zkw, region.getEncodedName());
  23. if (!ZKUtil.createEphemeralNodeAndWatch(zkw, node, data.getBytes())) {
  24. throw new IOException("Failed create of ephemeral " + node);
  25. }
  26. }

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

  1. String backupZNode = ZKUtil.joinZNode(
  2. this.watcher.backupMasterAddressesZNode, this.sn.toString());
  3. if (ZKUtil.createEphemeralNodeAndWatch(this.watcher,
  4. this.watcher.masterAddressZNode, this.sn.getVersionedBytes())) {
  5. ZKUtil.createEphemeralNodeAndWatch(this.watcher, backupZNode,
  6. this.sn.getVersionedBytes());

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

  1. /**
  2. * Creates a new ephemeral node in the PENDING_MERGE state for the merged region.
  3. * Create it ephemeral in case regionserver dies mid-merge.
  4. *
  5. * <p>
  6. * Does not transition nodes from other states. If a node already exists for
  7. * this region, a {@link org.apache.zookeeper.KeeperException.NodeExistsException} will be thrown.
  8. *
  9. * @param region region to be created as offline
  10. * @param serverName server event originates from
  11. * @throws IOException
  12. */
  13. @Override
  14. public void startRegionMergeTransaction(final HRegionInfo region, final ServerName serverName,
  15. final HRegionInfo a, final HRegionInfo b) throws IOException {
  16. LOG.debug(watcher.prefix("Creating ephemeral node for " + region.getEncodedName()
  17. + " in PENDING_MERGE state"));
  18. byte[] payload = HRegionInfo.toDelimitedByteArray(region, a, b);
  19. RegionTransition rt =
  20. RegionTransition.createRegionTransition(RS_ZK_REQUEST_REGION_MERGE, region.getRegionName(),
  21. serverName, payload);
  22. String node = ZKAssign.getNodeName(watcher, region.getEncodedName());
  23. try {
  24. if (!ZKUtil.createEphemeralNodeAndWatch(watcher, node, rt.toByteArray())) {
  25. throw new IOException("Failed create of ephemeral " + node);
  26. }
  27. } catch (KeeperException e) {
  28. throw new IOException(e);
  29. }
  30. }

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

  1. while (!candidate.isStopped()) {
  2. try {
  3. if (ZKUtil.createEphemeralNodeAndWatch(watcher, leaderZNode, nodeId)) {

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

  1. private void createMyEphemeralNode() throws KeeperException, IOException {
  2. RegionServerInfo.Builder rsInfo = RegionServerInfo.newBuilder();
  3. rsInfo.setInfoPort(infoServer != null ? infoServer.getPort() : -1);
  4. rsInfo.setVersionInfo(ProtobufUtil.getVersionInfo());
  5. byte[] data = ProtobufUtil.prependPBMagic(rsInfo.build().toByteArray());
  6. ZKUtil.createEphemeralNodeAndWatch(this.zooKeeper,
  7. getMyEphemeralNodePath(), data);
  8. }

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

  1. region.getRegionName(), serverName, payload);
  2. String node = ZKAssign.getNodeName(watcher, region.getEncodedName());
  3. if (!ZKUtil.createEphemeralNodeAndWatch(watcher, node, rt.toByteArray())) {
  4. throw new IOException("Failed create of ephemeral " + node);

相关文章