gpt4 book ai didi

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

转载 作者:知者 更新时间:2024-03-16 01:26:40 28 4
gpt4 key购买 nike

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

ZKUtil.watchAndCheckExists介绍

[英]Watch the specified znode for delete/create/change events. The watcher is set whether or not the node exists. If the node already exists, the method returns true. If the node does not exist, the method returns false.
[中]查看指定的znode中的删除/创建/更改事件。观察者被设置为节点是否存在。如果节点已经存在,则该方法返回true。如果节点不存在,则该方法返回false。

代码示例

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

@Override
public void nodeCreated(String path) {
 if (path.equals(labelZnode) || path.equals(userAuthsZnode)) {
  try {
   ZKUtil.watchAndCheckExists(watcher, path);
  } catch (KeeperException ke) {
   LOG.error("Error setting watcher on node " + path, ke);
   // only option is to abort
   watcher.abort("ZooKeeper error obtaining label node children", ke);
  }
 }
}

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

/**
 * Sets the watch on the top-level archive znode, and then updates the monitor with the current
 * tables that should be archived (and ensures that those nodes are watched as well).
 */
private void checkEnabledAndUpdate() {
 try {
  if (ZKUtil.watchAndCheckExists(watcher, archiveHFileZNode)) {
   LOG.debug(archiveHFileZNode + " znode does exist, checking for tables to archive");
   // update the tables we should backup, to get the most recent state.
   // This is safer than also watching for children and then hoping we get
   // all the updates as it makes sure we get and watch all the children
   updateWatchedTables();
  } else {
   LOG.debug("Archiving not currently enabled, waiting");
  }
 } catch (KeeperException e) {
  LOG.warn("Failed to watch for archiving znode", e);
 }
}

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

@Override
public synchronized void nodeDeleted(String path) {
 if (validate(path)) {
  try {
   if (ZKUtil.watchAndCheckExists(watcher, path)) {
    nodeCreated(path);
   }
  } catch (KeeperException e) {
   LOG.warn("Unexpected exception handling nodeDeleted event for path: " + path, e);
  }
 }
}

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

public void start() throws KeeperException {
 try {
  watcher.registerListener(this);
  if (ZKUtil.watchAndCheckExists(watcher, aclZNode)) {
   try {
    executor.submit(new Callable<Void>() {
     @Override
     public Void call() throws KeeperException {
      List<ZKUtil.NodeAndData> existing =
        ZKUtil.getChildDataAndWatchForNewChildren(watcher, aclZNode);
      if (existing != null) {
       refreshNodes(existing);
      }
      return null;
     }
    }).get();
   } catch (ExecutionException ex) {
    if (ex.getCause() instanceof KeeperException) {
     throw (KeeperException)ex.getCause();
    } else {
     throw new RuntimeException(ex.getCause());
    }
   } catch (InterruptedException ex) {
    Thread.currentThread().interrupt();
   }
  }
 } finally {
  initialized.countDown();
 }
}

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

@Override
public synchronized void nodeDeleted(String path) {
 if(path.equals(node)) {
  try {
   if(ZKUtil.watchAndCheckExists(watcher, node)) {
    nodeCreated(path);
   } else {
    this.data = null;
   }
  } catch(KeeperException e) {
   abortable.abort("Unexpected exception handling nodeDeleted event", e);
  }
 }
}

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

private void handleLeaderChange() {
 try {
  synchronized(lock) {
   if (ZKUtil.watchAndCheckExists(watcher, leaderZNode)) {
    LOG.info("Found new leader for znode: "+leaderZNode);
    leaderExists.set(true);
   } else {
    LOG.info("Leader change, but no new leader found");
    leaderExists.set(false);
    lock.notifyAll();
   }
  }
 } catch (KeeperException ke) {
  watcher.abort("ZooKeeper error checking for leader znode", ke);
  candidate.stop("ZooKeeper error checking for leader: "+ke.getMessage());
 }
}

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

if (ZKUtil.watchAndCheckExists(watcher, watcher.getZNodePaths().masterAddressZNode)) {

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

/**
 * List all the children of the specified znode, setting a watch for children
 * changes and also setting a watch on every individual child in order to get
 * the NodeCreated and NodeDeleted events.
 * @param zkw zookeeper reference
 * @param znode node to get children of and watch
 * @return list of znode names, null if the node doesn't exist
 * @throws KeeperException if a ZooKeeper operation fails
 */
public static List<String> listChildrenAndWatchThem(ZKWatcher zkw,
  String znode) throws KeeperException {
 List<String> children = listChildrenAndWatchForNewChildren(zkw, znode);
 if (children == null) {
  return null;
 }
 for (String child : children) {
  watchAndCheckExists(zkw, ZNodePaths.joinZNode(znode, child));
 }
 return children;
}

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

public void start() throws KeeperException {
 watcher.registerListener(this);
 // make sure the base node exists
 ZKUtil.createWithParents(watcher, keysParentZNode);
 if (ZKUtil.watchAndCheckExists(watcher, keysParentZNode)) {
  List<ZKUtil.NodeAndData> nodes =
    ZKUtil.getChildDataAndWatchForNewChildren(watcher, keysParentZNode);
  refreshNodes(nodes);
 }
}

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

Thread.currentThread().interrupt();
if(!watchAndCheckExists(zkw, znode)) {

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

/**
 * Starts the tracking of the node in ZooKeeper.
 *
 * <p>Use {@link #blockUntilAvailable()} to block until the node is available
 * or {@link #getData(boolean)} to get the data of the node if it is available.
 */
public synchronized void start() {
 this.watcher.registerListener(this);
 try {
  if(ZKUtil.watchAndCheckExists(watcher, node)) {
   byte [] data = ZKUtil.getDataAndWatch(watcher, node);
   if(data != null) {
    this.data = data;
   } else {
    // It existed but now does not, try again to ensure a watch is set
    LOG.debug("Try starting again because there is no data from " + node);
    start();
   }
  }
 } catch (KeeperException e) {
  abortable.abort("Unexpected exception during initialization, aborting", e);
 }
}

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

/**
 * Add this table to the tracker and then read a watch on that node.
 * <p>
 * Handles situation where table is deleted in the time between the update and resetting the watch
 * by deleting the table via {@link #safeStopTrackingTable(String)}
 * @param tableZnode full zookeeper path to the table to be added
 * @throws KeeperException if an unexpected zk exception occurs
 */
private void addAndReWatchTable(String tableZnode) throws KeeperException {
 getMonitor().addTable(ZKUtil.getNodeName(tableZnode));
 // re-add a watch to the table created
 // and check to make sure it wasn't deleted
 if (!ZKUtil.watchAndCheckExists(watcher, tableZnode)) {
  safeStopTrackingTable(tableZnode);
 }
}

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

private void watchAndCheckExists(String node) {
 try {
  if (ZKUtil.watchAndCheckExists(watcher, node)) {
   byte[] data = ZKUtil.getDataAndWatch(watcher, node);
   if (data != null) {
    // put the data into queue
    upsertQueue(node, data);
   } else {
    // It existed but now does not, should has been tracked by our watcher, ignore
    LOG.debug("Found no data from " + node);
    watchAndCheckExists(node);
   }
  } else {
   // cleanup stale ZNodes on client ZK to avoid invalid requests to server
   ZKUtil.deleteNodeFailSilent(clientZkWatcher, node);
  }
 } catch (KeeperException e) {
  server.abort("Unexpected exception during initialization, aborting", e);
 }
}

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

try {
 if (ZKUtil.watchAndCheckExists(zkProc.getWatcher(), abortNode)) {
  abort(abortNode);
  String znode = ZNodePaths.joinZNode(acquire, node);
  LOG.debug("Watching for acquire node:" + znode);
  if (ZKUtil.watchAndCheckExists(zkProc.getWatcher(), znode)) {
   coordinator.memberAcquiredBarrier(procName, node);

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

if (ZKUtil.watchAndCheckExists(zkProc.getWatcher(), znode)) {
 byte[] dataFromMember = ZKUtil.getData(zkProc.getWatcher(), znode);

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

if (ZKUtil.watchAndCheckExists(zkController.getWatcher(), abortZNode)) {
 LOG.debug("Not starting:" + opName + " because we already have an abort notification.");
 return;

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

/**
 * This attempts to create an acquired state znode for the procedure (snapshot name).
 *
 * It then looks for the reached znode to trigger in-barrier execution.  If not present we
 * have a watcher, if present then trigger the in-barrier action.
 */
@Override
public void sendMemberAcquired(Subprocedure sub) throws IOException {
 String procName = sub.getName();
 try {
  LOG.debug("Member: '" + memberName + "' joining acquired barrier for procedure (" + procName
    + ") in zk");
  String acquiredZNode = ZNodePaths.joinZNode(ZKProcedureUtil.getAcquireBarrierNode(
   zkController, procName), memberName);
  ZKUtil.createAndFailSilent(zkController.getWatcher(), acquiredZNode);
  // watch for the complete node for this snapshot
  String reachedBarrier = zkController.getReachedBarrierNode(procName);
  LOG.debug("Watch for global barrier reached:" + reachedBarrier);
  if (ZKUtil.watchAndCheckExists(zkController.getWatcher(), reachedBarrier)) {
   receivedReachedGlobalBarrier(reachedBarrier);
  }
 } catch (KeeperException e) {
  member.controllerConnectionFailure("Failed to acquire barrier for procedure: "
    + procName + " and member: " + memberName, e, procName);
 }
}

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

private String submitTaskAndWait(TaskBatch batch, String name) throws KeeperException,
  InterruptedException {
 String tasknode = ZKSplitLog.getEncodedNodeName(zkw, name);
 NodeCreationListener listener = new NodeCreationListener(zkw, tasknode);
 zkw.registerListener(listener);
 ZKUtil.watchAndCheckExists(zkw, tasknode);
 slm.enqueueSplitTask(name, batch);
 assertEquals(1, batch.installed);
 assertTrue(findOrCreateOrphanTask(tasknode).batch == batch);
 assertEquals(1L, tot_mgr_node_create_queued.sum());
 LOG.debug("waiting for task node creation");
 listener.waitForCreation();
 LOG.debug("task created");
 return tasknode;
}

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

@Override
public void nodeCreated(String path) {
 if (path.equals(labelZnode) || path.equals(userAuthsZnode)) {
  try {
   ZKUtil.watchAndCheckExists(watcher, path);
  } catch (KeeperException ke) {
   LOG.error("Error setting watcher on node " + path, ke);
   // only option is to abort
   watcher.abort("Zookeeper error obtaining label node children", ke);
  }
 }
}

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

public void start() throws KeeperException {
 watcher.registerListener(this);
 // make sure the base node exists
 ZKUtil.createWithParents(watcher, keysParentZNode);
 if (ZKUtil.watchAndCheckExists(watcher, keysParentZNode)) {
  List<ZKUtil.NodeAndData> nodes =
    ZKUtil.getChildDataAndWatchForNewChildren(watcher, keysParentZNode);
  refreshNodes(nodes);
 }
}

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com