use of org.apache.zookeeper.StatsTrack in project zookeeper by apache.
the class DelQuotaCommand method exec.
@Override
public boolean exec() throws CliException {
String path = args[1];
// Use a StatsTrack object to pass in to delQuota which quotas
// to delete by setting them to 1 as a flag.
StatsTrack quota = new StatsTrack();
if (cl.hasOption("n")) {
quota.setCount(1);
}
if (cl.hasOption("b")) {
quota.setBytes(1);
}
if (cl.hasOption("N")) {
quota.setCountHardLimit(1);
}
if (cl.hasOption("B")) {
quota.setByteHardLimit(1);
}
boolean flagSet = (cl.hasOption("n") || cl.hasOption("N") || cl.hasOption("b") || cl.hasOption("B"));
try {
delQuota(zk, path, flagSet ? quota : null);
} catch (IllegalArgumentException ex) {
throw new MalformedPathException(ex.getMessage());
} catch (KeeperException.NoNodeException ne) {
err.println("quota for " + path + " does not exist.");
} catch (KeeperException | InterruptedException ex) {
throw new CliWrapperException(ex);
}
return false;
}
use of org.apache.zookeeper.StatsTrack in project zookeeper by apache.
the class QuotaMetricsUtilsTest method buildLimitStatsTrack.
private StatsTrack buildLimitStatsTrack(final long countLimit, final long bytesLimit, final long countHardLimit, final long bytesHardLimit) {
final StatsTrack limitTrack = new StatsTrack();
limitTrack.setCount(countLimit);
limitTrack.setBytes(bytesLimit);
limitTrack.setCountHardLimit(countHardLimit);
limitTrack.setByteHardLimit(bytesHardLimit);
return limitTrack;
}
use of org.apache.zookeeper.StatsTrack in project zookeeper by apache.
the class QuotaMetricsUtilsTest method buildDataTree.
private void buildDataTree(final String path, final StatsTrack limitTrack, final StatsTrack usageTrack, final DataTree dataTree) throws Exception {
// create the ancestor and child data nodes
buildAncestors(path, dataTree);
// the node count always includes the top namespace itself
int childCount = (int) usageTrack.getCount() - 1;
if (childCount > 0) {
int dataBytes = (int) usageTrack.getBytes() / childCount;
for (int i = 0; i < childCount; i++) {
dataTree.createNode(path + "/n_" + i, new byte[dataBytes], null, -1, 1, 1, 1);
}
}
// create the quota tree
buildAncestors(Quotas.quotaPath(path), dataTree);
final String limitPath = Quotas.limitPath(path);
dataTree.createNode(limitPath, limitTrack.getStatsBytes(), null, -1, 1, 1, 1);
assertEquals(limitTrack, new StatsTrack(dataTree.getNode(limitPath).getData()));
final String usagePath = Quotas.statPath(path);
dataTree.createNode(usagePath, usageTrack.getStatsBytes(), null, -1, 1, 1, 1);
assertEquals(usageTrack, new StatsTrack(dataTree.getNode(usagePath).getData()));
}
use of org.apache.zookeeper.StatsTrack in project zookeeper by apache.
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() > -1 && (thisStats.getBytes() < updatedStat.getBytes())) {
LOG.warn("Quota exceeded: " + lastPrefix + " bytes=" + updatedStat.getBytes() + " limit=" + thisStats.getBytes());
}
}
use of org.apache.zookeeper.StatsTrack in project zookeeper by apache.
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() > -1 && (thisStats.getCount() < updatedStat.getCount())) {
LOG.warn("Quota exceeded: " + lastPrefix + " count=" + updatedStat.getCount() + " limit=" + thisStats.getCount());
}
}
Aggregations