Qutas mainly completes the definition of quota catalogue:
Restriction information contains the required size of a path
In zk, the directory structure is / zookeeper/quota/xxx/zookeeper_limits
State information contains the actual size of a path
/zookeeper/quota/xxx/zookeeper_stats
And provide the restricted path and state path methods corresponding to path transformation
Provide definitions for dealing with quotas
Quotas class path org.apache.zookeeper
attribute
/** the zookeeper nodes that acts as the management and status node **/ public static final String procZookeeper = "/zookeeper"; /** the zookeeper quota node that acts as the quota * management node for zookeeper */ public static final String quotaZookeeper = "/zookeeper/quota"; /** * the limit node that has the limit of * a subtree */ public static final String limitNode = "zookeeper_limits"; /** * the stat node that monitors the limit of * a subtree. */ public static final String statNode = "zookeeper_stats"; //Method /** * return the quota path associated with this * prefix * @param path the actual path in zookeeper. * @return the limit quota path */ public static String quotaPath(String path) { return quotaZookeeper + path + "/" + limitNode; } /** * return the stat quota path associated with this * prefix. * @param path the actual path in zookeeper * @return the stat quota path */ public static String statPath(String path) { return quotaZookeeper + path + "/" + statNode; }
PathTrie //Dictionary Tree Completes the Addendum and Delete of Quota Catalogue //Path finding //Inner class TrieNode //attribute final String value; final Map<String, TrieNode> children; boolean property;//The node sets a quota with the attribute true or false TrieNode parent; //Method //Add child nodes void addChild(String childName, TrieNode node) { this.children.putIfAbsent(childName, node); } /** * Delete child from this node. *Delete child nodes * @param childName the name of the child to be deleted */ void deleteChild(String childName) { this.children.computeIfPresent(childName, (key, childNode) -> { // Node no longer has an external property associated childNode.setProperty(false); // Delete it if it has no children (is a leaf node) if (childNode.isLeafNode()) { childNode.setParent(null); return null; } return childNode; }); } //Construction method: public PathTrie() { this.rootNode = new TrieNode(null, "/"); } //Method /** * Add a path to the path trie. All paths are relative to the root node. * * @param path the path to add to the trie */ public void addPath(final String path) { Objects.requireNonNull(path, "Path cannot be null"); final String[] pathComponents = StringUtils.split(path, '/'); if (pathComponents.length == 0) { throw new IllegalArgumentException("Invalid path: " + path); } writeLock.lock(); try { TrieNode parent = rootNode; for (final String part : pathComponents) { TrieNode child = parent.getChild(part); if (child == null) { child = new TrieNode(parent, part); parent.addChild(part, child); } parent = child; } parent.setProperty(true); } finally { writeLock.unlock(); } } /** * Return true if the given path exists in the trie, otherwise return false; * All paths are relative to the root node. * * @param path the input path * @return the largest prefix for the */ public boolean existsNode(final String path) { Objects.requireNonNull(path, "Path cannot be null"); final String[] pathComponents = StringUtils.split(path, '/'); if (pathComponents.length == 0) { throw new IllegalArgumentException("Invalid path: " + path); } readLock.lock(); try { TrieNode parent = rootNode; for (final String part : pathComponents) { if (parent.getChild(part) == null) { // the path does not exist return false; } parent = parent.getChild(part); LOG.debug("{}", parent); } } finally { readLock.unlock(); } return true; } StatsTrack //Record the actual count and bytes length information of the node //attribute private int count; private long bytes; private String countStr = "count"; private String byteStr = "bytes"; public String toString() { return countStr + "=" + count + "," + byteStr + "=" + bytes; }
Think: How are quotas recorded?
After modifying the node quota, will it affect the quota of other nodes?