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 2022/03/06 10:56:09 UTC

[GitHub] [pulsar] eolivelli commented on a change in pull request #14542: [PIP-146] ManagedCursorInfo compression

eolivelli commented on a change in pull request #14542:
URL: https://github.com/apache/pulsar/pull/14542#discussion_r820215471



##########
File path: managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/MetaStoreImpl.java
##########
@@ -364,41 +445,25 @@ private static MetaStoreException getException(Throwable t) {
         }
     }
 
-    public ManagedLedgerInfo parseManagedLedgerInfo(byte[] data) throws InvalidProtocolBufferException {
-        ByteBuf byteBuf = Unpooled.wrappedBuffer(data);
-        if (byteBuf.readableBytes() > 0 && byteBuf.readShort() == MAGIC_MANAGED_LEDGER_INFO_METADATA) {
-            ByteBuf decodeByteBuf = null;
-            try {
-                int metadataSize = byteBuf.readInt();
-                byte[] metadataBytes = new byte[metadataSize];
-                byteBuf.readBytes(metadataBytes);
-                MLDataFormats.ManagedLedgerInfoMetadata metadata =
-                        MLDataFormats.ManagedLedgerInfoMetadata.parseFrom(metadataBytes);
-
-                long unpressedSize = metadata.getUncompressedSize();
-                decodeByteBuf = getCompressionCodec(metadata.getCompressionType())
-                        .decode(byteBuf, (int) unpressedSize);
-                byte[] decodeBytes;
-                // couldn't decode data by ZLIB compression byteBuf array() directly
-                if (decodeByteBuf.hasArray() && !CompressionType.ZLIB.equals(metadata.getCompressionType())) {
-                    decodeBytes = decodeByteBuf.array();
-                } else {
-                    decodeBytes = new byte[decodeByteBuf.readableBytes() - decodeByteBuf.readerIndex()];
-                    decodeByteBuf.readBytes(decodeBytes);
-                }
-                return ManagedLedgerInfo.parseFrom(decodeBytes);
-            } catch (Exception e) {
-                log.error("Failed to parse managedLedgerInfo metadata, "
-                        + "fall back to parse managedLedgerInfo directly.", e);
-                return ManagedLedgerInfo.parseFrom(data);
-            } finally {
-                if (decodeByteBuf != null) {
-                    decodeByteBuf.release();
-                }
-                byteBuf.release();
+    private byte[] parseCompressedInfo(ByteBuf byteBuf, MLDataFormats.CompressionType compressionType,
+                                       long unpressedSize) throws IOException {
+        ByteBuf decodeByteBuf = null;
+        try {
+            decodeByteBuf = getCompressionCodec(compressionType)
+                    .decode(byteBuf, (int) unpressedSize);
+            byte[] decodeBytes;
+            // couldn't decode data by ZLIB compression byteBuf array() directly
+            if (decodeByteBuf.hasArray() && !CompressionType.ZLIB.equals(compressionType)) {
+                decodeBytes = decodeByteBuf.array();

Review comment:
       This may be wrong, the array() has an offset. 




-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org