@VisibleForTesting protected int getQueuesZNodeCversion() throws KeeperException { Stat stat = new Stat(); ZKUtil.getDataNoWatch(this.zookeeper, this.queuesZNode, stat); return stat.getCversion(); }
@VisibleForTesting protected int getHFileRefsZNodeCversion() throws ReplicationException { Stat stat = new Stat(); try { ZKUtil.getDataNoWatch(zookeeper, hfileRefsZNode, stat); } catch (KeeperException e) { throw new ReplicationException("Failed to get stat of replication hfile references node.", e); } return stat.getCversion(); }
private int getZNodeDataVersion(String znode) throws KeeperException { Stat stat = new Stat(); ZKUtil.getDataNoWatch(ZKW, znode, stat); return stat.getVersion(); }
/** * delete the master znode if its content is same as the parameter * @param zkw must not be null * @param content must not be null */ public static boolean deleteIfEquals(ZKWatcher zkw, final String content) { if (content == null){ throw new IllegalArgumentException("Content must not be null"); } try { Stat stat = new Stat(); byte[] data = ZKUtil.getDataNoWatch(zkw, zkw.getZNodePaths().masterAddressZNode, stat); ServerName sn = ProtobufUtil.parseServerNameFrom(data); if (sn != null && content.equals(sn.toString())) { return (ZKUtil.deleteNode(zkw, zkw.getZNodePaths().masterAddressZNode, stat.getVersion())); } } catch (KeeperException e) { LOG.warn("Can't get or delete the master znode", e); } catch (DeserializationException e) { LOG.warn("Can't get or delete the master znode", e); } return false; } }
if ((data = ZKUtil.getDataNoWatch(watcher, path, stat)) == null) { SplitLogCounters.tot_wkr_failed_to_grab_task_no_data.increment(); return false;
/** * Return the {lastPushedSequenceId, ZNodeDataVersion} pair. if ZNodeDataVersion is -1, it means * that the ZNode does not exist. */ @VisibleForTesting protected Pair<Long, Integer> getLastSequenceIdWithVersion(String encodedRegionName, String peerId) throws KeeperException { Stat stat = new Stat(); String path = getSerialReplicationRegionPeerNode(encodedRegionName, peerId); byte[] data = ZKUtil.getDataNoWatch(zookeeper, path, stat); if (data == null) { // ZNode does not exist, so just return version -1 to indicate that no node exist. return Pair.newPair(HConstants.NO_SEQNUM, -1); } try { return Pair.newPair(ZKUtil.parseWALPositionFrom(data), stat.getVersion()); } catch (DeserializationException de) { LOG.warn("Failed to parse log position (region=" + encodedRegionName + ", peerId=" + peerId + "), data=" + Bytes.toStringBinary(data)); } return Pair.newPair(HConstants.NO_SEQNUM, stat.getVersion()); }
/** * Create a bunch of znodes in a hierarchy, try deleting one that has childs (it will fail), then * delete it recursively, then delete the last znode */ @Test public void testZNodeDeletes() throws Exception { ZKUtil.createWithParents(ZKW, "/l1/l2/l3/l4"); try { ZKUtil.deleteNode(ZKW, "/l1/l2"); fail("We should not be able to delete if znode has childs"); } catch (KeeperException ex) { assertNotNull(ZKUtil.getDataNoWatch(ZKW, "/l1/l2/l3/l4", null)); } ZKUtil.deleteNodeRecursively(ZKW, "/l1/l2"); // make sure it really is deleted assertNull(ZKUtil.getDataNoWatch(ZKW, "/l1/l2/l3/l4", null)); // do the same delete again and make sure it doesn't crash ZKUtil.deleteNodeRecursively(ZKW, "/l1/l2"); ZKUtil.deleteNode(ZKW, "/l1"); assertNull(ZKUtil.getDataNoWatch(ZKW, "/l1/l2", null)); }
/** * 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>Does not set a watch. * * @param zkw zk reference * @param pathOrRegionName fully-specified path or region name * @param stat object to store node info into on getData call * @return znode content * @throws KeeperException if unexpected zookeeper exception */ public static byte [] getDataNoWatch(ZooKeeperWatcher zkw, String pathOrRegionName, Stat stat) throws KeeperException { String node = getPath(zkw, pathOrRegionName); return ZKUtil.getDataNoWatch(zkw, node, stat); }
@VisibleForTesting protected int getQueuesZNodeCversion() throws KeeperException { Stat stat = new Stat(); ZKUtil.getDataNoWatch(this.zookeeper, this.queuesZNode, stat); return stat.getCversion(); }
@Override public int getQueuesZNodeCversion() throws KeeperException { try { Stat stat = new Stat(); ZKUtil.getDataNoWatch(this.zookeeper, this.queuesZNode, stat); return stat.getCversion(); } catch (KeeperException e) { this.abortable.abort("Failed to get stat of replication rs node", e); throw e; } } }
@VisibleForTesting protected int getHFileRefsZNodeCversion() throws ReplicationException { Stat stat = new Stat(); try { ZKUtil.getDataNoWatch(zookeeper, hfileRefsZNode, stat); } catch (KeeperException e) { throw new ReplicationException("Failed to get stat of replication hfile references node.", e); } return stat.getCversion(); }
/** * 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>Does not set a watch. * * @param zkw zk reference * @param pathOrRegionName fully-specified path or region name * @param stat object to store node info into on getData call * @return data for the unassigned node or null if node does not exist * @throws KeeperException if unexpected zookeeper exception */ public static RegionTransitionData getDataNoWatch(ZooKeeperWatcher zkw, String pathOrRegionName, Stat stat) throws KeeperException { String node = pathOrRegionName.startsWith("/") ? pathOrRegionName : getNodeName(zkw, pathOrRegionName); byte [] data = ZKUtil.getDataNoWatch(zkw, node, stat); if (data == null) { return null; } return RegionTransitionData.fromBytes(data); }
private int getZNodeDataVersion(String znode) throws KeeperException { Stat stat = new Stat(); ZKUtil.getDataNoWatch(ZKW, znode, stat); return stat.getVersion(); }
/** * delete the master znode if its content is same as the parameter * @param zkw must not be null * @param content must not be null */ public static boolean deleteIfEquals(ZKWatcher zkw, final String content) { if (content == null){ throw new IllegalArgumentException("Content must not be null"); } try { Stat stat = new Stat(); byte[] data = ZKUtil.getDataNoWatch(zkw, zkw.getZNodePaths().masterAddressZNode, stat); ServerName sn = ProtobufUtil.parseServerNameFrom(data); if (sn != null && content.equals(sn.toString())) { return (ZKUtil.deleteNode(zkw, zkw.getZNodePaths().masterAddressZNode, stat.getVersion())); } } catch (KeeperException e) { LOG.warn("Can't get or delete the master znode", e); } catch (DeserializationException e) { LOG.warn("Can't get or delete the master znode", e); } return false; } }
/** * Update state as to indicate that a lock is held * @param createdZNode The lock znode * @throws IOException If an unrecoverable ZooKeeper error occurs */ protected void updateAcquiredLock(String createdZNode) throws IOException { Stat stat = new Stat(); byte[] data = null; Exception ex = null; try { data = ZKUtil.getDataNoWatch(zkWatcher, createdZNode, stat); } catch (KeeperException e) { LOG.warn("Cannot getData for znode:" + createdZNode, e); ex = e; } if (data == null) { LOG.error("Can't acquire a lock on a non-existent node " + createdZNode); throw new IllegalStateException("ZNode " + createdZNode + "no longer exists!", ex); } AcquiredLock newLock = new AcquiredLock(createdZNode, stat.getVersion()); if (!acquiredLock.compareAndSet(null, newLock)) { LOG.error("The lock " + fullyQualifiedZNode + " has already been acquired by another process!"); throw new IllegalStateException(fullyQualifiedZNode + " is held by another process"); } }
/** * Return the last failed RS name under /hbase/recovering-regions/encodedRegionName * @param encodedRegionName * @throws KeeperException */ private String getLastFailedRSFromZK(String encodedRegionName) throws KeeperException { String result = null; long maxZxid = 0; ZooKeeperWatcher zkw = this.getZooKeeper(); String nodePath = ZKUtil.joinZNode(zkw.recoveringRegionsZNode, encodedRegionName); List<String> failedServers = ZKUtil.listChildrenNoWatch(zkw, nodePath); if (failedServers == null || failedServers.isEmpty()) { return result; } for (String failedServer : failedServers) { String rsPath = ZKUtil.joinZNode(nodePath, failedServer); Stat stat = new Stat(); ZKUtil.getDataNoWatch(zkw, rsPath, stat); if (maxZxid < stat.getCzxid()) { maxZxid = stat.getCzxid(); result = failedServer; } } return result; }
/** * delete the master znode if its content is same as the parameter * @param zkw must not be null * @param content must not be null */ public static boolean deleteIfEquals(ZooKeeperWatcher zkw, final String content) { if (content == null){ throw new IllegalArgumentException("Content must not be null"); } try { Stat stat = new Stat(); byte[] data = ZKUtil.getDataNoWatch(zkw, zkw.getMasterAddressZNode(), stat); ServerName sn = ServerName.parseFrom(data); if (sn != null && content.equals(sn.toString())) { return (ZKUtil.deleteNode(zkw, zkw.getMasterAddressZNode(), stat.getVersion())); } } catch (KeeperException e) { LOG.warn("Can't get or delete the master znode", e); } catch (DeserializationException e) { LOG.warn("Can't get or delete the master znode", e); } return false; } }
/** * Return the {lastPushedSequenceId, ZNodeDataVersion} pair. if ZNodeDataVersion is -1, it means * that the ZNode does not exist. */ @VisibleForTesting protected Pair<Long, Integer> getLastSequenceIdWithVersion(String encodedRegionName, String peerId) throws KeeperException { Stat stat = new Stat(); String path = getSerialReplicationRegionPeerNode(encodedRegionName, peerId); byte[] data = ZKUtil.getDataNoWatch(zookeeper, path, stat); if (data == null) { // ZNode does not exist, so just return version -1 to indicate that no node exist. return Pair.newPair(HConstants.NO_SEQNUM, -1); } try { return Pair.newPair(ZKUtil.parseWALPositionFrom(data), stat.getVersion()); } catch (DeserializationException de) { LOG.warn("Failed to parse log position (region=" + encodedRegionName + ", peerId=" + peerId + "), data=" + Bytes.toStringBinary(data)); } return Pair.newPair(HConstants.NO_SEQNUM, stat.getVersion()); }
/** * Create a bunch of znodes in a hierarchy, try deleting one that has childs (it will fail), then * delete it recursively, then delete the last znode */ @Test public void testZNodeDeletes() throws Exception { ZKUtil.createWithParents(ZKW, "/l1/l2/l3/l4"); try { ZKUtil.deleteNode(ZKW, "/l1/l2"); fail("We should not be able to delete if znode has childs"); } catch (KeeperException ex) { assertNotNull(ZKUtil.getDataNoWatch(ZKW, "/l1/l2/l3/l4", null)); } ZKUtil.deleteNodeRecursively(ZKW, "/l1/l2"); // make sure it really is deleted assertNull(ZKUtil.getDataNoWatch(ZKW, "/l1/l2/l3/l4", null)); // do the same delete again and make sure it doesn't crash ZKUtil.deleteNodeRecursively(ZKW, "/l1/l2"); ZKUtil.deleteNode(ZKW, "/l1"); assertNull(ZKUtil.getDataNoWatch(ZKW, "/l1/l2", null)); }
/** * Create a bunch of znodes in a hierarchy, try deleting one that has childs (it will fail), then * delete it recursively, then delete the last znode */ @Test public void testZNodeDeletes() throws Exception { ZKUtil.createWithParents(ZKW, "/l1/l2/l3/l4"); try { ZKUtil.deleteNode(ZKW, "/l1/l2"); fail("We should not be able to delete if znode has childs"); } catch (KeeperException ex) { assertNotNull(ZKUtil.getDataNoWatch(ZKW, "/l1/l2/l3/l4", null)); } ZKUtil.deleteNodeRecursively(ZKW, "/l1/l2"); // make sure it really is deleted assertNull(ZKUtil.getDataNoWatch(ZKW, "/l1/l2/l3/l4", null)); // do the same delete again and make sure it doesn't crash ZKUtil.deleteNodeRecursively(ZKW, "/l1/l2"); ZKUtil.deleteNode(ZKW, "/l1"); assertNull(ZKUtil.getDataNoWatch(ZKW, "/l1/l2", null)); }