Skip to content
This repository has been archived by the owner on Apr 1, 2024. It is now read-only.

ISSUE-10967: parseMessageMetadata error when broker entry metadata enable #2662

Closed
sijie opened this issue Jun 18, 2021 · 0 comments
Closed
Labels

Comments

@sijie
Copy link
Member

sijie commented Jun 18, 2021

Original Issue: apache#10967


Describe the bug
If broker entry metadata enabled, we may get exception in many cases like :

Received error from server: Failed to get batch size for entry java.lang.IllegalArgumentException: Invalid unknonwn tag type: 6

this problem also reported in :
apache#10950
apache#9255
apache#10924

this is caused by apache#9046,

Before apache#9046 code is

public static MessageMetadata parseMessageMetadata(ByteBuf buffer) {
        try {
            // first, skip raw metadata if exist
            skipBrokerEntryMetadataIfExist(buffer);
            // initially reader-index may point to start_of_checksum : increment reader-index to start_of_metadata
            // to parse metadata
            skipChecksumIfPresent(buffer);
            int metadataSize = (int) buffer.readUnsignedInt();

            int writerIndex = buffer.writerIndex();
            buffer.writerIndex(buffer.readerIndex() + metadataSize);
            ByteBufCodedInputStream stream = ByteBufCodedInputStream.get(buffer);
            MessageMetadata.Builder messageMetadataBuilder = MessageMetadata.newBuilder();
            MessageMetadata res = messageMetadataBuilder.mergeFrom(stream, null).build();
            buffer.writerIndex(writerIndex);
            messageMetadataBuilder.recycle();
            stream.recycle();
            return res;
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

After apache#9046,

 public static MessageMetadata parseMessageMetadata(ByteBuf buffer) {
        MessageMetadata md = LOCAL_MESSAGE_METADATA.get();
        parseMessageMetadata(buffer, md);
        return md;
    }

    public static void parseMessageMetadata(ByteBuf buffer, MessageMetadata msgMetadata) {
        // initially reader-index may point to start_of_checksum : increment reader-index to start_of_metadata
        // to parse metadata
        skipChecksumIfPresent(buffer);
        int metadataSize = (int) buffer.readUnsignedInt();

        msgMetadata.parseFrom(buffer, metadataSize);
    }

this PR removed code

           skipBrokerEntryMetadataIfExist(buffer);

So, this may cause exceptions when parseMessageMetadata

@sijie sijie added the type/bug label Jun 18, 2021
@sijie sijie closed this as completed Jun 18, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

1 participant