ztzg commented on a change in pull request #934: ZOOKEEPER-3301:Enforce the
quota limit
URL: https://github.com/apache/zookeeper/pull/934#discussion_r357062883
##########
File path:
zookeeper-server/src/main/java/org/apache/zookeeper/server/PrepRequestProcessor.java
##########
@@ -286,6 +293,91 @@ void rollbackPendingChanges(long zxid, Map<String,
ChangeRecord>pendingChangeRec
}
}
+ /**
+ * check whether exceeded the quota.
+ *
+ * @param lastPrefix
+ * the path of the node that is quotaed.
+ * @param bytesDiff
+ * the diff to be added to number of bytes
+ * @param countDiff
+ * the diff to be added to the count
+ */
+ private void checkQuota(String lastPrefix, long bytesDiff, int countDiff)
+ throws KeeperException.QuotaExceededException {
+ if (!enforeQuota) {
+ return;
+ }
+
+ LOG.debug("checkQuota: lastPrefix={}, bytesDiff={}, countDiff={}",
lastPrefix, bytesDiff, countDiff);
+
+ if (lastPrefix == null || lastPrefix.length() == 0) {
+ return;
+ }
+ // now check if the counts match the quota
+ String limitNode = Quotas.limitPath(lastPrefix);
+ DataNode node = zks.getZKDatabase().getNode(limitNode);
+ StatsTrack limitStats;
+ if (node == null) {
+ // should not happen
+ LOG.error("Missing count node for quota " + limitNode);
+ return;
+ }
+ synchronized (node) {
+ limitStats = new StatsTrack(new String(node.data));
+ }
+ //check the quota
+ boolean checkCountQuota = (limitStats.getCount() > -1 ||
limitStats.getCountHardLimit() > -1);
+ boolean checkByteQuota = (limitStats.getBytes() > -1 ||
limitStats.getByteHardLimit() > -1);
+
+ if (!checkCountQuota && !checkByteQuota) {
+ return;
Review comment:
Just thinking out loud: how often does that happen? Should the
administrator be alerted, somehow, that the clients are hitting an useless
quota node? Or am I missing an existing case and/or foreseen extension?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services