lhotari commented on code in PR #4638:
URL: https://github.com/apache/bookkeeper/pull/4638#discussion_r2297836070
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerFragmentReplicator.java:
##########
@@ -455,9 +455,10 @@ void batchRecoverLedgerFragmentEntry(final long
startEntryId,
int entriesToReplicateCnt = (int) (endEntryId - startEntryId + 1);
int maxBytesToReplicate = conf.getReplicationRateByBytes();
if (replicationThrottle != null) {
- if (maxBytesToReplicate != -1 && maxBytesToReplicate >
averageEntrySize.get() * entriesToReplicateCnt) {
- maxBytesToReplicate = averageEntrySize.get() *
entriesToReplicateCnt;
- }
+ int bytesToReplicateCnt = averageEntrySize.get() *
entriesToReplicateCnt;
+ bytesToReplicateCnt = bytesToReplicateCnt >= 0 ?
bytesToReplicateCnt : Integer.MAX_VALUE;
+ maxBytesToReplicate = Math.min(maxBytesToReplicate,
bytesToReplicateCnt);
Review Comment:
I think making this calculation with a `long` value would produce more
correct results.
It's not really realistic, but it's possible that the resulting value could
"wrap around" multiple times and become positive.
Something like this:
```suggestion
long bytesToReplicateCnt = (long) averageEntrySize.get() *
entriesToReplicateCnt;
maxBytesToReplicate = bytesToReplicateCnt > Integer.MAX_VALUE ?
Integer.MAX_VALUE : (int) bytesToReplicateCnt;
```
--
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]