kezhuw commented on code in PR #2264:
URL: https://github.com/apache/zookeeper/pull/2264#discussion_r2113804414


##########
zookeeper-server/src/main/java/org/apache/zookeeper/server/BlueThrottle.java:
##########
@@ -323,6 +323,7 @@ public synchronized boolean checkLimit(int need) {
 
         long now = Time.currentElapsedTime();
         long diff = now - lastTime;
+        diff = Math.min((long) maxTokens * fillTime / fillCount, diff);

Review Comment:
   This confuses me in the first glance. I would prefer below code.
   
   ```java
   long refill = diff * fillCount / fillTime;
   tokens = (int) Math.min(tokens + refill, maxTokens);
   ```
   
   What are the configured values for these options to trigger the problem in 
your case ?
   
   I think above should be sufficient. If not, I think we could be more explict 
for overflow.
   
   ```
   if (tokens <= 0) {
       tokens = maxTokens;
   }
   ```
   ```



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

To unsubscribe, e-mail: notifications-unsubscr...@zookeeper.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to