@Test public void testCachedApproximateDataSize() throws Exception { DataTree dt = new DataTree(); long initialSize = dt.approximateDataSize(); Assert.assertEquals(dt.cachedApproximateDataSize(), dt.approximateDataSize()); // create a node dt.createNode("/testApproximateDataSize", new byte[20], null, -1, 1, 1, 1); dt.createNode("/testApproximateDataSize1", new byte[20], null, -1, 1, 1, 1); Assert.assertEquals(dt.cachedApproximateDataSize(), dt.approximateDataSize()); // update data dt.setData("/testApproximateDataSize1", new byte[32], -1, 1, 1); Assert.assertEquals(dt.cachedApproximateDataSize(), dt.approximateDataSize()); // delete a node dt.deleteNode("/testApproximateDataSize", -1); Assert.assertEquals(dt.cachedApproximateDataSize(), dt.approximateDataSize()); } }
public int getWatchCount() { return dataTree.getWatchCount(); }
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); } }
/** * 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); }
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"); } }
/** * 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); } }
@Test(timeout = 60000) public void testReconfigACLClearOnDeserialize() throws Exception { DataTree tree = new DataTree(); tree.deleteNode(ZooDefs.CONFIG_NODE, 1); tree.getReferenceCountedAclCache().aclIndex = 0; "expected to have 1 acl in acl cache map", 0, tree.aclCacheSize()); tree.createNode( "/bug", new byte[20], ZooDefs.Ids.OPEN_ACL_UNSAFE, -1, 1, 1, 1); tree.serialize(oa, "test"); baos.flush(); tree.deserialize(ia, "test"); "expected to have 1 acl in acl cache map", 1, tree.aclCacheSize()); Assert.assertEquals( "expected to have the same acl", ZooDefs.Ids.OPEN_ACL_UNSAFE, tree.getACL("/bug", new Stat())); tree.addConfigNode(); "expected to have 2 acl in acl cache map", 2, tree.aclCacheSize()); Assert.assertEquals( "expected to have the same acl", ZooDefs.Ids.OPEN_ACL_UNSAFE, tree.getACL("/bug", new Stat()));
CreateTxn createTxn = (CreateTxn) txn; rc.path = createTxn.getPath(); createNode( createTxn.getPath(), createTxn.getData(), rc.path = create2Txn.getPath(); Stat stat = new Stat(); createNode( create2Txn.getPath(), create2Txn.getData(), rc.path = createTtlTxn.getPath(); stat = new Stat(); createNode( createTtlTxn.getPath(), createTtlTxn.getData(), rc.path = createContainerTxn.getPath(); stat = new Stat(); createNode( createContainerTxn.getPath(), createContainerTxn.getData(), DeleteTxn deleteTxn = (DeleteTxn) txn; rc.path = deleteTxn.getPath(); deleteNode(deleteTxn.getPath(), header.getZxid()); break; case OpCode.reconfig:
DataTree.copyStat(response.getStat(), stat);
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); }
print("znode_count", zkdb.getNodeCount()); print("watch_count", zkdb.getDataTree().getWatchCount()); print("ephemerals_count", zkdb.getDataTree().getEphemeralsCount()); print("approximate_data_size", zkdb.getDataTree().approximateDataSize());
@Test(timeout = 60000) public void testSerializeDoesntLockDataNodeWhileWriting() throws Exception { DataTree tree = new DataTree(); tree.createNode("/marker", new byte[] {42}, null, -1, 1, 1, 1); final DataNode markerNode = tree.getNode("/marker"); final AtomicBoolean ranTestCase = new AtomicBoolean(); DataOutputStream out = new DataOutputStream(new ByteArrayOutputStream()); tree.serialize(oa, "test");
@Test(timeout = 60000) public void testPathTrieClearOnDeserialize() throws Exception { //Create a DataTree with quota nodes so PathTrie get updated DataTree dserTree = new DataTree(); dserTree.createNode("/bug", new byte[20], null, -1, 1, 1, 1); dserTree.createNode(Quotas.quotaZookeeper+"/bug", null, null, -1, 1, 1, 1); dserTree.createNode(Quotas.quotaPath("/bug"), new byte[20], null, -1, 1, 1, 1); dserTree.createNode(Quotas.statPath("/bug"), new byte[20], null, -1, 1, 1, 1); //deserialize a DataTree; this should clear the old /bug nodes and pathTrie DataTree tree = new DataTree(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); BinaryOutputArchive oa = BinaryOutputArchive.getArchive(baos); tree.serialize(oa, "test"); baos.flush(); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); BinaryInputArchive ia = BinaryInputArchive.getArchive(bais); dserTree.deserialize(ia, "test"); Field pfield = DataTree.class.getDeclaredField("pTrie"); pfield.setAccessible(true); PathTrie pTrie = (PathTrie)pfield.get(dserTree); //Check that the node path is removed from pTrie Assert.assertEquals("/bug is still in pTrie", "", pTrie.findMaxPrefix("/bug")); }
CreateTxn createTxn = (CreateTxn) txn; debug = "Create transaction for " + createTxn.getPath(); createNode( createTxn.getPath(), createTxn.getData(), DeleteTxn deleteTxn = (DeleteTxn) txn; debug = "Delete transaction for " + deleteTxn.getPath(); deleteNode(deleteTxn.getPath(), header.getZxid()); break; case OpCode.setData: debug = "Set data for transaction for " + setDataTxn.getPath(); rc.stat = setData(setDataTxn.getPath(), setDataTxn .getData(), setDataTxn.getVersion(), header .getZxid(), header.getTime()); debug = "Set ACL for transaction for " + setACLTxn.getPath(); rc.stat = setACL(setACLTxn.getPath(), setACLTxn.getAcl(), setACLTxn.getVersion()); break; case OpCode.closeSession: killSession(header.getClientId(), header.getZxid()); break; case OpCode.error:
public DataTree createDataTree() { return new DataTree(); } }
print("znode_count", zkdb.getNodeCount()); print("watch_count", zkdb.getDataTree().getWatchCount()); print("ephemerals_count", zkdb.getDataTree().getEphemeralsCount()); print("approximate_data_size", zkdb.getDataTree().cachedApproximateDataSize());
@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); }
File tmpDir = ClientBase.createTmpDir(); FileTxnSnapLog logFile = new FileTxnSnapLog(tmpDir, tmpDir); DataTree dt = new DataTree(); dt.createNode("/test", new byte[0], null, 0, -1, 1, 1); for (count = 1; count <= 3; count++) { dt.createNode("/test/" + count, new byte[0], null, 0, -1, count, Time.currentElapsedTime()); DataNode zk = dt.getNode("/test");
DataNode node = getNode(path); String children[] = null; synchronized (node) { updateQuotaForPath(realPath); this.pTrie.addPath(realPath); traverseNode(path + "/" + child);
/** * 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)); }