org.apache.hadoop.hbase.zookeeper.ZNodePaths类的使用及代码示例

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

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

ZNodePaths介绍

[英]Class that hold all the paths of znode for HBase.
[中]类,该类保存HBase的znode的所有路径。

代码示例

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

/**
 * Get the full znode path for the node used by the coordinator to trigger a global barrier
 * execution and release on each subprocedure.
 * @param controller controller running the procedure
 * @param opInstanceName name of the running procedure instance (not the procedure description).
 * @return full znode path to the commit barrier
 */
public static String getReachedBarrierNode(ZKProcedureUtil controller,
  String opInstanceName) {
 return ZNodePaths.joinZNode(controller.reachedZnode, opInstanceName);
}

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

ZKAsyncRegistry(Configuration conf) {
 this.znodePaths = new ZNodePaths(conf);
 this.zk = new ReadOnlyZKClient(conf);
}

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

public static void deleteMetaLocation(ZKWatcher zookeeper, int replicaId)
 throws KeeperException {
 if (replicaId == RegionInfo.DEFAULT_REPLICA_ID) {
  LOG.info("Deleting hbase:meta region location in ZooKeeper");
 } else {
  LOG.info("Deleting hbase:meta for " + replicaId + " region location in ZooKeeper");
 }
 try {
  // Just delete the node.  Don't need any watches.
  ZKUtil.deleteNode(zookeeper, zookeeper.getZNodePaths().getZNodeForReplica(replicaId));
 } catch(KeeperException.NoNodeException nne) {
  // Has already been deleted
 }
}
/**

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

@Test
 public void testIsClientReadable() {
  ZNodePaths znodePaths = new ZNodePaths(HBaseConfiguration.create());
  assertTrue(znodePaths.isClientReadable(znodePaths.baseZNode));
  assertTrue(znodePaths.isClientReadable(znodePaths.getZNodeForReplica(0)));
  assertTrue(znodePaths.isClientReadable(znodePaths.masterAddressZNode));
  assertTrue(znodePaths.isClientReadable(znodePaths.clusterIdZNode));
  assertTrue(znodePaths.isClientReadable(znodePaths.tableZNode));
  assertTrue(znodePaths.isClientReadable(ZNodePaths.joinZNode(znodePaths.tableZNode, "foo")));
  assertTrue(znodePaths.isClientReadable(znodePaths.rsZNode));

  assertFalse(znodePaths.isClientReadable(znodePaths.tableLockZNode));
  assertFalse(znodePaths.isClientReadable(znodePaths.balancerZNode));
  assertFalse(znodePaths.isClientReadable(znodePaths.regionNormalizerZNode));
  assertFalse(znodePaths.isClientReadable(znodePaths.clusterStateZNode));
  assertFalse(znodePaths.isClientReadable(znodePaths.drainingZNode));
  assertFalse(znodePaths.isClientReadable(znodePaths.splitLogZNode));
  assertFalse(znodePaths.isClientReadable(znodePaths.backupMasterAddressesZNode));
 }
}

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

@Test
public void testZookeeperNodesForReplicas() throws Exception {
 // Checks all the znodes exist when meta's replicas are enabled
 ZKWatcher zkw = TEST_UTIL.getZooKeeperWatcher();
 Configuration conf = TEST_UTIL.getConfiguration();
 String baseZNode = conf.get(HConstants.ZOOKEEPER_ZNODE_PARENT,
   HConstants.DEFAULT_ZOOKEEPER_ZNODE_PARENT);
 String primaryMetaZnode = ZNodePaths.joinZNode(baseZNode,
   conf.get("zookeeper.znode.metaserver", "meta-region-server"));
 // check that the data in the znode is parseable (this would also mean the znode exists)
 byte[] data = ZKUtil.getData(zkw, primaryMetaZnode);
 ProtobufUtil.toServerName(data);
 for (int i = 1; i < 3; i++) {
  String secZnode = ZNodePaths.joinZNode(baseZNode,
    conf.get("zookeeper.znode.metaserver", "meta-region-server") + "-" + i);
  String str = zkw.getZNodePaths().getZNodeForReplica(i);
  assertTrue(str.equals(secZnode));
  // check that the data in the znode is parseable (this would also mean the znode exists)
  data = ZKUtil.getData(zkw, secZnode);
  ProtobufUtil.toServerName(data);
 }
}

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

private void checkZnodePermsRecursive(ZKWatcher watcher,
  RecoverableZooKeeper zk, String znode) throws KeeperException, InterruptedException {
 boolean expectedWorldReadable = watcher.getZNodePaths().isClientReadable(znode);
 assertZnodePerms(zk, znode, expectedWorldReadable);
 try {
  List<String> children = zk.getChildren(znode, false);
  for (String child : children) {
   checkZnodePermsRecursive(watcher, zk, ZNodePaths.joinZNode(znode, child));
  }
 } catch (KeeperException ke) {
  // if we are not authenticated for listChildren, it is fine.
  if (ke.code() != Code.NOAUTH && ke.code() != Code.NONODE) {
   throw ke;
  }
 }
}

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

private void unassignExcessMetaReplica(int numMetaReplicasConfigured) {
  final ZKWatcher zooKeeper = master.getZooKeeper();
  // unassign the unneeded replicas (for e.g., if the previous master was configured
  // with a replication of 3 and now it is 2, we need to unassign the 1 unneeded replica)
  try {
   List<String> metaReplicaZnodes = zooKeeper.getMetaReplicaNodes();
   for (String metaReplicaZnode : metaReplicaZnodes) {
    int replicaId = zooKeeper.getZNodePaths().getMetaReplicaIdFromZnode(metaReplicaZnode);
    if (replicaId >= numMetaReplicasConfigured) {
     RegionState r = MetaTableLocator.getMetaRegionState(zooKeeper, replicaId);
     LOG.info("Closing excess replica of meta region " + r.getRegion());
     // send a close and wait for a max of 30 seconds
     ServerManager.closeRegionSilentlyAndWait(master.getClusterConnection(),
       r.getServerName(), r.getRegion(), 30000);
     ZKUtil.deleteNode(zooKeeper, zooKeeper.getZNodePaths().getZNodeForReplica(replicaId));
    }
   }
  } catch (Exception ex) {
   // ignore the exception since we don't want the master to be wedged due to potential
   // issues in the cleanup of the extra regions. We can do that cleanup via hbck or manually
   LOG.warn("Ignoring exception " + ex);
  }
 }
}

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

/**
 * Returns whether the znode is supposed to be readable by the client and DOES NOT contain
 * sensitive information (world readable).
 */
public boolean isClientReadable(String node) {
 // Developer notice: These znodes are world readable. DO NOT add more znodes here UNLESS
 // all clients need to access this data to work. Using zk for sharing data to clients (other
 // than service lookup case is not a recommended design pattern.
 return node.equals(baseZNode) || isAnyMetaReplicaZNode(node) ||
  node.equals(masterAddressZNode) || node.equals(clusterIdZNode) || node.equals(rsZNode) ||
  // /hbase/table and /hbase/table/foo is allowed, /hbase/table-lock is not
  node.equals(tableZNode) || node.startsWith(tableZNode + "/");
}

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

if (zkw.getZNodePaths().isClientReadable(node)) {
 acls.addAll(Ids.CREATOR_ALL_ACL);
 acls.addAll(Ids.READ_ACL_UNSAFE);

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

@Test
 public void testIsClientReadable() {
  ZNodePaths znodePaths = new ZNodePaths(HBaseConfiguration.create());
  assertTrue(znodePaths.isClientReadable(znodePaths.baseZNode));
  assertTrue(znodePaths.isClientReadable(znodePaths.getZNodeForReplica(0)));
  assertTrue(znodePaths.isClientReadable(znodePaths.masterAddressZNode));
  assertTrue(znodePaths.isClientReadable(znodePaths.clusterIdZNode));
  assertTrue(znodePaths.isClientReadable(znodePaths.tableZNode));
  assertTrue(znodePaths.isClientReadable(ZNodePaths.joinZNode(znodePaths.tableZNode, "foo")));
  assertTrue(znodePaths.isClientReadable(znodePaths.rsZNode));

  assertFalse(znodePaths.isClientReadable(znodePaths.tableLockZNode));
  assertFalse(znodePaths.isClientReadable(znodePaths.balancerZNode));
  assertFalse(znodePaths.isClientReadable(znodePaths.regionNormalizerZNode));
  assertFalse(znodePaths.isClientReadable(znodePaths.clusterStateZNode));
  assertFalse(znodePaths.isClientReadable(znodePaths.drainingZNode));
  assertFalse(znodePaths.isClientReadable(znodePaths.splitLogZNode));
  assertFalse(znodePaths.isClientReadable(znodePaths.backupMasterAddressesZNode));
 }
}

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

@Test
public void testZookeeperNodesForReplicas() throws Exception {
 // Checks all the znodes exist when meta's replicas are enabled
 ZKWatcher zkw = TEST_UTIL.getZooKeeperWatcher();
 Configuration conf = TEST_UTIL.getConfiguration();
 String baseZNode = conf.get(HConstants.ZOOKEEPER_ZNODE_PARENT,
   HConstants.DEFAULT_ZOOKEEPER_ZNODE_PARENT);
 String primaryMetaZnode = ZNodePaths.joinZNode(baseZNode,
   conf.get("zookeeper.znode.metaserver", "meta-region-server"));
 // check that the data in the znode is parseable (this would also mean the znode exists)
 byte[] data = ZKUtil.getData(zkw, primaryMetaZnode);
 ProtobufUtil.toServerName(data);
 for (int i = 1; i < 3; i++) {
  String secZnode = ZNodePaths.joinZNode(baseZNode,
    conf.get("zookeeper.znode.metaserver", "meta-region-server") + "-" + i);
  String str = zkw.getZNodePaths().getZNodeForReplica(i);
  assertTrue(str.equals(secZnode));
  // check that the data in the znode is parseable (this would also mean the znode exists)
  data = ZKUtil.getData(zkw, secZnode);
  ProtobufUtil.toServerName(data);
 }
}

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

private void checkZnodePermsRecursive(ZKWatcher watcher,
  RecoverableZooKeeper zk, String znode) throws KeeperException, InterruptedException {
 boolean expectedWorldReadable = watcher.getZNodePaths().isClientReadable(znode);
 assertZnodePerms(zk, znode, expectedWorldReadable);
 try {
  List<String> children = zk.getChildren(znode, false);
  for (String child : children) {
   checkZnodePermsRecursive(watcher, zk, ZNodePaths.joinZNode(znode, child));
  }
 } catch (KeeperException ke) {
  // if we are not authenticated for listChildren, it is fine.
  if (ke.code() != Code.NOAUTH && ke.code() != Code.NONODE) {
   throw ke;
  }
 }
}

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

@Override
boolean validate(String path) {
 return watcher.getZNodePaths().isAnyMetaReplicaZNode(path);
}

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

if (zkw.getZNodePaths().isClientReadable(node)) {
 acls.addAll(Ids.CREATOR_ALL_ACL);
 acls.addAll(Ids.READ_ACL_UNSAFE);

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

/**
 * Get the full znode path for the node used by the coordinator to trigger a global barrier
 * acquire on each subprocedure.
 * @param controller controller running the procedure
 * @param opInstanceName name of the running procedure instance (not the procedure description).
 * @return full znode path to the prepare barrier/start node
 */
public static String getAcquireBarrierNode(ZKProcedureUtil controller,
  String opInstanceName) {
 return ZNodePaths.joinZNode(controller.acquiredZnode, opInstanceName);
}

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

private void unassignMetaReplica(HbckInfo hi) throws IOException, InterruptedException,
KeeperException {
 undeployRegions(hi);
 ZKUtil.deleteNode(zkw, zkw.getZNodePaths().getZNodeForReplica(hi.metaEntry.getReplicaId()));
}

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

this.znodePaths = new ZNodePaths(conf);
PendingWatcher pendingWatcher = new PendingWatcher();
this.recoverableZooKeeper = ZKUtil.connect(conf, quorum, pendingWatcher, identifier);

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

/**
 * Returns whether the znode is supposed to be readable by the client and DOES NOT contain
 * sensitive information (world readable).
 */
public boolean isClientReadable(String node) {
 // Developer notice: These znodes are world readable. DO NOT add more znodes here UNLESS
 // all clients need to access this data to work. Using zk for sharing data to clients (other
 // than service lookup case is not a recommended design pattern.
 return node.equals(baseZNode) || isAnyMetaReplicaZNode(node) ||
  node.equals(masterAddressZNode) || node.equals(clusterIdZNode) || node.equals(rsZNode) ||
  // /hbase/table and /hbase/table/foo is allowed, /hbase/table-lock is not
  node.equals(tableZNode) || node.startsWith(tableZNode + "/");
}

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

/**
 * Get the full znode path for the node used by the coordinator or member to trigger an abort
 * of the global barrier acquisition or execution in subprocedures.
 * @param controller controller running the procedure
 * @param opInstanceName name of the running procedure instance (not the procedure description).
 * @return full znode path to the abort znode
 */
public static String getAbortNode(ZKProcedureUtil controller, String opInstanceName) {
 return ZNodePaths.joinZNode(controller.abortZnode, opInstanceName);
}

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

private static void waitUntilZnodeAvailable(int replicaId) throws Exception {
 String znode = util.getZooKeeperWatcher().getZNodePaths().getZNodeForReplica(replicaId);
 int i = 0;
 while (i < 1000) {
  if (ZKUtil.checkExists(util.getZooKeeperWatcher(), znode) == -1) {
   Thread.sleep(100);
   i++;
  } else break;
 }
 if (i == 1000) throw new IOException("znode for meta replica " + replicaId + " not available");
}

相关文章