use of org.apache.zookeeper_voltpatches.server.DataNode in project voltdb by VoltDB.
the class DataTree method updateBytes.
/**
* update the count of bytes of this stat datanode
*
* @param lastPrefix
* the path of the node that is quotaed
* @param diff
* the diff to added to number of bytes
* @throws IOException
* if path is not found
*/
public void updateBytes(String lastPrefix, long diff) {
String statNode = Quotas.statPath(lastPrefix);
DataNode node = nodes.get(statNode);
if (node == null) {
// should never be null but just to make
// findbugs happy
LOG.error("Missing stat node for bytes " + statNode);
return;
}
StatsTrack updatedStat = null;
synchronized (node) {
updatedStat = new StatsTrack(new String(node.data));
updatedStat.setBytes(updatedStat.getBytes() + diff);
node.data = updatedStat.toString().getBytes();
}
// now check if the bytes match the quota
String quotaNode = Quotas.quotaPath(lastPrefix);
node = nodes.get(quotaNode);
if (node == null) {
// should never be null but just to make
// findbugs happy
LOG.error("Missing quota node for bytes " + quotaNode);
return;
}
StatsTrack thisStats = null;
synchronized (node) {
thisStats = new StatsTrack(new String(node.data));
}
if (thisStats.getBytes() < updatedStat.getBytes()) {
LOG.warn("Quota exceeded: " + lastPrefix + " bytes=" + updatedStat.getBytes() + " limit=" + thisStats.getBytes());
}
}
use of org.apache.zookeeper_voltpatches.server.DataNode in project voltdb by VoltDB.
the class DataTree method deleteNode.
/**
* remove the path from the datatree
*
* @param path
* the path to of the node to be deleted
* @param zxid
* the current zxid
* @throws KeeperException.NoNodeException
*/
public void deleteNode(String path, long zxid) throws KeeperException.NoNodeException {
int lastSlash = path.lastIndexOf('/');
String parentName = path.substring(0, lastSlash);
String childName = path.substring(lastSlash + 1);
DataNode node = nodes.get(path);
if (node == null) {
throw new KeeperException.NoNodeException();
}
nodes.remove(path);
DataNode parent = nodes.get(parentName);
if (parent == null) {
throw new KeeperException.NoNodeException();
}
synchronized (parent) {
parent.removeChild(childName);
parent.stat.setCversion(parent.stat.getCversion() + 1);
parent.stat.setPzxid(zxid);
long eowner = node.stat.getEphemeralOwner();
if (eowner != 0) {
HashSet<String> nodes = ephemerals.get(eowner);
if (nodes != null) {
synchronized (nodes) {
nodes.remove(path);
}
}
}
node.parent = null;
}
if (parentName.startsWith(procZookeeper)) {
// delete the node in the trie.
if (Quotas.limitNode.equals(childName)) {
// we need to update the trie
// as well
pTrie.deletePath(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);
int bytes = 0;
synchronized (node) {
bytes = (node.data == null ? 0 : -(node.data.length));
}
updateBytes(lastPrefix, bytes);
}
if (LOG.isTraceEnabled()) {
ZooTrace.logTraceMessage(LOG, ZooTrace.EVENT_DELIVERY_TRACE_MASK, "dataWatches.triggerWatch " + path);
ZooTrace.logTraceMessage(LOG, ZooTrace.EVENT_DELIVERY_TRACE_MASK, "childWatches.triggerWatch " + parentName);
}
Set<Watcher> processed = dataWatches.triggerWatch(path, EventType.NodeDeleted);
childWatches.triggerWatch(path, EventType.NodeDeleted, processed);
childWatches.triggerWatch(parentName.equals("") ? "/" : parentName, EventType.NodeChildrenChanged);
}
use of org.apache.zookeeper_voltpatches.server.DataNode in project voltdb by VoltDB.
the class DataTree method getChildren.
public List<String> getChildren(String path, Stat stat, Watcher watcher) throws KeeperException.NoNodeException {
DataNode n = nodes.get(path);
if (n == null) {
throw new KeeperException.NoNodeException();
}
synchronized (n) {
if (stat != null) {
n.copyStat(stat);
}
ArrayList<String> children;
Set<String> childs = n.getChildren();
if (childs != null) {
children = new ArrayList<String>(childs.size());
children.addAll(childs);
} else {
children = new ArrayList<String>(0);
}
if (watcher != null) {
childWatches.addWatch(path, watcher);
}
return children;
}
}
use of org.apache.zookeeper_voltpatches.server.DataNode in project voltdb by VoltDB.
the class DataTree method statNode.
public Stat statNode(String path, Watcher watcher) throws KeeperException.NoNodeException {
Stat stat = new Stat();
DataNode n = nodes.get(path);
if (watcher != null) {
dataWatches.addWatch(path, watcher);
}
if (n == null) {
throw new KeeperException.NoNodeException();
}
synchronized (n) {
n.copyStat(stat);
return stat;
}
}
use of org.apache.zookeeper_voltpatches.server.DataNode in project voltdb by VoltDB.
the class DataTree method getCounts.
/**
* this method gets the count of nodes and the bytes under a subtree
*
* @param path
* the path to be used
* @param bytes
* the long bytes
* @param count
* the int count
*/
private void getCounts(String path, Counts counts) {
DataNode node = getNode(path);
if (node == null) {
return;
}
String[] children = null;
int len = 0;
synchronized (node) {
Set<String> childs = node.getChildren();
if (childs != null) {
children = childs.toArray(new String[childs.size()]);
}
len = (node.data == null ? 0 : node.data.length);
}
// add itself
counts.count += 1;
counts.bytes += len;
if (children == null || children.length == 0) {
return;
}
for (String child : children) {
getCounts(path + "/" + child, counts);
}
}
Aggregations