hangc0276 commented on code in PR #4741:
URL: https://github.com/apache/bookkeeper/pull/4741#discussion_r3307187249
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/BatchedReadEntryProcessor.java:
##########
@@ -56,18 +56,23 @@ protected ReferenceCounted readData() throws Exception {
}
long maxSize = Math.min(batchRequest.getMaxSize(), maxBatchReadSize);
//See BookieProtoEncoding.ResponseEnDeCoderPreV3#encode on
BatchedReadResponse case.
- long frameSize = 24 + 8 + 4;
+ long frameSize = 24 + 8 + Integer.BYTES;
for (int i = 0; i < maxCount; i++) {
try {
ByteBuf entry =
requestProcessor.getBookie().readEntry(request.getLedgerId(),
request.getEntryId() + i);
- frameSize += entry.readableBytes() + 4;
if (data == null) {
+ frameSize += entry.readableBytes() + Integer.BYTES;
data = ByteBufList.get(entry);
+ long perEntrySize = entry.readableBytes() + Integer.BYTES;
+ long remainingBudget = maxSize - frameSize;
+ long remainingEntries = remainingBudget > 0 ?
remainingBudget / Math.max(perEntrySize, 1L) : 0L;
+ maxCount = (int) Math.min(maxCount, 1L + remainingEntries);
} else {
- if (frameSize > maxSize) {
+ if (frameSize + entry.readableBytes() + Integer.BYTES >
maxSize) {
Review Comment:
Simplify the code to
```
frameSize += entry.readableBytes() + Integer.BYTES;
if (frameSize > maxSize) {
entry.release();
break;
}
data.add(entry);
```
--
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]