You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by "congbobo184 (via GitHub)" <gi...@apache.org> on 2024/07/16 08:21:44 UTC

[PR] [improve][client] Add exception handle for client send error [pulsar]

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

   <!--
   ### Contribution Checklist
     
     - PR title format should be *[type][component] summary*. For details, see *[Guideline - Pulsar PR Naming Convention](https://pulsar.apache.org/contribute/develop-semantic-title/)*. 
   
     - Fill out the template below to describe the changes contributed by the pull request. That will give reviewers the context they need to do the review.
     
     - Each pull request should address only one issue, not mix up code from multiple issues.
     
     - Each commit in the pull request has a meaningful commit message
   
     - Once all items of the checklist are addressed, remove the above text and this checklist, leaving only the filled out template below.
   -->
   
   <!-- Either this PR fixes an issue, -->
   
   
   <!-- or this PR is one task of an issue -->
   
   <!-- If the PR belongs to a PIP, please add the PIP link here -->
   
   <!-- Details of when a PIP is required and how the PIP process work, please see: https://github.com/apache/pulsar/blob/master/pip/README.md -->
   
   ### Motivation
   
   - producer send messages return error will close the current cnx
   - if close the current cnx, all producers and consumers witch use this cnx will close and reconnect
   (https://github.com/apache/pulsar/blob/5c6602cbb3660a696bf960f2847aac1a2ae037d2/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ClientCnx.java#L323-L345)
   - this will influence a lot of producers and consumers
   - we only close this producer and reconnect enough, don't need to close this cnx
   
   
   ### Modifications
   
   receive send_error, close current producer connection, then it will reconnect automatically
   
   ### Verifying this change
   
   - [x] Make sure that the change passes the CI checks.
   
   *(Please pick either of the following options)*
   
   This change is a trivial rework / code cleanup without any test coverage.
   
   *(or)*
   
   This change is already covered by existing tests, such as *(please describe tests)*.
   
   *(or)*
   
   This change added tests and can be verified as follows:
   
   *(example:)*
     - *Added integration tests for end-to-end deployment with large payloads (10MB)*
     - *Extended integration test for recovery after broker failure*
   
   ### Does this pull request potentially affect one of the following parts:
   
   <!-- DO NOT REMOVE THIS SECTION. CHECK THE PROPER BOX ONLY. -->
   
   *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
   - [ ] The metrics
   - [ ] Anything that affects deployment
   
   ### Documentation
   
   <!-- DO NOT REMOVE THIS SECTION. CHECK THE PROPER BOX ONLY. -->
   
   - [ ] `doc` <!-- Your PR contains doc changes. -->
   - [ ] `doc-required` <!-- Your PR changes impact docs and you will update later -->
   - [x] `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


Re: [PR] [improve][client] Add exception handle for client send error [pulsar]

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

   LGTM. But not sure why an extra blank line between the import clauses passes the checkstyle check.


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


Re: [PR] [improve][client] Add exception handle for client send error [pulsar]

Posted by "congbobo184 (via GitHub)" <gi...@apache.org>.
congbobo184 merged PR #23038:
URL: https://github.com/apache/pulsar/pull/23038


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


Re: [PR] [improve][client] Add exception handle for client send error [pulsar]

Posted by "BewareMyPower (via GitHub)" <gi...@apache.org>.
BewareMyPower commented on code in PR #23038:
URL: https://github.com/apache/pulsar/pull/23038#discussion_r1682698924


##########
pulsar-broker/src/test/java/org/apache/pulsar/client/impl/ClientCnxTest.java:
##########
@@ -25,16 +25,21 @@
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+

Review Comment:
   ```suggestion
   import java.util.concurrent.TimeUnit;
   ```



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


Re: [PR] [improve][client] Add exception handle for client send error [pulsar]

Posted by "nodece (via GitHub)" <gi...@apache.org>.
nodece commented on code in PR #23038:
URL: https://github.com/apache/pulsar/pull/23038#discussion_r1687367318


##########
pulsar-broker/src/test/java/org/apache/pulsar/client/impl/ClientCnxTest.java:
##########
@@ -130,6 +134,50 @@ public void testClientVersion() throws Exception {
     }
 
     @Test
+    public void testCnxReceiveSendError() throws Exception {
+        final String topicOne = "persistent://" + NAMESPACE + "/testCnxReceiveSendError-one";
+        final String topicTwo = "persistent://" + NAMESPACE + "/testCnxReceiveSendError-two";
+
+        PulsarClient client = PulsarClient.builder().serviceUrl(lookupUrl.toString()).connectionsPerBroker(1).build();
+        Producer<String> producerOne = client.newProducer(Schema.STRING)
+                .topic(topicOne)
+                .create();
+        Producer<String> producerTwo = client.newProducer(Schema.STRING)
+                .topic(topicTwo)
+                .create();
+        ClientCnx cnxOne = ((ProducerImpl<?>) producerOne).getClientCnx();
+        ClientCnx cnxTwo = ((ProducerImpl<?>) producerTwo).getClientCnx();
+
+        // simulate a sending error
+        cnxOne.handleSendError(Commands.newSendErrorCommand(((ProducerImpl<?>) producerOne).producerId,
+                10, ServerError.PersistenceError, "persistent error").getSendError());
+
+        // two producer use the same cnx
+        Assert.assertEquals(cnxOne, cnxTwo);
+
+        // the cnx will not change
+        try {
+            Awaitility.await().atMost(5, TimeUnit.SECONDS).until(() ->
+                    (((ProducerImpl<?>) producerOne).getClientCnx() != null
+                            && !cnxOne.equals(((ProducerImpl<?>) producerOne).getClientCnx()))
+                            || !cnxTwo.equals(((ProducerImpl<?>) producerTwo).getClientCnx()));
+            Assert.fail();
+        } catch (Throwable e) {
+            Assert.assertTrue(e instanceof ConditionTimeoutException);
+        }
+
+        // two producer use the same cnx
+        Assert.assertEquals(((ProducerImpl<?>) producerTwo).getClientCnx(),
+                ((ProducerImpl<?>) producerOne).getClientCnx());

Review Comment:
   This check looks confusing, could you try `pollDelay`? which can meet your needs.
   
   ```suggestion
           // the cnx will not change
           Awaitility.await().pollDelay(3, TimeUnit.SECONDS)
                   .until(() -> cnxOne.equals(((ProducerImpl<?>) producerOne).getClientCnx()) && cnxTwo.equals(
                           ((ProducerImpl<?>) producerTwo).getClientCnx()));
   ```



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


Re: [PR] [improve][client] Add exception handle for client send error [pulsar]

Posted by "nodece (via GitHub)" <gi...@apache.org>.
nodece commented on code in PR #23038:
URL: https://github.com/apache/pulsar/pull/23038#discussion_r1687368123


##########
pulsar-broker/src/test/java/org/apache/pulsar/client/impl/ClientCnxTest.java:
##########
@@ -130,6 +134,50 @@ public void testClientVersion() throws Exception {
     }
 
     @Test
+    public void testCnxReceiveSendError() throws Exception {
+        final String topicOne = "persistent://" + NAMESPACE + "/testCnxReceiveSendError-one";
+        final String topicTwo = "persistent://" + NAMESPACE + "/testCnxReceiveSendError-two";
+
+        PulsarClient client = PulsarClient.builder().serviceUrl(lookupUrl.toString()).connectionsPerBroker(1).build();
+        Producer<String> producerOne = client.newProducer(Schema.STRING)
+                .topic(topicOne)
+                .create();
+        Producer<String> producerTwo = client.newProducer(Schema.STRING)
+                .topic(topicTwo)
+                .create();
+        ClientCnx cnxOne = ((ProducerImpl<?>) producerOne).getClientCnx();
+        ClientCnx cnxTwo = ((ProducerImpl<?>) producerTwo).getClientCnx();
+
+        // simulate a sending error
+        cnxOne.handleSendError(Commands.newSendErrorCommand(((ProducerImpl<?>) producerOne).producerId,
+                10, ServerError.PersistenceError, "persistent error").getSendError());
+
+        // two producer use the same cnx
+        Assert.assertEquals(cnxOne, cnxTwo);
+
+        // the cnx will not change
+        try {
+            Awaitility.await().atMost(5, TimeUnit.SECONDS).until(() ->
+                    (((ProducerImpl<?>) producerOne).getClientCnx() != null
+                            && !cnxOne.equals(((ProducerImpl<?>) producerOne).getClientCnx()))
+                            || !cnxTwo.equals(((ProducerImpl<?>) producerTwo).getClientCnx()));
+            Assert.fail();
+        } catch (Throwable e) {
+            Assert.assertTrue(e instanceof ConditionTimeoutException);
+        }
+
+        // two producer use the same cnx
+        Assert.assertEquals(((ProducerImpl<?>) producerTwo).getClientCnx(),
+                ((ProducerImpl<?>) producerOne).getClientCnx());

Review Comment:
   It has been merged.



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


Re: [PR] [improve][client] Add exception handle for client send error [pulsar]

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

   ## [Codecov](https://app.codecov.io/gh/apache/pulsar/pull/23038?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   All modified and coverable lines are covered by tests :white_check_mark:
   > Project coverage is 73.46%. Comparing base [(`bbc6224`)](https://app.codecov.io/gh/apache/pulsar/commit/bbc62245c5ddba1de4b1e7cee4ab49334bc36277?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) to head [(`60b69a4`)](https://app.codecov.io/gh/apache/pulsar/commit/60b69a4c1e44785efaae51905eba545d373207a2?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   > Report is 463 commits behind head on master.
   
   <details><summary>Additional details and impacted files</summary>
   
   
   [![Impacted file tree graph](https://app.codecov.io/gh/apache/pulsar/pull/23038/graphs/tree.svg?width=650&height=150&src=pr&token=acYqCpsK9J&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)](https://app.codecov.io/gh/apache/pulsar/pull/23038?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   
   ```diff
   @@             Coverage Diff              @@
   ##             master   #23038      +/-   ##
   ============================================
   - Coverage     73.57%   73.46%   -0.12%     
   - Complexity    32624    33500     +876     
   ============================================
     Files          1877     1915      +38     
     Lines        139502   143963    +4461     
     Branches      15299    15730     +431     
   ============================================
   + Hits         102638   105759    +3121     
   - Misses        28908    30094    +1186     
   - Partials       7956     8110     +154     
   ```
   
   | [Flag](https://app.codecov.io/gh/apache/pulsar/pull/23038/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
   |---|---|---|
   | [inttests](https://app.codecov.io/gh/apache/pulsar/pull/23038/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `27.78% <0.00%> (+3.19%)` | :arrow_up: |
   | [systests](https://app.codecov.io/gh/apache/pulsar/pull/23038/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `24.73% <0.00%> (+0.40%)` | :arrow_up: |
   | [unittests](https://app.codecov.io/gh/apache/pulsar/pull/23038/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `72.53% <100.00%> (-0.32%)` | :arrow_down: |
   
   Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
   
   | [Files](https://app.codecov.io/gh/apache/pulsar/pull/23038?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
   |---|---|---|
   | [.../java/org/apache/pulsar/client/impl/ClientCnx.java](https://app.codecov.io/gh/apache/pulsar/pull/23038?src=pr&el=tree&filepath=pulsar-client%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fpulsar%2Fclient%2Fimpl%2FClientCnx.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cHVsc2FyLWNsaWVudC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcHVsc2FyL2NsaWVudC9pbXBsL0NsaWVudENueC5qYXZh) | `71.82% <100.00%> (+0.05%)` | :arrow_up: |
   
   ... and [509 files with indirect coverage changes](https://app.codecov.io/gh/apache/pulsar/pull/23038/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   
   </details>


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