/** * 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(); } }
/** * this method gets the count of nodes and the bytes under a subtree * * @param path the path to be used * @param bytes the long bytes * @param count the int count */ private void getCounts(String path, Counts counts) { DataNode node = getNode(path); if (node == null) { return; } String[] children = null; synchronized (node) { children = node.children.toArray(new String[node.children.size()]); } // add itself counts.count += 1; counts.bytes += (long) node.data.length; if (children.length == 0) { return; } for (String child : children) { getCounts(path + "/" + child, counts); } }