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

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

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

ZKUtil.getParent介绍

[英]Returns the full path of the immediate parent of the specified node.
[中]返回指定节点的直接父节点的完整路径。

代码示例

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

  1. @Override
  2. public void nodeDeleted(String path) {
  3. if (keysParentZNode.equals(ZKUtil.getParent(path))) {
  4. String keyId = ZKUtil.getNodeName(path);
  5. try {
  6. Integer id = Integer.valueOf(keyId);
  7. secretManager.removeKey(id);
  8. } catch (NumberFormatException nfe) {
  9. LOG.error("Invalid znode name for key ID '"+keyId+"'", nfe);
  10. }
  11. }
  12. }

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

  1. @Override
  2. public void nodeDeleted(final String path) {
  3. waitUntilStarted();
  4. if (aclZNode.equals(ZKUtil.getParent(path))) {
  5. asyncProcessNodeUpdate(new Runnable() {
  6. @Override
  7. public void run() {
  8. String table = ZKUtil.getNodeName(path);
  9. if(AccessControlLists.isNamespaceEntry(table)) {
  10. authManager.removeNamespace(Bytes.toBytes(table));
  11. } else {
  12. authManager.removeTable(TableName.valueOf(table));
  13. }
  14. }
  15. });
  16. }
  17. }

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

  1. @Override
  2. public void nodeDataChanged(final String path) {
  3. waitUntilStarted();
  4. if (aclZNode.equals(ZKUtil.getParent(path))) {
  5. asyncProcessNodeUpdate(new Runnable() {
  6. @Override
  7. public void run() {
  8. // update cache on an existing table node
  9. String entry = ZKUtil.getNodeName(path);
  10. try {
  11. byte[] data = ZKUtil.getDataAndWatch(watcher, path);
  12. refreshAuthManager(entry, data);
  13. } catch (KeeperException ke) {
  14. LOG.error("Error reading data from zookeeper for node " + entry, ke);
  15. // only option is to abort
  16. watcher.abort("ZooKeeper error getting data for node " + entry, ke);
  17. } catch (IOException ioe) {
  18. LOG.error("Error reading permissions writables", ioe);
  19. }
  20. }
  21. });
  22. }
  23. }

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

  1. @Override
  2. public void nodeDataChanged(String path) {
  3. if (keysParentZNode.equals(ZKUtil.getParent(path))) {
  4. try {
  5. byte[] data = ZKUtil.getDataAndWatch(watcher, path);
  6. if (data == null || data.length == 0) {
  7. LOG.debug("Ignoring empty node "+path);
  8. return;
  9. }
  10. AuthenticationKey key = (AuthenticationKey)Writables.getWritable(data,
  11. new AuthenticationKey());
  12. secretManager.addKey(key);
  13. } catch (KeeperException ke) {
  14. LOG.error(HBaseMarkers.FATAL, "Error reading data from zookeeper", ke);
  15. watcher.abort("Error reading updated key znode "+path, ke);
  16. } catch (IOException ioe) {
  17. LOG.error(HBaseMarkers.FATAL, "Error reading key writables", ioe);
  18. watcher.abort("Error reading key writables from znode "+path, ioe);
  19. }
  20. }
  21. }

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

  1. @Override
  2. public void nodeCreated(String path) {
  3. if (!isInProcedurePath(path)) {
  4. return;
  5. }
  6. LOG.info("Received created event:" + path);
  7. // if it is a simple start/end/abort then we just rewatch the node
  8. if (isAcquiredNode(path)) {
  9. waitForNewProcedures();
  10. return;
  11. } else if (isAbortNode(path)) {
  12. watchForAbortedProcedures();
  13. return;
  14. }
  15. String parent = ZKUtil.getParent(path);
  16. // if its the end barrier, the procedure can be completed
  17. if (isReachedNode(parent)) {
  18. receivedReachedGlobalBarrier(path);
  19. return;
  20. } else if (isAbortNode(parent)) {
  21. abort(path);
  22. return;
  23. } else if (isAcquiredNode(parent)) {
  24. startNewSubprocedure(path);
  25. } else {
  26. LOG.debug("Ignoring created notification for node:" + path);
  27. }
  28. }

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

  1. public void start() {
  2. try {
  3. watcher.registerListener(this);
  4. String parent = ZKUtil.getParent(leaderZNode);
  5. if (ZKUtil.checkExists(watcher, parent) < 0) {
  6. ZKUtil.createWithParents(watcher, parent);
  7. }
  8. } catch (KeeperException ke) {
  9. watcher.abort("Unhandled zk exception when starting", ke);
  10. candidate.stop("Unhandled zk exception starting up: "+ke.getMessage());
  11. }
  12. }

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

  1. /**
  2. * Creates the specified node and all parent nodes required for it to exist. The creation of
  3. * parent znodes is not atomic with the leafe znode creation but the data is written atomically
  4. * when the leaf node is created.
  5. *
  6. * No watches are set and no errors are thrown if the node already exists.
  7. *
  8. * The nodes created are persistent and open access.
  9. *
  10. * @param zkw zk reference
  11. * @param znode path of node
  12. * @throws KeeperException if unexpected zookeeper exception
  13. */
  14. public static void createWithParents(ZKWatcher zkw, String znode, byte[] data)
  15. throws KeeperException {
  16. try {
  17. if(znode == null) {
  18. return;
  19. }
  20. zkw.getRecoverableZooKeeper().create(znode, data, createACL(zkw, znode),
  21. CreateMode.PERSISTENT);
  22. } catch(KeeperException.NodeExistsException nee) {
  23. return;
  24. } catch(KeeperException.NoNodeException nne) {
  25. createWithParents(zkw, getParent(znode));
  26. createWithParents(zkw, znode, data);
  27. } catch(InterruptedException ie) {
  28. zkw.interruptedException(ie);
  29. }
  30. }

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

  1. if (isAcquiredPathNode(path)) {
  2. coordinator.memberAcquiredBarrier(ZKUtil.getNodeName(ZKUtil.getParent(path)),
  3. ZKUtil.getNodeName(path));
  4. } else if (isReachedPathNode(path)) {
  5. String procName = ZKUtil.getNodeName(ZKUtil.getParent(path));
  6. String member = ZKUtil.getNodeName(path);

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

  1. @Override
  2. public void nodeDeleted(String path) {
  3. if (nsZNode.equals(ZKUtil.getParent(path))) {
  4. String nsName = ZKUtil.getNodeName(path);
  5. cache.remove(nsName);
  6. }
  7. }

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

  1. @Override
  2. public void nodeDeleted(String path) {
  3. if (keysParentZNode.equals(ZKUtil.getParent(path))) {
  4. String keyId = ZKUtil.getNodeName(path);
  5. try {
  6. Integer id = Integer.valueOf(keyId);
  7. secretManager.removeKey(id);
  8. } catch (NumberFormatException nfe) {
  9. LOG.error("Invalid znode name for key ID '"+keyId+"'", nfe);
  10. }
  11. }
  12. }

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

  1. @Override
  2. public void nodeDeleted(String path) {
  3. waitUntilStarted();
  4. if (aclZNode.equals(ZKUtil.getParent(path))) {
  5. String table = ZKUtil.getNodeName(path);
  6. if(AccessControlLists.isNamespaceEntry(table)) {
  7. authManager.removeNamespace(Bytes.toBytes(table));
  8. } else {
  9. authManager.removeTable(TableName.valueOf(table));
  10. }
  11. }
  12. }

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

  1. public void start() {
  2. try {
  3. watcher.registerListener(this);
  4. String parent = ZKUtil.getParent(leaderZNode);
  5. if (ZKUtil.checkExists(watcher, parent) < 0) {
  6. ZKUtil.createWithParents(watcher, parent);
  7. }
  8. } catch (KeeperException ke) {
  9. watcher.abort("Unhandled zk exception when starting", ke);
  10. candidate.stop("Unhandled zk exception starting up: "+ke.getMessage());
  11. }
  12. }

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

  1. public void start() {
  2. try {
  3. watcher.registerListener(this);
  4. String parent = ZKUtil.getParent(leaderZNode);
  5. if (ZKUtil.checkExists(watcher, parent) < 0) {
  6. ZKUtil.createWithParents(watcher, parent);
  7. }
  8. } catch (KeeperException ke) {
  9. watcher.abort("Unhandled zk exception when starting", ke);
  10. candidate.stop("Unhandled zk exception starting up: "+ke.getMessage());
  11. }
  12. }

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

  1. public void start() {
  2. try {
  3. watcher.registerListener(this);
  4. String parent = ZKUtil.getParent(leaderZNode);
  5. if (ZKUtil.checkExists(watcher, parent) < 0) {
  6. ZKUtil.createWithParents(watcher, parent);
  7. }
  8. } catch (KeeperException ke) {
  9. watcher.abort("Unhandled zk exception when starting", ke);
  10. candidate.stop("Unhandled zk exception starting up: "+ke.getMessage());
  11. }
  12. }

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

  1. @Override
  2. public void nodeCreated(String path) {
  3. if (!isInProcedurePath(path)) {
  4. return;
  5. }
  6. LOG.info("Received created event:" + path);
  7. // if it is a simple start/end/abort then we just rewatch the node
  8. if (isAcquiredNode(path)) {
  9. waitForNewProcedures();
  10. return;
  11. } else if (isAbortNode(path)) {
  12. watchForAbortedProcedures();
  13. return;
  14. }
  15. String parent = ZKUtil.getParent(path);
  16. // if its the end barrier, the procedure can be completed
  17. if (isReachedNode(parent)) {
  18. receivedReachedGlobalBarrier(path);
  19. return;
  20. } else if (isAbortNode(parent)) {
  21. abort(path);
  22. return;
  23. } else if (isAcquiredNode(parent)) {
  24. startNewSubprocedure(path);
  25. } else {
  26. LOG.debug("Ignoring created notification for node:" + path);
  27. }
  28. }

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

  1. @Override
  2. public void nodeDataChanged(String path) {
  3. if (nsZNode.equals(ZKUtil.getParent(path))) {
  4. try {
  5. byte[] data = ZKUtil.getDataAndWatch(watcher, path);
  6. NamespaceDescriptor ns =
  7. ProtobufUtil.toNamespaceDescriptor(
  8. HBaseProtos.NamespaceDescriptor.parseFrom(data));
  9. cache.put(ns.getName(), ns);
  10. } catch (KeeperException ke) {
  11. String msg = "Error reading data from zookeeper for node "+path;
  12. LOG.error(msg, ke);
  13. // only option is to abort
  14. watcher.abort(msg, ke);
  15. } catch (IOException ioe) {
  16. String msg = "Error deserializing namespace: "+path;
  17. LOG.error(msg, ioe);
  18. watcher.abort(msg, ioe);
  19. }
  20. }
  21. }

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

  1. @Override
  2. public void nodeDataChanged(String path) {
  3. waitUntilStarted();
  4. if (aclZNode.equals(ZKUtil.getParent(path))) {
  5. // update cache on an existing table node
  6. String entry = ZKUtil.getNodeName(path);
  7. try {
  8. byte[] data = ZKUtil.getDataAndWatch(watcher, path);
  9. refreshAuthManager(entry, data);
  10. } catch (KeeperException ke) {
  11. LOG.error("Error reading data from zookeeper for node " + entry, ke);
  12. // only option is to abort
  13. watcher.abort("Zookeeper error getting data for node " + entry, ke);
  14. } catch (IOException ioe) {
  15. LOG.error("Error reading permissions writables", ioe);
  16. }
  17. }
  18. }

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

  1. @Override
  2. public void nodeCreated(String path) {
  3. if (!isInProcedurePath(path)) return;
  4. LOG.debug("Node created: " + path);
  5. logZKTree(this.baseZNode);
  6. if (isAcquiredPathNode(path)) {
  7. // node wasn't present when we created the watch so zk event triggers acquire
  8. coordinator.memberAcquiredBarrier(ZKUtil.getNodeName(ZKUtil.getParent(path)),
  9. ZKUtil.getNodeName(path));
  10. } else if (isReachedPathNode(path)) {
  11. // node was absent when we created the watch so zk event triggers the finished barrier.
  12. // TODO Nothing enforces that acquire and reached znodes from showing up in wrong order.
  13. coordinator.memberFinishedBarrier(ZKUtil.getNodeName(ZKUtil.getParent(path)),
  14. ZKUtil.getNodeName(path));
  15. } else if (isAbortPathNode(path)) {
  16. abort(path);
  17. }
  18. }
  19. };

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

  1. @Override
  2. public void nodeDataChanged(String path) {
  3. if (keysParentZNode.equals(ZKUtil.getParent(path))) {
  4. try {
  5. byte[] data = ZKUtil.getDataAndWatch(watcher, path);
  6. if (data == null || data.length == 0) {
  7. LOG.debug("Ignoring empty node "+path);
  8. return;
  9. }
  10. AuthenticationKey key = (AuthenticationKey)Writables.getWritable(data,
  11. new AuthenticationKey());
  12. secretManager.addKey(key);
  13. } catch (KeeperException ke) {
  14. LOG.fatal("Error reading data from zookeeper", ke);
  15. watcher.abort("Error reading updated key znode "+path, ke);
  16. } catch (IOException ioe) {
  17. LOG.fatal("Error reading key writables", ioe);
  18. watcher.abort("Error reading key writables from znode "+path, ioe);
  19. }
  20. }
  21. }

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

  1. @Override
  2. public void nodeCreated(String path) {
  3. if (!isInProcedurePath(path)) {
  4. return;
  5. }
  6. LOG.info("Received created event:" + path);
  7. // if it is a simple start/end/abort then we just rewatch the node
  8. if (isAcquiredNode(path)) {
  9. waitForNewProcedures();
  10. return;
  11. } else if (isAbortNode(path)) {
  12. watchForAbortedProcedures();
  13. return;
  14. }
  15. String parent = ZKUtil.getParent(path);
  16. // if its the end barrier, the procedure can be completed
  17. if (isReachedNode(parent)) {
  18. receivedReachedGlobalBarrier(path);
  19. return;
  20. } else if (isAbortNode(parent)) {
  21. abort(path);
  22. return;
  23. } else if (isAcquiredNode(parent)) {
  24. startNewSubprocedure(path);
  25. } else {
  26. LOG.debug("Ignoring created notification for node:" + path);
  27. }
  28. }

相关文章