Search in sources :

Example 6 with DataNode

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

the class DataTree method setupQuota.

/**
     * this method sets up the path trie and sets up stats for quota nodes
     */
private void setupQuota() {
    String quotaPath = Quotas.quotaZookeeper;
    DataNode node = getNode(quotaPath);
    if (node == null) {
        return;
    }
    traverseNode(quotaPath);
}
Also used : DataNode(org.apache.zookeeper_voltpatches.server.DataNode)

Example 7 with DataNode

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

the class DataTree method createNode.

/**
     * @param path
     * @param data
     * @param acl
     * @param ephemeralOwner
     *            the session id that owns this node. -1 indicates this is not
     *            an ephemeral node.
     * @param zxid
     * @param time
     * @return the patch of the created node
     * @throws KeeperException
     */
public String createNode(String path, byte[] data, List<ACL> acl, long ephemeralOwner, long zxid, long time) throws KeeperException.NoNodeException, KeeperException.NodeExistsException {
    int lastSlash = path.lastIndexOf('/');
    String parentName = path.substring(0, lastSlash);
    String childName = path.substring(lastSlash + 1);
    StatPersisted stat = new StatPersisted();
    stat.setCtime(time);
    stat.setMtime(time);
    stat.setCzxid(zxid);
    stat.setMzxid(zxid);
    stat.setPzxid(zxid);
    stat.setVersion(0);
    stat.setAversion(0);
    stat.setEphemeralOwner(ephemeralOwner);
    DataNode parent = nodes.get(parentName);
    if (parent == null) {
        throw new KeeperException.NoNodeException();
    }
    synchronized (parent) {
        Set<String> children = parent.getChildren();
        if (children != null) {
            if (children.contains(childName)) {
                throw new KeeperException.NodeExistsException();
            }
        }
        int cver = parent.stat.getCversion();
        cver++;
        parent.stat.setCversion(cver);
        parent.stat.setPzxid(zxid);
        Long longval = convertAcls(acl);
        DataNode child = new DataNode(parent, data, longval, stat);
        parent.addChild(childName);
        nodes.put(path, child);
        if (ephemeralOwner != 0) {
            HashSet<String> list = ephemerals.get(ephemeralOwner);
            if (list == null) {
                list = new HashSet<String>();
                ephemerals.put(ephemeralOwner, list);
            }
            synchronized (list) {
                list.add(path);
            }
        }
    }
    // now check if its one of the zookeeper node child
    if (parentName.startsWith(quotaZookeeper)) {
        // now check if its the limit node
        if (Quotas.limitNode.equals(childName)) {
            // this is the limit node
            // get the parent and add it to the trie
            pTrie.addPath(parentName.substring(quotaZookeeper.length()));
        }
        if (Quotas.statNode.equals(childName)) {
            updateQuotaForPath(parentName.substring(quotaZookeeper.length()));
        }
    }
    // also check to update the quotas for this node
    String lastPrefix = pTrie.findMaxPrefix(path);
    if (!rootZookeeper.equals(lastPrefix) && !("".equals(lastPrefix))) {
        // ok we have some match and need to update
        updateCount(lastPrefix, 1);
        updateBytes(lastPrefix, data == null ? 0 : data.length);
    }
    dataWatches.triggerWatch(path, Event.EventType.NodeCreated);
    childWatches.triggerWatch(parentName.equals("") ? "/" : parentName, Event.EventType.NodeChildrenChanged);
    return path;
}
Also used : NoNodeException(org.apache.zookeeper_voltpatches.KeeperException.NoNodeException) DataNode(org.apache.zookeeper_voltpatches.server.DataNode) StatPersisted(org.apache.zookeeper_voltpatches.data.StatPersisted)

Example 8 with DataNode

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

the class DataTree method setACL.

public Stat setACL(String path, List<ACL> acl, int version) throws KeeperException.NoNodeException {
    Stat stat = new Stat();
    DataNode n = nodes.get(path);
    if (n == null) {
        throw new KeeperException.NoNodeException();
    }
    synchronized (n) {
        n.stat.setAversion(version);
        n.acl = convertAcls(acl);
        n.copyStat(stat);
        return stat;
    }
}
Also used : Stat(org.apache.zookeeper_voltpatches.data.Stat) NoNodeException(org.apache.zookeeper_voltpatches.KeeperException.NoNodeException) DataNode(org.apache.zookeeper_voltpatches.server.DataNode)

Example 9 with DataNode

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

the class DataTree method setWatches.

public void setWatches(long relativeZxid, List<String> dataWatches, List<String> existWatches, List<String> childWatches, Watcher watcher) {
    for (String path : dataWatches) {
        DataNode node = getNode(path);
        WatchedEvent e = null;
        if (node == null) {
            e = new WatchedEvent(EventType.NodeDeleted, KeeperState.SyncConnected, path);
        } else if (node.stat.getCzxid() > relativeZxid) {
            e = new WatchedEvent(EventType.NodeCreated, KeeperState.SyncConnected, path);
        } else if (node.stat.getMzxid() > relativeZxid) {
            e = new WatchedEvent(EventType.NodeDataChanged, KeeperState.SyncConnected, path);
        }
        if (e != null) {
            watcher.process(e);
        } else {
            this.dataWatches.addWatch(path, watcher);
        }
    }
    for (String path : existWatches) {
        DataNode node = getNode(path);
        WatchedEvent e = null;
        if (node == null) {
        // This is the case when the watch was registered
        } else if (node.stat.getMzxid() > relativeZxid) {
            e = new WatchedEvent(EventType.NodeDataChanged, KeeperState.SyncConnected, path);
        } else {
            e = new WatchedEvent(EventType.NodeCreated, KeeperState.SyncConnected, path);
        }
        if (e != null) {
            watcher.process(e);
        } else {
            this.dataWatches.addWatch(path, watcher);
        }
    }
    for (String path : childWatches) {
        DataNode node = getNode(path);
        WatchedEvent e = null;
        if (node == null) {
            e = new WatchedEvent(EventType.NodeDeleted, KeeperState.SyncConnected, path);
        } else if (node.stat.getPzxid() > relativeZxid) {
            e = new WatchedEvent(EventType.NodeChildrenChanged, KeeperState.SyncConnected, path);
        }
        if (e != null) {
            watcher.process(e);
        } else {
            this.childWatches.addWatch(path, watcher);
        }
    }
}
Also used : WatchedEvent(org.apache.zookeeper_voltpatches.WatchedEvent) DataNode(org.apache.zookeeper_voltpatches.server.DataNode)

Example 10 with DataNode

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

the class DataTree method setData.

public Stat setData(String path, byte[] data, int version, long zxid, long time) throws KeeperException.NoNodeException {
    Stat s = new Stat();
    DataNode n = nodes.get(path);
    if (n == null) {
        throw new KeeperException.NoNodeException();
    }
    byte[] lastdata = null;
    synchronized (n) {
        lastdata = n.data;
        n.data = data;
        n.stat.setMtime(time);
        n.stat.setMzxid(zxid);
        n.stat.setVersion(version);
        n.copyStat(s);
    }
    // now update if the path is in a quota subtree.
    String lastPrefix = pTrie.findMaxPrefix(path);
    // root node for now.
    if (!rootZookeeper.equals(lastPrefix) && !("".equals(lastPrefix))) {
        this.updateBytes(lastPrefix, (data == null ? 0 : data.length) - (lastdata == null ? 0 : lastdata.length));
    }
    dataWatches.triggerWatch(path, EventType.NodeDataChanged);
    return s;
}
Also used : Stat(org.apache.zookeeper_voltpatches.data.Stat) NoNodeException(org.apache.zookeeper_voltpatches.KeeperException.NoNodeException) DataNode(org.apache.zookeeper_voltpatches.server.DataNode)

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