/** * get the datanode for this path * @param path the path to lookup * @return the datanode for getting the path */ public DataNode getNode(String path) { return dataTree.getNode(path); }
private static void serializeTree(int depth, int width, int len) throws InterruptedException, IOException, KeeperException.NodeExistsException, KeeperException.NoNodeException { DataTree tree = new DataTree(); createNodes(tree, "/", depth, width, tree.getNode("/").stat.getCversion(), new byte[len]); int count = tree.getNodeCount(); BinaryOutputArchive oa = BinaryOutputArchive.getArchive(new NullOutputStream()); System.gc(); long start = System.nanoTime(); tree.serialize(oa, "test"); long end = System.nanoTime(); long durationms = (end - start)/1000000L; long pernodeus = ((end - start)/1000L)/count; LOG.info("Serialized " + count + " nodes in " + durationms + " ms (" + pernodeus + "us/node), depth=" + depth + " width=" + width + " datalen=" + len); }
/** * get the datanode for this path * @param path the path to lookup * @return the datanode for getting the path */ public DataNode getNode(String path) { return dataTree.getNode(path); }
private static void deserializeTree(int depth, int width, int len) throws InterruptedException, IOException, KeeperException.NodeExistsException, KeeperException.NoNodeException { BinaryInputArchive ia; int count; { DataTree tree = new DataTree(); SerializationPerfTest.createNodes(tree, "/", depth, width, tree.getNode("/").stat.getCversion(), new byte[len]); count = tree.getNodeCount(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); BinaryOutputArchive oa = BinaryOutputArchive.getArchive(baos); tree.serialize(oa, "test"); baos.flush(); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); ia = BinaryInputArchive.getArchive(bais); } DataTree dserTree = new DataTree(); System.gc(); long start = System.nanoTime(); dserTree.deserialize(ia, "test"); long end = System.nanoTime(); long durationms = (end - start) / 1000000L; long pernodeus = ((end - start) / 1000L) / count; Assert.assertEquals(count, dserTree.getNodeCount()); LOG.info("Deserialized " + count + " nodes in " + durationms + " ms (" + pernodeus + "us/node), depth=" + depth + " width=" + width + " datalen=" + len); }
/** * this method sets up the path trie and sets up stats for quota nodes */ private void setupQuota() { String quotaPath = Quotas.quotaZookeeper; DataNode node = getNode(quotaPath); if (node == null) { return; } traverseNode(quotaPath); }
/** * this method sets up the path trie and sets up stats for quota nodes */ private void setupQuota() { String quotaPath = Quotas.quotaZookeeper; DataNode node = getNode(quotaPath); if (node == null) { return; } traverseNode(quotaPath); }
/** * this method gets the count of nodes and the bytes under a subtree * * @param path * the path to be used * @param counts * the int count */ private void getCounts(String path, Counts counts) { DataNode node = getNode(path); if (node == null) { return; } String[] children = null; int len = 0; synchronized (node) { Set<String> childs = node.getChildren(); children = childs.toArray(new String[childs.size()]); len = (node.data == null ? 0 : node.data.length); } // add itself counts.count += 1; counts.bytes += len; for (String child : children) { getCounts(path + "/" + child, counts); } }
public synchronized void initConfigInZKDatabase(QuorumVerifier qv) { if (qv == null) return; // only happens during tests try { if (this.dataTree.getNode(ZooDefs.CONFIG_NODE) == null) { // should only happen during upgrade LOG.warn("configuration znode missing (should only happen during upgrade), creating the node"); this.dataTree.addConfigNode(); } this.dataTree.setData(ZooDefs.CONFIG_NODE, qv.toString().getBytes(), -1, qv.getVersion(), Time.currentWallTime()); } catch (NoNodeException e) { System.out.println("configuration node missing - should not happen"); } }
private long printZnode(DataTree dataTree, String name, boolean dumpData) { System.out.println("----"); DataNode n = dataTree.getNode(name); Set<String> children; long zxid; synchronized (n) { // keep findbugs happy System.out.println(name); printStat(n.stat); zxid = Math.max(n.stat.getMzxid(), n.stat.getPzxid()); if (dumpData) { System.out.println(" data = " + (n.data == null ? "" : Base64.getEncoder().encodeToString(n.data))); } else { System.out.println(" dataLength = " + (n.data == null ? 0 : n.data.length)); } children = n.getChildren(); } if (children != null) { for (String child : children) { long cxid = printZnode( dataTree, name + (name.equals("/") ? "" : "/") + child, dumpData ); zxid = Math.max(zxid, cxid); } } return zxid; }
DataNode node = getNode(path); String children[] = null; synchronized (node) {
/** * update the quota for the given path * * @param path * the path to be used */ private void updateQuotaForPath(String path) { Counts c = new Counts(); getCounts(path, c); StatsTrack strack = new StatsTrack(); strack.setBytes(c.bytes); strack.setCount(c.count); String statPath = Quotas.quotaZookeeper + path + "/" + Quotas.statNode; DataNode node = getNode(statPath); // it should exist if (node == null) { LOG.warn("Missing quota stat node " + statPath); return; } synchronized (node) { node.data = strack.toString().getBytes(); } }
private void createEphemeralNode(long session, final DataTree dataTree, int count) throws NoNodeException, NodeExistsException { for (int i = 0; i < count; i++) { dataTree.createNode("/test" + i, new byte[0], null, session + i, dataTree.getNode("/").stat.getCversion() + 1, 1, 1); } }
protected Collection<String> getCandidates() { Set<String> candidates = new HashSet<String>(); for (String containerPath : zkDb.getDataTree().getContainers()) { DataNode node = zkDb.getDataTree().getNode(containerPath); DataNode node = zkDb.getDataTree().getNode(ttlPath); if (node != null) { Set<String> children = node.getChildren();
Watcher watcher) { for (String path : dataWatches) { DataNode node = getNode(path); WatchedEvent e = null; if (node == null) { DataNode node = getNode(path); if (node != null) { watcher.process(new WatchedEvent(EventType.NodeCreated, DataNode node = getNode(path); if (node == null) { watcher.process(new WatchedEvent(EventType.NodeDeleted,
@Test public void testPzxidUpdatedWhenDeletingNonExistNode() throws Exception { DataNode root = dt.getNode("/"); long currentPzxid = root.stat.getPzxid(); // pzxid updated with deleteNode on higher zxid long zxid = currentPzxid + 1; try { dt.deleteNode("/testPzxidUpdatedWhenDeletingNonExistNode", zxid); } catch (NoNodeException e) { /* expected */ } root = dt.getNode("/"); currentPzxid = root.stat.getPzxid(); Assert.assertEquals(currentPzxid, zxid); // pzxid not updated with smaller zxid long prevPzxid = currentPzxid; zxid = prevPzxid - 1; try { dt.deleteNode("/testPzxidUpdatedWhenDeletingNonExistNode", zxid); } catch (NoNodeException e) { /* expected */ } root = dt.getNode("/"); currentPzxid = root.stat.getPzxid(); Assert.assertEquals(currentPzxid, prevPzxid); }
@Test(timeout = 60000) public void testRootWatchTriggered() throws Exception { class MyWatcher implements Watcher{ boolean fired=false; public void process(WatchedEvent event) { if(event.getPath().equals("/")) fired=true; } } MyWatcher watcher=new MyWatcher(); // set a watch on the root node dt.getChildren("/", new Stat(), watcher); // add a new node, should trigger a watch dt.createNode("/xyz", new byte[0], null, 0, dt.getNode("/").stat.getCversion()+1, 1, 1); Assert.assertFalse("Root node watch not triggered",!watcher.fired); }
@Test public void testNoCversionRevert() throws Exception { DataNode parent = dt.getNode("/"); dt.createNode("/test", new byte[0], null, 0, parent.stat.getCversion() + 1, 1, 1); int currentCversion = parent.stat.getCversion(); long currentPzxid = parent.stat.getPzxid(); dt.createNode("/test1", new byte[0], null, 0, currentCversion - 1, 1, 1); parent = dt.getNode("/"); int newCversion = parent.stat.getCversion(); long newPzxid = parent.stat.getPzxid(); Assert.assertTrue("<cversion, pzxid> verification failed. Expected: <" + currentCversion + ", " + currentPzxid + ">, found: <" + newCversion + ", " + newPzxid + ">", (newCversion >= currentCversion && newPzxid >= currentPzxid)); }
/** * For ZOOKEEPER-1046 test if cversion is getting incremented correctly. */ @Test(timeout = 60000) public void testIncrementCversion() throws Exception { dt.createNode("/test", new byte[0], null, 0, dt.getNode("/").stat.getCversion()+1, 1, 1); DataNode zk = dt.getNode("/test"); int prevCversion = zk.stat.getCversion(); long prevPzxid = zk.stat.getPzxid(); dt.setCversionPzxid("/test/", prevCversion + 1, prevPzxid + 1); int newCversion = zk.stat.getCversion(); long newPzxid = zk.stat.getPzxid(); Assert.assertTrue("<cversion, pzxid> verification failed. Expected: <" + (prevCversion + 1) + ", " + (prevPzxid + 1) + ">, found: <" + newCversion + ", " + newPzxid + ">", (newCversion == prevCversion + 1 && newPzxid == prevPzxid + 1)); }
@Test public void test353TTL() throws KeeperException, InterruptedException { DataTree dataTree = serverFactory.zkServer.getZKDatabase().dataTree; long ephemeralOwner = EphemeralTypeEmulate353.ttlToEphemeralOwner(100); dataTree.createNode("/foo", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, ephemeralOwner, dataTree.getNode("/").stat.getCversion()+1, 1, 1); final AtomicLong fakeElapsed = new AtomicLong(0); ContainerManager containerManager = newContainerManager(fakeElapsed); containerManager.checkContainers(); Assert.assertNotNull("Ttl node should not have been deleted yet", zk.exists("/foo", false)); fakeElapsed.set(1000); containerManager.checkContainers(); Assert.assertNull("Ttl node should have been deleted", zk.exists("/foo", false)); }
Time.currentElapsedTime()); DataNode zk = dt.getNode("/test");