Search in sources :

Example 11 with DataNode

use of org.apache.zookeeper_voltpatches.server.DataNode in project voltdb by VoltDB.

the class DataTree method traverseNode.

/**
     * this method traverses the quota path and update the path trie and sets
     *
     * @param path
     */
private void traverseNode(String path) {
    DataNode node = getNode(path);
    String[] children = null;
    synchronized (node) {
        Set<String> childs = node.getChildren();
        if (childs != null) {
            children = childs.toArray(new String[childs.size()]);
        }
    }
    if (children != null) {
        if (children.length == 0) {
            // this node does not have a child
            // is the leaf node
            // check if its the leaf node
            String endString = "/" + Quotas.limitNode;
            if (path.endsWith(endString)) {
                // ok this is the limit node
                // get the real node and update
                // the count and the bytes
                String realPath = path.substring(Quotas.quotaZookeeper.length(), path.indexOf(endString));
                updateQuotaForPath(realPath);
                this.pTrie.addPath(realPath);
            }
            return;
        }
        for (String child : children) {
            traverseNode(path + "/" + child);
        }
    }
}
Also used : DataNode(org.apache.zookeeper_voltpatches.server.DataNode)

Example 12 with DataNode

use of org.apache.zookeeper_voltpatches.server.DataNode in project voltdb by VoltDB.

the class DataTree method updateQuotaForPath.

/**
     * 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();
    }
}
Also used : StatsTrack(org.apache.zookeeper_voltpatches.StatsTrack) DataNode(org.apache.zookeeper_voltpatches.server.DataNode)

Example 13 with DataNode

use of org.apache.zookeeper_voltpatches.server.DataNode in project voltdb by VoltDB.

the class DataTree method approximateDataSize.

/**
     * Get the size of the nodes based on path and data length.
     *
     * @return size of the data
     */
public long approximateDataSize() {
    long result = 0;
    for (Map.Entry<String, DataNode> entry : nodes.entrySet()) {
        DataNode value = entry.getValue();
        synchronized (value) {
            result += entry.getKey().length();
            result += (value.data == null ? 0 : value.data.length);
        }
    }
    return result;
}
Also used : DataNode(org.apache.zookeeper_voltpatches.server.DataNode) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 14 with DataNode

use of org.apache.zookeeper_voltpatches.server.DataNode in project voltdb by VoltDB.

the class DataTree method updateCount.

/**
     * update the count of this stat datanode
     *
     * @param lastPrefix
     *            the path of the node that is quotaed.
     * @param diff
     *            the diff to be added to the count
     */
public void updateCount(String lastPrefix, int diff) {
    String statNode = Quotas.statPath(lastPrefix);
    DataNode node = nodes.get(statNode);
    StatsTrack updatedStat = null;
    if (node == null) {
        // should not happen
        LOG.error("Missing count node for stat " + statNode);
        return;
    }
    synchronized (node) {
        updatedStat = new StatsTrack(new String(node.data));
        updatedStat.setCount(updatedStat.getCount() + diff);
        node.data = updatedStat.toString().getBytes();
    }
    // now check if the counts match the quota
    String quotaNode = Quotas.quotaPath(lastPrefix);
    node = nodes.get(quotaNode);
    StatsTrack thisStats = null;
    if (node == null) {
        // should not happen
        LOG.error("Missing count node for quota " + quotaNode);
        return;
    }
    synchronized (node) {
        thisStats = new StatsTrack(new String(node.data));
    }
    if (thisStats.getCount() < updatedStat.getCount()) {
        LOG.warn("Quota exceeded: " + lastPrefix + " count=" + updatedStat.getCount() + " limit=" + thisStats.getCount());
    }
}
Also used : StatsTrack(org.apache.zookeeper_voltpatches.StatsTrack) DataNode(org.apache.zookeeper_voltpatches.server.DataNode)

Example 15 with DataNode

use of org.apache.zookeeper_voltpatches.server.DataNode in project voltdb by VoltDB.

the class DataTree method deserialize.

public void deserialize(InputArchive ia, String tag) throws IOException {
    deserializeList(longKeyMap, ia);
    nodes.clear();
    String path = ia.readString("path");
    while (!path.equals("/")) {
        DataNode node = new DataNode();
        ia.readRecord(node, "node");
        nodes.put(path, node);
        int lastSlash = path.lastIndexOf('/');
        if (lastSlash == -1) {
            root = node;
        } else {
            String parentPath = path.substring(0, lastSlash);
            node.parent = nodes.get(parentPath);
            if (node.parent == null) {
                throw new IOException("Invalid Datatree, unable to find " + "parent " + parentPath + " of path " + path);
            }
            node.parent.addChild(path.substring(lastSlash + 1));
            long eowner = node.stat.getEphemeralOwner();
            if (eowner != 0) {
                HashSet<String> list = ephemerals.get(eowner);
                if (list == null) {
                    list = new HashSet<String>();
                    ephemerals.put(eowner, list);
                }
                list.add(path);
            }
        }
        path = ia.readString("path");
    }
    nodes.put("/", root);
    // we are done with deserializing the
    // the datatree
    // update the quotas - create path trie
    // and also update the stat nodes
    setupQuota();
}
Also used : DataNode(org.apache.zookeeper_voltpatches.server.DataNode) IOException(java.io.IOException)

Aggregations

DataNode (org.apache.zookeeper_voltpatches.server.DataNode)16 NoNodeException (org.apache.zookeeper_voltpatches.KeeperException.NoNodeException)6 StatsTrack (org.apache.zookeeper_voltpatches.StatsTrack)3 Stat (org.apache.zookeeper_voltpatches.data.Stat)3 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 WatchedEvent (org.apache.zookeeper_voltpatches.WatchedEvent)1 Watcher (org.apache.zookeeper_voltpatches.Watcher)1 StatPersisted (org.apache.zookeeper_voltpatches.data.StatPersisted)1