温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

zk中的节点配额,配额管理树和状态信息分别是什么

发布时间:2021-06-23 10:20:25 来源:亿速云 阅读:242 作者:chen 栏目:大数据

本篇内容介绍了“zk中的节点配额,配额管理树和状态信息分别是什么”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

Qutas 主要完成配额目录的定义:

限制信息包含某个路径的要求大小

在zk中目录结构为/zookeeper/quota/xxx/zookeeper_limits

状态信息包含对某个路径实际大小

/zookeeper/quota/xxx/zookeeper_stats

以及提供path转换对应的限制path和状态path方法

为处理配额提供定义

Quotas类路径org.apache.zookeeper

属性

/** 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"; 方法 /**  * 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     字典树完成配额目录的增删查    路径查找 内部类 TrieNode 属性 final String value; final Map<String, TrieNode> children; boolean property;//节点设置了配额,属性为true,否则为false TrieNode parent; 方法 //添加子节点 void addChild(String childName, TrieNode node) {     this.children.putIfAbsent(childName, node); } /**  * Delete child from this node.  *删除子节点  * @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;     }); }   构造方法: public PathTrie() {     this.rootNode = new TrieNode(null, "/"); } 方法 /**  * 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  记录节点实际的count和bytes长度信息 属性 private int count; private long bytes; private String countStr = "count"; private String byteStr = "bytes";  public String toString() {     return countStr + "=" + count + "," + byteStr + "=" + bytes; }

“zk中的节点配额,配额管理树和状态信息分别是什么”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

zk
AI