zymap commented on code in PR #15063:
URL: https://github.com/apache/pulsar/pull/15063#discussion_r849305637


##########
tiered-storage/jcloud/src/main/java/org/apache/bookkeeper/mledger/offload/jcloud/impl/BlockAwareSegmentInputStreamImpl.java:
##########
@@ -76,6 +78,52 @@ public BlockAwareSegmentInputStreamImpl(ReadHandle ledger, 
long startEntryId, in
         this.entriesByteBuf = Lists.newLinkedList();
     }
 
+    private int currentOffset = 0;
+
+    private byte[] readEntries(int len) throws IOException {
+        checkState(bytesReadOffset >= 
DataBlockHeaderImpl.getDataStartOffset());
+        checkState(bytesReadOffset < blockSize);
+
+        // once reach the end of entry buffer, read more, if there is more
+        if (bytesReadOffset < dataBlockFullOffset
+            && entriesByteBuf.isEmpty()
+            && startEntryId + blockEntryCount <= ledger.getLastAddConfirmed()) 
{
+            entriesByteBuf = readNextEntriesFromLedger(startEntryId + 
blockEntryCount, ENTRIES_PER_READ);
+        }
+
+        if (!entriesByteBuf.isEmpty()
+            && bytesReadOffset + entriesByteBuf.get(0).readableBytes() <= 
blockSize) {
+            // always read from the first ByteBuf in the list, once read all 
of its content remove it.
+            ByteBuf entryByteBuf = entriesByteBuf.get(0);
+            int readableBytes = entryByteBuf.readableBytes();
+            int read = Math.min(readableBytes, len);
+            byte[] buf = new byte[read];

Review Comment:
   Maybe we can create a bytes array and reuse it to fill the data for every 
read operation? That would reduce the bytes allocate.



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