/** * Gets the full path node name for the unassigned node for the specified * entityGroup. * @param zkw zk reference * @param entityGroupName entityGroup name * @return full path node name */ public static String getNodeName(ZooKeeperWatcher zkw, String entityGroupName) { return ZKUtil.joinZNode(zkw.assignmentZNode, entityGroupName); }
/** * Set the local variable node names using the specified configuration. */ private void setNodeNames(Configuration conf) { baseZNode = conf.get(FConstants.ZOOKEEPER_ZNODE_PARENT, FConstants.DEFAULT_ZOOKEEPER_ZNODE_PARENT); fsZNode = ZKUtil.joinZNode(baseZNode, conf.get("zookeeper.znode.fs", "fs")); drainingZNode = ZKUtil.joinZNode(baseZNode, conf.get("zookeeper.znode.draining.fs", "draining")); masterAddressZNode = ZKUtil.joinZNode(baseZNode, conf.get("zookeeper.znode.master", "master")); backupMasterAddressesZNode = ZKUtil.joinZNode(baseZNode, conf.get("zookeeper.znode.backup.masters", "backup-masters")); clusterStateZNode = ZKUtil.joinZNode(baseZNode, conf.get("zookeeper.znode.state", "shutdown")); assignmentZNode = ZKUtil.joinZNode(baseZNode, conf.get("zookeeper.znode.unassigned", "unassigned")); tableZNode = ZKUtil.joinZNode(baseZNode, conf.get("zookeeper.znode.tableEnableDisable", "table")); clusterIdZNode = ZKUtil.joinZNode(baseZNode, conf.get("zookeeper.znode.clusterId", "waspid")); balancerZNode = ZKUtil.joinZNode(baseZNode, conf.get("zookeeper.znode.balancer", "balancer")); }
/** * Deletes the table in zookeeper. Fails silently if the table is not * currently disabled in zookeeper. Sets no watches. * * @param tableName * @throws org.apache.zookeeper.KeeperException * unexpected zookeeper exception */ public void setDeletedTable(final String tableName) throws KeeperException { synchronized (this.cache) { if (this.cache.remove(tableName) == null) { LOG.warn("Moving table " + tableName + " state to deleted but was " + "already deleted"); } ZKUtil.deleteNodeFailSilent(this.watcher, ZKUtil.joinZNode(this.watcher.tableZNode, tableName)); } }
/** * Delete all the children of the specified node but not the node itself. * * Sets no watches. Throws all exceptions besides dealing with deletion of * children. */ public static void deleteChildrenRecursively(ZooKeeperWatcher zkw, String node) throws KeeperException { List<String> children = ZKUtil.listChildrenNoWatch(zkw, node); if (children == null || children.isEmpty()) return; for (String child : children) { deleteNodeRecursively(zkw, joinZNode(node, child)); } }
private String getMyEphemeralNodePath() { return ZKUtil.joinZNode(this.zooKeeper.fsZNode, getServerName().toString()); }
/** * 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 org.apache.zookeeper.KeeperException */ public static List<String> listChildrenAndWatchThem(ZooKeeperWatcher zkw, String znode) throws KeeperException { List<String> children = listChildrenAndWatchForNewChildren(zkw, znode); if (children == null) { return null; } for (String child : children) { watchAndCheckExists(zkw, joinZNode(znode, child)); } return children; }
/** * Delete the specified node and all of it's children. * <p> * If the node does not exist, just returns. * <p> * Sets no watches. Throws all exceptions besides dealing with deletion of * children. */ public static void deleteNodeRecursively(ZooKeeperWatcher zkw, String node) throws KeeperException { try { List<String> children = ZKUtil.listChildrenNoWatch(zkw, node); // the node is already deleted, so we just finish if (children == null) return; if (!children.isEmpty()) { for (String child : children) { deleteNodeRecursively(zkw, joinZNode(node, child)); } } zkw.getRecoverableZooKeeper().delete(node, -1); } catch (InterruptedException ie) { zkw.interruptedException(ie); } }
@Override public void run() { try { // Just make sure we see the changes for the new znodes List<String> children = ZKUtil.listChildrenAndWatchForNewChildren( watcher, watcher.assignmentZNode); if (children != null) { for (String child : children) { // if entityGroup is in transition, we already have a watch // on it, so no need to watch it again. So, as I know for now, // this is needed to watch splitting nodes only. if (!entityGroupStates.isEntityGroupInTransition(child)) { ZKUtil.watchAndCheckExists(watcher, ZKUtil.joinZNode(watcher.assignmentZNode, child)); } } } } catch (KeeperException e) { server.abort("Unexpected ZK exception reading unassigned children", e); } } });
private void setTableState(final String tableName, final ZooKeeperProtos.Table.State state) throws KeeperException { String znode = ZKUtil.joinZNode(this.watcher.tableZNode, tableName); if (ZKUtil.checkExists(this.watcher, znode) == -1) { ZKUtil.createAndFailSilent(this.watcher, znode); } synchronized (this.cache) { ZooKeeperProtos.Table.Builder builder = ZooKeeperProtos.Table .newBuilder(); builder.setState(state); byte[] data = builder.build().toByteArray(); ZKUtil.setData(this.watcher, znode, data); this.cache.put(tableName, state); } }
try { byte[] bytes = ZKUtil.getData(this.zooKeeper, ZKUtil.joinZNode(this.zooKeeper.backupMasterAddressesZNode, s)); if (bytes != null) { ServerName sn;
/** * @param zkw * @param child * @return Null or {@link org.apache.hadoop.hbase.zookeeper.ZKTable.TableState} found in znode. * @throws org.apache.zookeeper.KeeperException */ static ZooKeeperProtos.Table.State getTableState(final ZooKeeperWatcher zkw, final String child) throws KeeperException { String znode = ZKUtil.joinZNode(zkw.tableZNode, child); byte[] data = ZKUtil.getData(zkw, znode); if (data == null || data.length <= 0) return null; try { ZooKeeperProtos.Table.Builder builder = ZooKeeperProtos.Table .newBuilder(); ZooKeeperProtos.Table t = builder.mergeFrom(data, 0, data.length).build(); return t.getState(); } catch (InvalidProtocolBufferException e) { KeeperException ke = new KeeperException.DataInconsistencyException(); ke.initCause(e); throw ke; } } }
String backupZNode = ZKUtil.joinZNode( this.watcher.backupMasterAddressesZNode, this.sn.toString()); if (MasterAddressTracker.setMasterAddress(this.watcher,