nzw921rx commented on code in PR #11766:
URL: https://github.com/apache/seatunnel/pull/11766#discussion_r3764538449
##########
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:
Great job🎉, do you think this would be more elegant? I would like to discuss
with you😄
```java
bytesRateLimiter.ifPresent(rateLimiter -> acquireBytes(rateLimiter, row));
/**
* 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.
*
*/
private void acquireBytes(RateLimiter rateLimiter, SeaTunnelRow row) {
int bytesSize = row.getBytesSize();
if (bytesSize > 0) {
rateLimiter.acquire(bytesSize);
}
}
```
--
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]