dimas-b commented on code in PR #3433:
URL: https://github.com/apache/polaris/pull/3433#discussion_r2688475237


##########
runtime/service/src/main/java/org/apache/polaris/service/ratelimiter/TokenBucket.java:
##########
@@ -51,11 +51,11 @@ public synchronized boolean tryAcquire() {
     long t = instantSource.millis();
     long millisPassed = Math.subtractExact(t, lastTokenGenerationMillis);
     lastTokenGenerationMillis = t;
-    tokens = Math.min(maxTokens, tokens + ((long) (millisPassed * 
tokensPerMilli)));
+    tokens = Math.min((double) maxTokens, tokens + (millisPassed * 
tokensPerMilli));

Review Comment:
   I believe a more robust fix would be to count the elapsed time in longer 
periods rather than computing small fractional increments. Note that floating 
point addition may not increase the value if given sufficient difference in 
exponents.
   
   ```
   shell> double x = 1e100;
   x ==> 1.0E100
   
   jshell> x + 0.0000001
   $2 ==> 1.0E100
   ```



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to