horizonzy commented on code in PR #15063:
URL: https://github.com/apache/pulsar/pull/15063#discussion_r869455058
##########
tiered-storage/jcloud/src/main/java/org/apache/bookkeeper/mledger/offload/jcloud/impl/BlockAwareSegmentInputStreamImpl.java:
##########
@@ -87,6 +94,50 @@ public BlockAwareSegmentInputStreamImpl(ReadHandle ledger,
long startEntryId, in
this.topicName = ledgerName;
}
+ private ByteBuf 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);
+ ByteBuf buf = entryByteBuf.slice(currentOffset, read);
+ buf.retain();
+ currentOffset += read;
+ entryByteBuf.readerIndex(currentOffset);
+ bytesReadOffset += read;
+
+ if (entryByteBuf.readableBytes() == 0) {
+ entryByteBuf.release();
+ entriesByteBuf.remove(0);
+ blockEntryCount++;
+ currentOffset = 0;
+ }
+
+ return buf;
+ } else {
+ // no space for a new entry or there are no more entries
+ // set data block full, return end padding
+ if (dataBlockFullOffset == blockSize) {
Review Comment:
Discuss: When there is not more entries to read, will fill up padding, it
just 1 byte one by one to fill, it looks back the origin logicment. Shall we
need support multi level buffer to make it faster and reduce invoke times.
--
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]