千家信息网

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

发表于:2025-01-23 作者:千家信息网编辑
千家信息网最后更新 2025年01月23日,本篇内容介绍了"zk中的节点配额,配额管理树和状态信息分别是什么"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够
千家信息网最后更新 2025年01月23日zk中的节点配额,配额管理树和状态信息分别是什么

本篇内容介绍了"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 children;boolean property;//节点设置了配额,属性为true,否则为falseTrieNode 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中的节点配额,配额管理树和状态信息分别是什么"的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注网站,小编将为大家输出更多高质量的实用文章!

0