Skip to content

MINOR: Fix MetadataResponse#toStruct serialization for null leaders#4449

Merged
hachikuji merged 1 commit intoapache:trunkfrom
cmccabe:fix-metadataresponse-serialization
Jan 27, 2018
Merged

MINOR: Fix MetadataResponse#toStruct serialization for null leaders#4449
hachikuji merged 1 commit intoapache:trunkfrom
cmccabe:fix-metadataresponse-serialization

Conversation

@cmccabe
Copy link
Copy Markdown
Contributor

@cmccabe cmccabe commented Jan 19, 2018

In MetadataResponse deserialization, if the partition leader key is set
to -1, the leader is set to null. The MetadataResponse#toStruct code
should handle this correctly as well.

RequestResponseTest should test this as well.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could perhaps add a leaderId in PartitionMetadata

@cmccabe cmccabe force-pushed the fix-metadataresponse-serialization branch from 91aab9f to 33d067e Compare January 19, 2018 19:55
Copy link
Copy Markdown
Contributor

@hachikuji hachikuji left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@hachikuji
Copy link
Copy Markdown
Contributor

Actually I may have jumped the gun on my +1. I was looking at uses of leader() and it seems like this one would also NPE: https://github.com/apache/kafka/blob/trunk/core/src/main/scala/kafka/server/KafkaApis.scala#L1107. Maybe we can fix it as well?

@cmccabe cmccabe force-pushed the fix-metadataresponse-serialization branch from 33d067e to e730d96 Compare January 24, 2018 19:13
@cmccabe
Copy link
Copy Markdown
Contributor Author

cmccabe commented Jan 24, 2018

Should be fixed now

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a little annoying that we have to handle both null and None. Any reason not to use flatMap as suggested offline?

.flatMap(p => Option(p.leader))

Or something like that.

…tly.

In MetadataResponse deserialization, if the partition leader key is set
to -1, the leader is set to null.  The MetadataResponse#toStruct code
should handle this correctly as well.

Also fix a case in KafkaApis where we were not taking into account the
possibility of the leader being null.

RequestResponseTest should test this as well.
@cmccabe cmccabe force-pushed the fix-metadataresponse-serialization branch from e730d96 to 8a278e6 Compare January 26, 2018 19:07
@hachikuji hachikuji merged commit e8b30e4 into apache:trunk Jan 27, 2018
hachikuji pushed a commit that referenced this pull request Jan 27, 2018
…tly. (#4449)

In MetadataResponse deserialization, if the partition leader key is set
to -1, the leader is set to null.  The MetadataResponse#toStruct code
should handle this correctly as well.

Also fix a case in KafkaApis where we were not taking into account the
possibility of the leader being null.

RequestResponseTest should test this as well.

Reviewers: Ismael Juma <ismael@juma.me.uk>, Jason Gustafson <jason@confluent.io>
@cmccabe cmccabe deleted the fix-metadataresponse-serialization branch May 20, 2019 18:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants