[improve][client]PIP-230 Throw exception when MessageIdImpl and BatchMessageIdImpl compare with each other#18981
[improve][client]PIP-230 Throw exception when MessageIdImpl and BatchMessageIdImpl compare with each other#18981congbobo184 wants to merge 7 commits into
Conversation
…eIdImpl compare with each other
|
@congbobo184 Please add the following content to your PR description and select a checkbox: |
| public int compareTo(@Nonnull MessageId o) { | ||
| if (o instanceof MessageIdImpl) { | ||
| if (o instanceof BatchMessageIdImpl) { | ||
| throw new UnsupportedOperationException(this.getClass().getName() |
There was a problem hiding this comment.
maybe we could allow comparison when MessageIdImpl' and BatchMessageIdImpl' do not have the same ledgerId and entryId?
There was a problem hiding this comment.
This may cause confusion for users, direct forbid may be more effective and easier to understand
There was a problem hiding this comment.
But comparing (1,1,0) to (1,2) is expected, right? only comparing (1,1,0) to 1,1 is not expected.
There was a problem hiding this comment.
We should forbit comparing the two types. This is not the correct behavior for users. In what scenario will they compare BatchMessageId and MessageId? Now that have decided to throw an exception, why not forbid it outright? if allow some, forbid some, the user may use the wrong situation, which may exceed his expectations and judgments. @codelipenghui /cc
| public int compareTo(@Nonnull MessageId o) { | ||
| if (o instanceof MessageIdImpl) { | ||
| if (!(o instanceof BatchMessageIdImpl)) { | ||
| throw new UnsupportedOperationException(this.getClass().getName() |
There was a problem hiding this comment.
If we use the way of throwing exceptions then illegalArgumentException may be better here when the BatchMessageID and MessageID have the same ledger ID and entry ID.
There was a problem hiding this comment.
this throw UnsupportedOperationException , We should throw the same exception, otherwise, the user needs to catch both exceptions. MessageIdImpl and BatchMessageIdImpl can compare not illegal arguments, It's just that we don't support it
| long ledgerId2, long entryId2, int partitionIndex2, int batchIndex2 | ||
| ) { | ||
| return ComparisonChain.start() | ||
| .compare(ledgerId1, ledgerId2) |
There was a problem hiding this comment.
This code will be exd uted in hot paths probably.
Is it better to use raw java code? We could save method calls and allocations
There was a problem hiding this comment.
goog point! I think we can use raw java code
|
The pr had no activity for 30 days, mark with Stale label. |
|
Since we will start the RC version of
|
|
The pr had no activity for 30 days, mark with Stale label. |
Motivation
#18957
Modifications
#18957
Verifying this change
Add the different MessageId compareTo another MessageId test
Does this pull request potentially affect one of the following parts:
If the box was checked, please highlight the changes
Documentation
docdoc-requireddoc-not-neededdoc-completeMatching PR in forked repository
PR in forked repository:
congbobo184#13