溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

zk中的節(jié)點(diǎn)配額,配額管理樹和狀態(tài)信息分別是什么

發(fā)布時(shí)間:2021-06-23 10:20:25 來源:億速云 閱讀:198 作者:chen 欄目:大數(shù)據(jù)

本篇內(nèi)容介紹了“zk中的節(jié)點(diǎn)配額,配額管理樹和狀態(tài)信息分別是什么”的有關(guān)知識(shí),在實(shí)際案例的操作過程中,不少人都會(huì)遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!

Qutas 主要完成配額目錄的定義:

限制信息包含某個(gè)路徑的要求大小

在zk中目錄結(jié)構(gòu)為/zookeeper/quota/xxx/zookeeper_limits

狀態(tài)信息包含對(duì)某個(gè)路徑實(shí)際大小

/zookeeper/quota/xxx/zookeeper_stats

以及提供path轉(zhuǎn)換對(duì)應(yīng)的限制path和狀態(tài)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
    字典樹完成配額目錄的增刪查
   路徑查找
內(nèi)部類
TrieNode
屬性
final String value;
final Map<String, TrieNode> children;
boolean property;//節(jié)點(diǎn)設(shè)置了配額,屬性為true,否則為false
TrieNode parent;

方法
//添加子節(jié)點(diǎn)
void addChild(String childName, TrieNode node) {
    this.children.putIfAbsent(childName, node);
}


/**
 * Delete child from this node.
 *刪除子節(jié)點(diǎn)
 * @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;
    });
}



 

構(gòu)造方法:
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
 記錄節(jié)點(diǎn)實(shí)際的count和bytes長(zhǎng)度信息

屬性
private int count;
private long bytes;
private String countStr = "count";
private String byteStr = "bytes";

 public String toString() {
    return countStr + "=" + count + "," + byteStr + "=" + bytes;
}

“zk中的節(jié)點(diǎn)配額,配額管理樹和狀態(tài)信息分別是什么”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí)可以關(guān)注億速云網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

zk
AI