diff --git a/tiered-storage/jcloud/src/main/java/org/apache/bookkeeper/mledger/offload/jcloud/impl/BlobStoreBackedInputStreamImpl.java b/tiered-storage/jcloud/src/main/java/org/apache/bookkeeper/mledger/offload/jcloud/impl/BlobStoreBackedInputStreamImpl.java index d07bab6cb3bf3..1cb01c248ade7 100644 --- a/tiered-storage/jcloud/src/main/java/org/apache/bookkeeper/mledger/offload/jcloud/impl/BlobStoreBackedInputStreamImpl.java +++ b/tiered-storage/jcloud/src/main/java/org/apache/bookkeeper/mledger/offload/jcloud/impl/BlobStoreBackedInputStreamImpl.java @@ -116,7 +116,7 @@ public int read(byte[] b, int off, int len) throws IOException { @Override public void seek(long position) { - log.debug("Seeking to {} on {}/{}, current position {}", position, bucket, key, cursor); + log.debug("Seeking to {} on {}/{}, current position {} (bufStart:{}, bufEnd:{})", position, bucket, key, cursor, bufferOffsetStart, bufferOffsetEnd); if (position >= bufferOffsetStart && position <= bufferOffsetEnd) { long newIndex = position - bufferOffsetStart; buffer.readerIndex((int)newIndex); diff --git a/tiered-storage/jcloud/src/main/java/org/apache/bookkeeper/mledger/offload/jcloud/impl/BlobStoreBackedReadHandleImpl.java b/tiered-storage/jcloud/src/main/java/org/apache/bookkeeper/mledger/offload/jcloud/impl/BlobStoreBackedReadHandleImpl.java index 20ccb3dba5f70..d64deb890df9c 100644 --- a/tiered-storage/jcloud/src/main/java/org/apache/bookkeeper/mledger/offload/jcloud/impl/BlobStoreBackedReadHandleImpl.java +++ b/tiered-storage/jcloud/src/main/java/org/apache/bookkeeper/mledger/offload/jcloud/impl/BlobStoreBackedReadHandleImpl.java @@ -106,14 +106,11 @@ public CompletableFuture readAsync(long firstEntry, long lastEntr List entries = new ArrayList(); long nextExpectedId = firstEntry; try { - OffloadIndexEntry entry = index.getIndexEntryForEntry(firstEntry); - inputStream.seek(entry.getDataOffset()); - while (entriesToRead > 0) { int length = dataStream.readInt(); if (length < 0) { // hit padding or new block - inputStream.seekForward(index.getIndexEntryForEntry(nextExpectedId).getDataOffset()); - length = dataStream.readInt(); + inputStream.seek(index.getIndexEntryForEntry(nextExpectedId).getDataOffset()); + continue; } long entryId = dataStream.readLong(); @@ -126,6 +123,14 @@ public CompletableFuture readAsync(long firstEntry, long lastEntr } entriesToRead--; nextExpectedId++; + } else if (entryId > nextExpectedId) { + inputStream.seek(index.getIndexEntryForEntry(nextExpectedId).getDataOffset()); + continue; + } else if (entryId < nextExpectedId + && !index.getIndexEntryForEntry(nextExpectedId).equals( + index.getIndexEntryForEntry(entryId))) { + inputStream.seek(index.getIndexEntryForEntry(nextExpectedId).getDataOffset()); + continue; } else if (entryId > lastEntry) { log.info("Expected to read {}, but read {}, which is greater than last entry {}", nextExpectedId, entryId, lastEntry); diff --git a/tiered-storage/jcloud/src/main/java/org/apache/bookkeeper/mledger/offload/jcloud/impl/DataBlockHeaderImpl.java b/tiered-storage/jcloud/src/main/java/org/apache/bookkeeper/mledger/offload/jcloud/impl/DataBlockHeaderImpl.java index bb406c48b7589..0aa4959d8dec7 100644 --- a/tiered-storage/jcloud/src/main/java/org/apache/bookkeeper/mledger/offload/jcloud/impl/DataBlockHeaderImpl.java +++ b/tiered-storage/jcloud/src/main/java/org/apache/bookkeeper/mledger/offload/jcloud/impl/DataBlockHeaderImpl.java @@ -123,5 +123,11 @@ public InputStream toStream() { // true means the input stream will release the ByteBuf on close return new ByteBufInputStream(out, true); } + + @Override + public String toString() { + return String.format("DataBlockHeader(len:%d,hlen:%d,firstEntry:%d)", + blockLength, headerLength, firstEntryId); + } } diff --git a/tiered-storage/jcloud/src/main/java/org/apache/bookkeeper/mledger/offload/jcloud/impl/OffloadIndexEntryImpl.java b/tiered-storage/jcloud/src/main/java/org/apache/bookkeeper/mledger/offload/jcloud/impl/OffloadIndexEntryImpl.java index f3b81da6883ee..5cce6d48553c7 100644 --- a/tiered-storage/jcloud/src/main/java/org/apache/bookkeeper/mledger/offload/jcloud/impl/OffloadIndexEntryImpl.java +++ b/tiered-storage/jcloud/src/main/java/org/apache/bookkeeper/mledger/offload/jcloud/impl/OffloadIndexEntryImpl.java @@ -58,5 +58,11 @@ private OffloadIndexEntryImpl(long entryId, int partId, long offset, long blockH this.offset = offset; this.blockHeaderSize = blockHeaderSize; } + + @Override + public String toString() { + return String.format("[eid:%d, part:%d, offset:%d, doffset:%d]", + entryId, partId, offset, getDataOffset()); + } }