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

[PR] When sending a message, pulsar verifies the logic of recordSequenceId… [pulsar]

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

   … > highestSequenceId.
   
   <!--
   ### 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, -->
   
   Fixes #21886 
   
   <!-- or this PR is one task of an issue -->
   
   Main Issue: #21886 
   
   <!-- If the PR belongs to a PIP, please add the PIP link here -->
   
   PIP: #xyz 
   
   <!-- 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
   
   This is a question I had after reading the pulsar source code. I’m not sure if it’s a real problem.
   
   In function org.apache.pulsar.broker.service.ServerCnx#handleSend#line 1838,There is a logic to verify sequenceId, the code is as follows:
   
   ```java
   // Persist the message
   if (send.hasHighestSequenceId() && send.getSequenceId() <= send.getHighestSequenceId()) {
       producer.publishMessage(send.getProducerId(), send.getSequenceId(), send.getHighestSequenceId(),
               headersAndPayload, send.getNumMessages(), send.isIsChunk(), send.isMarker(), position);
   } else {
       producer.publishMessage(send.getProducerId(), send.getSequenceId(), headersAndPayload,
               send.getNumMessages(), send.isIsChunk(), send.isMarker(), position);
   }
   ```
   
   
   ### Modifications
   
   I find `org.apache.pulsar.broker.service.Producer#publishMessage` function makes a judgment of `lowestSequenceId > highestSequenceId`:
   ```java
   public void publishMessage(long producerId, long lowestSequenceId, long highestSequenceId,
               ByteBuf headersAndPayload, long batchSize, boolean isChunked, boolean isMarker, Position position) {
           if (lowestSequenceId > highestSequenceId) {
   ```
   so  `org.apache.pulsar.broker.service.ServerCnx#handleSend` function can be changed to:
   ```java
   // Persist the message
   if (send.hasHighestSequenceId()) {
       producer.publishMessage(send.getProducerId(), send.getSequenceId(), send.getHighestSequenceId(),
               headersAndPayload, send.getNumMessages(), send.isIsChunk(), send.isMarker(), position);
   } else {
       producer.publishMessage(send.getProducerId(), send.getSequenceId(), headersAndPayload,
               send.getNumMessages(), send.isIsChunk(), send.isMarker(), position);
   }
   ```
   
   ### Verifying this change
   
   - [ ] 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 -->
   - [ ] `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] [fix] [broker] When sending a message, broker don't verifies the logic of recordSequenceId > highestSequenceId. [pulsar]

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


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java:
##########
@@ -1835,7 +1835,7 @@ protected void handleSend(CommandSend send, ByteBuf headersAndPayload) {
                 ? PositionImpl.get(send.getMessageId().getLedgerId(), send.getMessageId().getEntryId()) : null;
 
         // Persist the message
-        if (send.hasHighestSequenceId() && send.getSequenceId() <= send.getHighestSequenceId()) {
+        if (send.hasHighestSequenceId()) {

Review Comment:
   It does not make sense without adding a test to show which issue it fixes.
   
   IMO, the original code is just defensive programming that handles the exceptional case that `sequence_id` > `highest_sequence_id` when the client constructs the `CommandSend` request. Though with the correct implementation, the client should not set a sequence id that is greater than the highest sequence 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


Re: [PR] [fix] [broker] When sending a message, broker don't verifies the logic of recordSequenceId > highestSequenceId. [pulsar]

Posted by "luky116 (via GitHub)" <gi...@apache.org>.
luky116 closed pull request #21887: [fix] [broker] When sending a message, broker don't verifies the logic of recordSequenceId > highestSequenceId.
URL: https://github.com/apache/pulsar/pull/21887


-- 
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] When sending a message, broker don't verifies the logic of recordSequenceId > highestSequenceId. [pulsar]

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

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


Re: [PR] [fix] [broker] When sending a message, broker don't verifies the logic of recordSequenceId > highestSequenceId. [pulsar]

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


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java:
##########
@@ -1835,7 +1835,7 @@ protected void handleSend(CommandSend send, ByteBuf headersAndPayload) {
                 ? PositionImpl.get(send.getMessageId().getLedgerId(), send.getMessageId().getEntryId()) : null;
 
         // Persist the message
-        if (send.hasHighestSequenceId() && send.getSequenceId() <= send.getHighestSequenceId()) {
+        if (send.hasHighestSequenceId()) {

Review Comment:
   get it,thank you



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