New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[fix][client] Fixes batch_size not checked in MessageId#fromByteArrayWithTopic #18405
Merged
BewareMyPower
merged 1 commit into
apache:master
from
BewareMyPower:bewaremypower/fix-message-id-parse
Nov 14, 2022
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any case in that we will have a batch index but no batch size?
Maybe we should throw an exception due to it should be the case that corrupted data is provided.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
batch_size
field was introduced from #8659, before that, thebatch_index
field already existed. For example, the 2.7.1 client could send such a message id, see #18395 (comment).Other languages clients might also sent a message id that has the
batch_index
field but nobatch_size
field.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And when I revisited the existing code, there are many places that set the
batch_index
field but doesn't set thebatch_size
field. Thebatch_size
field is easily to be ignored because it's not considered inequals
andhashCode
methods. BTW, I'm not sure whether the default value of thebatch_index
field might increase the cases thatbatch_index
is set whilebatch_size
is not set. IMO, adding default values to the optional fields increases the chance of such an error. We should be careful for new fields if it's optional.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@codelipenghui FWIW we even have already done it for
fromByteArray
(as this patch modifies).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@BewareMyPower So you may simplify the code as
fromByteArray
did:That is, a simpler constructor. Or factor it out to a helper method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to refactor these two classes in another PR. IMO, BatchMessageIdImpl should be deprecated and I'm not willing to add new public APIs to it. The design of BatchMessageIdImpl is bad. We should add the optional
batch_size
andbatch_index
fields to MessageIdImpl instead. If we followed the design of BatchMessageIdImpl, whenbatch_size
was introduced, we should add another class like BatchMessageIdImplWithSize that inherits the BatchMessageIdImpl and add thebatch_size
field as well as the acker.