ztzg commented on a change in pull request #934: ZOOKEEPER-3301:Enforce the 
quota limit
URL: https://github.com/apache/zookeeper/pull/934#discussion_r357070025
 
 

 ##########
 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);
 
 Review comment:
   How about:
   
   ```java
   boolean checkCountQuota = countDiff != 0 && (limitStats.getCount() > -1 || 
limitStats.getCountHardLimit() > -1);
   ```
   
   (and the same for `checkByteQuota`/`bytesDiff`.)

----------------------------------------------------------------
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

Reply via email to