/** * Gets the current data in the unassigned node for the specified region name or fully-qualified * path. * * <p>Returns null if the region does not currently have a node. * * <p>Sets a watch on the node if the node exists. * * @param zkw zk reference * @param pathOrRegionName fully-specified path or region name * @param stat object to populate the version. * @return data for the unassigned node * @throws KeeperException if unexpected zookeeper exception */ public static RegionTransitionData getDataAndWatch( ZooKeeperWatcher zkw, String pathOrRegionName, Stat stat) throws KeeperException { String node = pathOrRegionName.startsWith("/") ? pathOrRegionName : getNodeName(zkw, pathOrRegionName); byte[] data = ZKUtil.getDataAndWatch(zkw, node, stat); if (data == null) { return null; } return RegionTransitionData.fromBytes(data); }
/** * Verifies that the specified region is in the specified state in ZooKeeper. * * <p>Returns true if region is in transition and in the specified state in ZooKeeper. Returns * false if the region does not exist in ZK or is in a different state. * * <p>Method synchronizes() with ZK so will yield an up-to-date result but is a slow read. * * @param zkw * @param region * @param expectedState * @return true if region exists and is in expected state */ public static boolean verifyRegionState( ZooKeeperWatcher zkw, HRegionInfo region, EventType expectedState) throws KeeperException { String encoded = region.getEncodedName(); String node = getNodeName(zkw, encoded); zkw.sync(node); // Read existing data of the node byte[] existingBytes = null; try { existingBytes = ZKUtil.getDataAndWatch(zkw, node); } catch (KeeperException.NoNodeException nne) { return false; } catch (KeeperException e) { throw e; } if (existingBytes == null) return false; RegionTransitionData existingData = RegionTransitionData.fromBytes(existingBytes); if (existingData.getEventType() == expectedState) { return true; } return false; }