You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/12/19 08:44:36 UTC

[GitHub] [pulsar] congbobo184 opened a new pull request, #18981: [improve][pip-230] Throw exception when MessageIdImpl and BatchMessageIdImpl compare with each other

congbobo184 opened a new pull request, #18981:
URL: https://github.com/apache/pulsar/pull/18981

   ### Motivation
   https://github.com/apache/pulsar/issues/18957
   
   ### Modifications
   https://github.com/apache/pulsar/issues/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
   
   <!-- DO NOT REMOVE THIS SECTION. CHECK THE PROPER BOX ONLY. -->
   
   - [ ] `doc` <!-- Your PR contains doc changes. Please attach the local preview screenshots (run `sh start.sh` at `pulsar/site2/website`) to your PR description, or else your PR might not get merged. -->
   - [ ] `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 -->
   
   ### Matching PR in forked repository
   
   PR in forked repository: <!-- ENTER URL HERE -->
   
   <!--
   After opening this PR, the build in apache/pulsar will fail and instructions will
   be provided for opening a PR in the PR author's forked repository.
   
   apache/pulsar pull requests should be first tested in your own fork since the 
   apache/pulsar CI based on GitHub Actions has constrained resources and quota.
   GitHub Actions provides separate quota for pull requests that are executed in 
   a forked repository.
   
   The tests will be run in the forked repository until all PR review comments have
   been handled, the tests pass and the PR is approved by a reviewer.
   -->
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] congbobo184 commented on a diff in pull request #18981: [PIP-230][improve] Throw exception when MessageIdImpl and BatchMessageIdImpl compare with each other

Posted by GitBox <gi...@apache.org>.
congbobo184 commented on code in PR #18981:
URL: https://github.com/apache/pulsar/pull/18981#discussion_r1052333031


##########
pulsar-client/src/main/java/org/apache/pulsar/client/impl/MessageIdImpl.java:
##########
@@ -204,11 +204,13 @@ public byte[] toByteArray() {
     @Override
     public int compareTo(@Nonnull MessageId o) {
         if (o instanceof MessageIdImpl) {
+            if (o instanceof BatchMessageIdImpl) {
+                throw new UnsupportedOperationException(this.getClass().getName()

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



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] congbobo184 commented on a diff in pull request #18981: [improve][client]PIP-230 Throw exception when MessageIdImpl and BatchMessageIdImpl compare with each other

Posted by GitBox <gi...@apache.org>.
congbobo184 commented on code in PR #18981:
URL: https://github.com/apache/pulsar/pull/18981#discussion_r1052827107


##########
pulsar-client/src/main/java/org/apache/pulsar/client/impl/MessageIdImpl.java:
##########
@@ -204,11 +204,13 @@ public byte[] toByteArray() {
     @Override
     public int compareTo(@Nonnull MessageId o) {
         if (o instanceof MessageIdImpl) {
+            if (o instanceof BatchMessageIdImpl) {
+                throw new UnsupportedOperationException(this.getClass().getName()

Review 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 you have decided to throw an exception, why not forbid it outright? The user may use the wrong situation, which may exceed his expectations and judgments



##########
pulsar-client/src/main/java/org/apache/pulsar/client/impl/MessageIdImpl.java:
##########
@@ -204,11 +204,13 @@ public byte[] toByteArray() {
     @Override
     public int compareTo(@Nonnull MessageId o) {
         if (o instanceof MessageIdImpl) {
+            if (o instanceof BatchMessageIdImpl) {
+                throw new UnsupportedOperationException(this.getClass().getName()

Review Comment:
   We should prohibit comparing the two types. This is not the correct behavior for users. In what scenario will they compare BatchMessageId and MessageId? Now that you have decided to throw an exception, why not forbid it outright? The user may use the wrong situation, which may exceed his expectations and judgments



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] congbobo184 commented on a diff in pull request #18981: [improve][client]PIP-230 Throw exception when MessageIdImpl and BatchMessageIdImpl compare with each other

Posted by GitBox <gi...@apache.org>.
congbobo184 commented on code in PR #18981:
URL: https://github.com/apache/pulsar/pull/18981#discussion_r1052827107


##########
pulsar-client/src/main/java/org/apache/pulsar/client/impl/MessageIdImpl.java:
##########
@@ -204,11 +204,13 @@ public byte[] toByteArray() {
     @Override
     public int compareTo(@Nonnull MessageId o) {
         if (o instanceof MessageIdImpl) {
+            if (o instanceof BatchMessageIdImpl) {
+                throw new UnsupportedOperationException(this.getClass().getName()

Review 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



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] congbobo184 commented on a diff in pull request #18981: [improve][client]PIP-230 Throw exception when MessageIdImpl and BatchMessageIdImpl compare with each other

Posted by GitBox <gi...@apache.org>.
congbobo184 commented on code in PR #18981:
URL: https://github.com/apache/pulsar/pull/18981#discussion_r1052829702


##########
pulsar-client/src/main/java/org/apache/pulsar/client/impl/BatchMessageIdImpl.java:
##########
@@ -71,11 +72,14 @@ public int getBatchIndex() {
     @Override
     public int compareTo(@Nonnull MessageId o) {
         if (o instanceof MessageIdImpl) {
+            if (!(o instanceof BatchMessageIdImpl)) {
+                throw new UnsupportedOperationException(this.getClass().getName()

Review Comment:
   https://github.com/apache/pulsar/blob/3177345ec4f9486993829950daa1dd9a3a75fd6f/pulsar-client/src/main/java/org/apache/pulsar/client/impl/BatchMessageIdImpl.java#L83
   
   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



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] github-actions[bot] commented on pull request #18981: [improve][client]PIP-230 Throw exception when MessageIdImpl and BatchMessageIdImpl compare with each other

Posted by github-actions.
github-actions[bot] commented on PR #18981:
URL: https://github.com/apache/pulsar/pull/18981#issuecomment-1404473336

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


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] congbobo184 commented on a diff in pull request #18981: [improve][client]PIP-230 Throw exception when MessageIdImpl and BatchMessageIdImpl compare with each other

Posted by GitBox <gi...@apache.org>.
congbobo184 commented on code in PR #18981:
URL: https://github.com/apache/pulsar/pull/18981#discussion_r1052827107


##########
pulsar-client/src/main/java/org/apache/pulsar/client/impl/MessageIdImpl.java:
##########
@@ -204,11 +204,13 @@ public byte[] toByteArray() {
     @Override
     public int compareTo(@Nonnull MessageId o) {
         if (o instanceof MessageIdImpl) {
+            if (o instanceof BatchMessageIdImpl) {
+                throw new UnsupportedOperationException(this.getClass().getName()

Review 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



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] github-actions[bot] commented on pull request #18981: [improve][client]PIP-230 Throw exception when MessageIdImpl and BatchMessageIdImpl compare with each other

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #18981:
URL: https://github.com/apache/pulsar/pull/18981#issuecomment-1543179277

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


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] liangyepianzhou commented on a diff in pull request #18981: [improve][client]PIP-230 Throw exception when MessageIdImpl and BatchMessageIdImpl compare with each other

Posted by GitBox <gi...@apache.org>.
liangyepianzhou commented on code in PR #18981:
URL: https://github.com/apache/pulsar/pull/18981#discussion_r1052807610


##########
pulsar-client/src/main/java/org/apache/pulsar/client/impl/BatchMessageIdImpl.java:
##########
@@ -71,11 +72,14 @@ public int getBatchIndex() {
     @Override
     public int compareTo(@Nonnull MessageId o) {
         if (o instanceof MessageIdImpl) {
+            if (!(o instanceof BatchMessageIdImpl)) {
+                throw new UnsupportedOperationException(this.getClass().getName()

Review 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.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] congbobo184 commented on a diff in pull request #18981: [improve][client]PIP-230 Throw exception when MessageIdImpl and BatchMessageIdImpl compare with each other

Posted by GitBox <gi...@apache.org>.
congbobo184 commented on code in PR #18981:
URL: https://github.com/apache/pulsar/pull/18981#discussion_r1052827107


##########
pulsar-client/src/main/java/org/apache/pulsar/client/impl/MessageIdImpl.java:
##########
@@ -204,11 +204,13 @@ public byte[] toByteArray() {
     @Override
     public int compareTo(@Nonnull MessageId o) {
         if (o instanceof MessageIdImpl) {
+            if (o instanceof BatchMessageIdImpl) {
+                throw new UnsupportedOperationException(this.getClass().getName()

Review Comment:
   We should prohibit comparing the two types. This is not the correct behavior for users. In what scenario will they compare BatchMessageId and MessageId? Now that you have decided to throw an exception, why not just forbid it?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] github-actions[bot] commented on pull request #18981: [improve][pip-230] Throw exception when MessageIdImpl and BatchMessageIdImpl compare with each other

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #18981:
URL: https://github.com/apache/pulsar/pull/18981#issuecomment-1357294315

   @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 -->
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] congbobo184 commented on a diff in pull request #18981: [improve][client]PIP-230 Throw exception when MessageIdImpl and BatchMessageIdImpl compare with each other

Posted by GitBox <gi...@apache.org>.
congbobo184 commented on code in PR #18981:
URL: https://github.com/apache/pulsar/pull/18981#discussion_r1057235435


##########
pulsar-client/src/main/java/org/apache/pulsar/client/impl/BatchMessageIdImpl.java:
##########
@@ -140,4 +151,16 @@ public BatchMessageAcker getAcker() {
         return acker;
     }
 
+    static int messageIdCompare(
+            long ledgerId1, long entryId1, int partitionIndex1, int batchIndex1,
+            long ledgerId2, long entryId2, int partitionIndex2, int batchIndex2
+    ) {
+        return ComparisonChain.start()
+                .compare(ledgerId1, ledgerId2)

Review Comment:
   goog point! I think we can use raw java code
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] mattisonchao commented on a diff in pull request #18981: [PIP-230][improve] Throw exception when MessageIdImpl and BatchMessageIdImpl compare with each other

Posted by GitBox <gi...@apache.org>.
mattisonchao commented on code in PR #18981:
URL: https://github.com/apache/pulsar/pull/18981#discussion_r1052180651


##########
pulsar-client/src/main/java/org/apache/pulsar/client/impl/MessageIdImpl.java:
##########
@@ -204,11 +204,13 @@ public byte[] toByteArray() {
     @Override
     public int compareTo(@Nonnull MessageId o) {
         if (o instanceof MessageIdImpl) {
+            if (o instanceof BatchMessageIdImpl) {
+                throw new UnsupportedOperationException(this.getClass().getName()

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



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] eolivelli commented on a diff in pull request #18981: [improve][client]PIP-230 Throw exception when MessageIdImpl and BatchMessageIdImpl compare with each other

Posted by GitBox <gi...@apache.org>.
eolivelli commented on code in PR #18981:
URL: https://github.com/apache/pulsar/pull/18981#discussion_r1056808187


##########
pulsar-client/src/main/java/org/apache/pulsar/client/impl/BatchMessageIdImpl.java:
##########
@@ -140,4 +151,16 @@ public BatchMessageAcker getAcker() {
         return acker;
     }
 
+    static int messageIdCompare(
+            long ledgerId1, long entryId1, int partitionIndex1, int batchIndex1,
+            long ledgerId2, long entryId2, int partitionIndex2, int batchIndex2
+    ) {
+        return ComparisonChain.start()
+                .compare(ledgerId1, ledgerId2)

Review 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



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] poorbarcode commented on pull request #18981: [improve][client]PIP-230 Throw exception when MessageIdImpl and BatchMessageIdImpl compare with each other

Posted by "poorbarcode (via GitHub)" <gi...@apache.org>.
poorbarcode commented on PR #18981:
URL: https://github.com/apache/pulsar/pull/18981#issuecomment-1501514465

   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`


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] liangyepianzhou commented on a diff in pull request #18981: [feat][client][pip-230] Throw exception when MessageIdImpl and BatchMessageIdImpl compare with each other

Posted by GitBox <gi...@apache.org>.
liangyepianzhou commented on code in PR #18981:
URL: https://github.com/apache/pulsar/pull/18981#discussion_r1052807610


##########
pulsar-client/src/main/java/org/apache/pulsar/client/impl/BatchMessageIdImpl.java:
##########
@@ -71,11 +72,14 @@ public int getBatchIndex() {
     @Override
     public int compareTo(@Nonnull MessageId o) {
         if (o instanceof MessageIdImpl) {
+            if (!(o instanceof BatchMessageIdImpl)) {
+                throw new UnsupportedOperationException(this.getClass().getName()

Review Comment:
   If we use the way of throwing exceptions then maybe `illegalArgumentException` will be better here when the BatchMessageID and MessageID have the same ledger ID and entry ID.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] codelipenghui commented on a diff in pull request #18981: [feat][client][pip-230] Throw exception when MessageIdImpl and BatchMessageIdImpl compare with each other

Posted by GitBox <gi...@apache.org>.
codelipenghui commented on code in PR #18981:
URL: https://github.com/apache/pulsar/pull/18981#discussion_r1052801279


##########
pulsar-client/src/main/java/org/apache/pulsar/client/impl/MessageIdImpl.java:
##########
@@ -204,11 +204,13 @@ public byte[] toByteArray() {
     @Override
     public int compareTo(@Nonnull MessageId o) {
         if (o instanceof MessageIdImpl) {
+            if (o instanceof BatchMessageIdImpl) {
+                throw new UnsupportedOperationException(this.getClass().getName()

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



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org