You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by mm...@apache.org on 2018/05/22 13:54:24 UTC

[incubator-pulsar] branch master updated: BlockAwareSegmentInputStreamImpl shouldn't use LedgerEntry#getLength (#1799)

This is an automated email from the ASF dual-hosted git repository.

mmerli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-pulsar.git


The following commit(s) were added to refs/heads/master by this push:
     new ca9099d  BlockAwareSegmentInputStreamImpl shouldn't use LedgerEntry#getLength (#1799)
ca9099d is described below

commit ca9099d41586571c9b782a66400d839b08157ea8
Author: Ivan Kelly <iv...@apache.org>
AuthorDate: Tue May 22 15:54:21 2018 +0200

    BlockAwareSegmentInputStreamImpl shouldn't use LedgerEntry#getLength (#1799)
    
    LedgerEntry#getLength() returns the length of the ledger up to and
    including the length of the entry, not the length of the entry as you
    would expected (and the documentation states). So we shouldn't use it
    when serializing the entry, because what we need is the length of the
    entry.
    
    This patch changes BlockAwareSegmentInputStreamImpl to use the
    readable bytes of the bytebuf instead.
    
    Master Issue: #1511
---
 .../broker/s3offload/impl/BlockAwareSegmentInputStreamImpl.java      | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/s3offload/impl/BlockAwareSegmentInputStreamImpl.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/s3offload/impl/BlockAwareSegmentInputStreamImpl.java
index 0fdf48f..03ae702 100644
--- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/s3offload/impl/BlockAwareSegmentInputStreamImpl.java
+++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/s3offload/impl/BlockAwareSegmentInputStreamImpl.java
@@ -122,14 +122,15 @@ public class BlockAwareSegmentInputStreamImpl extends BlockAwareSegmentInputStre
             Iterator<LedgerEntry> iterator = ledgerEntriesOnce.iterator();
             while (iterator.hasNext()) {
                 LedgerEntry entry = iterator.next();
-                int entryLength = (int) entry.getLength();
+                ByteBuf buf = entry.getEntryBuffer().retain();
+                int entryLength = buf.readableBytes();
                 long entryId = entry.getEntryId();
 
                 CompositeByteBuf entryBuf = PooledByteBufAllocator.DEFAULT.compositeBuffer(2);
                 ByteBuf entryHeaderBuf = PooledByteBufAllocator.DEFAULT.buffer(ENTRY_HEADER_SIZE, ENTRY_HEADER_SIZE);
 
                 entryHeaderBuf.writeInt(entryLength).writeLong(entryId);
-                entryBuf.addComponents(true, entryHeaderBuf, entry.getEntryBuffer().retain());
+                entryBuf.addComponents(true, entryHeaderBuf, buf);
 
                 entries.add(entryBuf);
             }

-- 
To stop receiving notification emails like this one, please contact
mmerli@apache.org.