Skip to content

[improve][client]PIP-230 Throw exception when MessageIdImpl and BatchMessageIdImpl compare with each other#18981

Draft
congbobo184 wants to merge 7 commits into
apache:masterfrom
congbobo184:congbo/pip-230
Draft

[improve][client]PIP-230 Throw exception when MessageIdImpl and BatchMessageIdImpl compare with each other#18981
congbobo184 wants to merge 7 commits into
apache:masterfrom
congbobo184:congbo/pip-230

Conversation

@congbobo184
Copy link
Copy Markdown
Contributor

@congbobo184 congbobo184 commented Dec 19, 2022

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

  • Dependencies (add or upgrade a dependency)
  • The public API
  • The schema
  • The default values of configurations
  • The threading model
  • The binary protocol
  • The REST endpoints
  • The admin CLI options
  • Anything that affects deployment

Documentation

  • doc
  • doc-required
  • doc-not-needed
  • doc-complete

Matching PR in forked repository

PR in forked repository:
congbobo184#13

@congbobo184 congbobo184 added type/bug The PR fixed a bug or issue reported a bug area/client doc-not-needed Your PR changes do not impact docs labels Dec 19, 2022
@congbobo184 congbobo184 added this to the 2.12.0 milestone Dec 19, 2022
@congbobo184 congbobo184 self-assigned this Dec 19, 2022
@github-actions github-actions Bot added doc-label-missing and removed doc-not-needed Your PR changes do not impact docs labels Dec 19, 2022
@github-actions
Copy link
Copy Markdown

@congbobo184 Please add the following content to your PR description and select a checkbox:

- [ ] `doc` <!-- Your PR contains doc changes -->
- [ ] `doc-required` <!-- Your PR changes impact docs and you will update later -->
- [ ] `doc-not-needed` <!-- Your PR changes do not impact docs -->
- [ ] `doc-complete` <!-- Docs have been already added -->

@github-actions github-actions Bot added doc-not-needed Your PR changes do not impact docs and removed doc-label-missing labels Dec 19, 2022
@congbobo184 congbobo184 changed the title [improve][pip-230] Throw exception when MessageIdImpl and BatchMessageIdImpl compare with each other [PIP-230][improve] Throw exception when MessageIdImpl and BatchMessageIdImpl compare with each other Dec 19, 2022
public int compareTo(@Nonnull MessageId o) {
if (o instanceof MessageIdImpl) {
if (o instanceof BatchMessageIdImpl) {
throw new UnsupportedOperationException(this.getClass().getName()
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.

maybe we could allow comparison when MessageIdImpl' and BatchMessageIdImpl' do not have the same ledgerId and entryId?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This may cause confusion for users, direct forbid may be more effective and easier to understand

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.

But comparing (1,1,0) to (1,2) is expected, right? only comparing (1,1,0) to 1,1 is not expected.

Copy link
Copy Markdown
Contributor Author

@congbobo184 congbobo184 Dec 20, 2022

Choose a reason for hiding this comment

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

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

@congbobo184 congbobo184 removed the type/bug The PR fixed a bug or issue reported a bug label Dec 19, 2022
@congbobo184 congbobo184 changed the title [PIP-230][improve] Throw exception when MessageIdImpl and BatchMessageIdImpl compare with each other [feat][PIP-230] Throw exception when MessageIdImpl and BatchMessageIdImpl compare with each other Dec 19, 2022
@congbobo184 congbobo184 changed the title [feat][PIP-230] Throw exception when MessageIdImpl and BatchMessageIdImpl compare with each other [feat][client] Throw exception when MessageIdImpl and BatchMessageIdImpl compare with each other Dec 19, 2022
@congbobo184 congbobo184 changed the title [feat][client] Throw exception when MessageIdImpl and BatchMessageIdImpl compare with each other [feat][pip-230] Throw exception when MessageIdImpl and BatchMessageIdImpl compare with each other Dec 19, 2022
@congbobo184 congbobo184 changed the title [feat][pip-230] Throw exception when MessageIdImpl and BatchMessageIdImpl compare with each other [feat][client][pip-230] Throw exception when MessageIdImpl and BatchMessageIdImpl compare with each other Dec 19, 2022
public int compareTo(@Nonnull MessageId o) {
if (o instanceof MessageIdImpl) {
if (!(o instanceof BatchMessageIdImpl)) {
throw new UnsupportedOperationException(this.getClass().getName()
Copy link
Copy Markdown
Contributor

@liangyepianzhou liangyepianzhou Dec 20, 2022

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

throw new UnsupportedOperationException("Unknown MessageId type: " + o.getClass().getName());

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

@congbobo184 congbobo184 changed the title [feat][client][pip-230] Throw exception when MessageIdImpl and BatchMessageIdImpl compare with each other [improve][client]PIP-230 Throw exception when MessageIdImpl and BatchMessageIdImpl compare with each other Dec 20, 2022
@congbobo184 congbobo184 marked this pull request as draft December 24, 2022 08:07
long ledgerId2, long entryId2, int partitionIndex2, int batchIndex2
) {
return ComparisonChain.start()
.compare(ledgerId1, ledgerId2)
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.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

goog point! I think we can use raw java code

@github-actions
Copy link
Copy Markdown

The pr had no activity for 30 days, mark with Stale label.

@github-actions github-actions Bot added the Stale label Jan 26, 2023
@poorbarcode
Copy link
Copy Markdown
Contributor

Since we will start the RC version of 3.0.0 on 2023-04-11, I will change the label/milestone of PR who have not been merged.

  • The PR of type feature is deferred to 3.1.0
  • The PR of type fix is deferred to 3.0.1
    So drag this PR to 3.1.0

@poorbarcode poorbarcode modified the milestones: 3.0.0, 3.1.0 Apr 10, 2023
@github-actions github-actions Bot removed the Stale label Apr 11, 2023
@github-actions
Copy link
Copy Markdown

The pr had no activity for 30 days, mark with Stale label.

@github-actions github-actions Bot added the Stale label May 11, 2023
@Technoboy- Technoboy- modified the milestones: 3.1.0, 3.2.0 Jul 31, 2023
@Technoboy- Technoboy- modified the milestones: 3.2.0, 3.3.0 Dec 22, 2023
@coderzc coderzc modified the milestones: 3.3.0, 3.4.0 May 8, 2024
@lhotari lhotari modified the milestones: 4.0.0, 4.1.0 Oct 14, 2024
@coderzc coderzc modified the milestones: 4.1.0, 4.2.0 Sep 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/client doc-not-needed Your PR changes do not impact docs Stale

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants