You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2018/12/08 22:05:03 UTC
[GitHub] sijie closed pull request #3143: Recycle objects when parsing
single message metadata
sijie closed pull request #3143: Recycle objects when parsing single message metadata
URL: https://github.com/apache/pulsar/pull/3143
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/pulsar-common/src/main/java/org/apache/pulsar/common/api/Commands.java b/pulsar-common/src/main/java/org/apache/pulsar/common/api/Commands.java
index 31dcac190e..2adb274697 100644
--- a/pulsar-common/src/main/java/org/apache/pulsar/common/api/Commands.java
+++ b/pulsar-common/src/main/java/org/apache/pulsar/common/api/Commands.java
@@ -1069,21 +1069,20 @@ public static ByteBuf deSerializeSingleMessageInBatch(ByteBuf uncompressedPayloa
int beginIndex = uncompressedPayload.readerIndex() + singleMetaSize;
uncompressedPayload.writerIndex(beginIndex);
ByteBufCodedInputStream stream = ByteBufCodedInputStream.get(uncompressedPayload);
- PulsarApi.SingleMessageMetadata singleMessageMetadata = singleMessageMetadataBuilder.mergeFrom(stream, null)
- .build();
+ singleMessageMetadataBuilder.mergeFrom(stream, null);
+ stream.recycle();
- int singleMessagePayloadSize = singleMessageMetadata.getPayloadSize();
+ int singleMessagePayloadSize = singleMessageMetadataBuilder.getPayloadSize();
- uncompressedPayload.markReaderIndex();
- ByteBuf singleMessagePayload = uncompressedPayload.slice(uncompressedPayload.readerIndex(),
- singleMessagePayloadSize);
- singleMessagePayload.retain();
+ int readerIndex = uncompressedPayload.readerIndex();
+ ByteBuf singleMessagePayload = uncompressedPayload.retainedSlice(readerIndex, singleMessagePayloadSize);
uncompressedPayload.writerIndex(writerIndex);
- uncompressedPayload.resetReaderIndex();
+
// reader now points to beginning of payload read; so move it past message payload just read
if (index < batchSize) {
- uncompressedPayload.readerIndex(uncompressedPayload.readerIndex() + singleMessagePayloadSize);
+ uncompressedPayload.readerIndex(readerIndex + singleMessagePayloadSize);
}
+
return singleMessagePayload;
}
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services