PDGGK commented on code in PR #11766:
URL: https://github.com/apache/seatunnel/pull/11766#discussion_r3785712700


##########
seatunnel-core/seatunnel-core-starter/src/main/java/org/apache/seatunnel/core/starter/flowcontrol/FlowControlGate.java:
##########
@@ -44,7 +44,18 @@ private FlowControlGate(FlowControlStrategy 
flowControlStrategy) {
     }
 
     public void audit(SeaTunnelRow row) {
-        bytesRateLimiter.ifPresent(rateLimiter -> 
rateLimiter.acquire(row.getBytesSize()));
+        bytesRateLimiter.ifPresent(
+                rateLimiter -> {
+                    // A row can legitimately measure zero bytes -- 
SeaTunnelRow#getBytesSize
+                    // counts null as 0 and a String as its length, so an 
all-null row or one of
+                    // only empty strings sums to 0. RateLimiter rejects a 
non-positive permit
+                    // count, so charging it would abort the task instead of 
throttling it. Such a
+                    // row consumes no byte budget; the count limiter is what 
bounds its rate.
+                    int bytesSize = row.getBytesSize();
+                    if (bytesSize > 0) {
+                        rateLimiter.acquire(bytesSize);
+                    }
+                });
         countRateLimiter.ifPresent(RateLimiter::acquire);
     }
 

Review Comment:
   Agreed, that reads better — `audit` goes back to being a two-line dispatcher 
and the guard gets a name. Done in 24cbf06, with the explanation promoted to 
javadoc on the new method:
   
   ```java
   public void audit(SeaTunnelRow row) {
       bytesRateLimiter.ifPresent(rateLimiter -> acquireBytes(rateLimiter, 
row));
       countRateLimiter.ifPresent(RateLimiter::acquire);
   }
   ```
   
   Same condition and same `acquire` call, so behaviour is unchanged. 
`FlowControlGateTest` still passes 5/5 and `spotless:check` on 
`seatunnel-core-starter` is clean.
   
   Thanks for the review.



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