ivankelly commented on a change in pull request #1678: PIP-17: provide BlockAwareSegmentInputStream implementation and test URL: https://github.com/apache/incubator-pulsar/pull/1678#discussion_r185495929
########## File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/s3offload/impl/BlockAwareSegmentInputStream.java ########## @@ -90,68 +84,60 @@ private int readEntries() throws IOException { checkState(bytesReadOffset >= DataBlockHeaderImpl.getDataStartOffset()); checkState(bytesReadOffset < dataBlockFullOffset); - try { - // once reach the end of entry buffer, start a new read. - if (entriesByteBuf.isEmpty()) { - readNextEntriesFromLedger(); - log.debug("After readNextEntriesFromLedger: bytesReadOffset: {}, blockBytesHave: {}", - bytesReadOffset, blockBytesHave); - } - - // always read from the first ByteBuf in the list, once read all of its content remove it. - ByteBuf entryByteBuf = entriesByteBuf.get(0); - int ret = entryByteBuf.readByte(); - bytesReadOffset ++; + // once reach the end of entry buffer, start a new read. + if (entriesByteBuf.isEmpty()) { + entriesByteBuf = readNextEntriesFromLedger(startEntryId + blockEntryCount, ENTRIES_PER_READ); + } - if (entryByteBuf.readableBytes() == 0) { - entryByteBuf.release(); - entriesByteBuf.remove(0); + // always read from the first ByteBuf in the list, once read all of its content remove it. + ByteBuf entryByteBuf = entriesByteBuf.get(0); + int ret = entryByteBuf.readByte(); + bytesReadOffset ++; + + if (entryByteBuf.readableBytes() == 0) { + entryByteBuf.release(); + entriesByteBuf.remove(0); + blockEntryCount++; + if ((!entriesByteBuf.isEmpty()) && bytesReadOffset + entriesByteBuf.get(0).readableBytes() > blockSize) { Review comment: What entriesByteBuf is empty, but the first entry in the next read block will put you over the blockSize? This check needs to move to before line 92 (that's why I had the if-else in previous comment). ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services