/** * 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); }
ZKAsyncRegistry(Configuration conf) { this.znodePaths = new ZNodePaths(conf); this.zk = new ReadOnlyZKClient(conf); }
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 } } /**
@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)); } }
@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); } }
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; } } }
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); } } }
/** * 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 + "/"); }
if (zkw.getZNodePaths().isClientReadable(node)) { acls.addAll(Ids.CREATOR_ALL_ACL); acls.addAll(Ids.READ_ACL_UNSAFE);
@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)); } }
@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); } }
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; } } }
@Override boolean validate(String path) { return watcher.getZNodePaths().isAnyMetaReplicaZNode(path); }
if (zkw.getZNodePaths().isClientReadable(node)) { acls.addAll(Ids.CREATOR_ALL_ACL); acls.addAll(Ids.READ_ACL_UNSAFE);
/** * 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); }
private void unassignMetaReplica(HbckInfo hi) throws IOException, InterruptedException, KeeperException { undeployRegions(hi); ZKUtil.deleteNode(zkw, zkw.getZNodePaths().getZNodeForReplica(hi.metaEntry.getReplicaId())); }
this.znodePaths = new ZNodePaths(conf); PendingWatcher pendingWatcher = new PendingWatcher(); this.recoverableZooKeeper = ZKUtil.connect(conf, quorum, pendingWatcher, identifier);
/** * 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 + "/"); }
/** * 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); }
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"); }