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

   ### Motivation
   - The backlog was calculated by `managedLedger.entriesAddedCounter - 
cursor.messagesConsumedCounter`
   - When resetting a subscription, the broker resets the value 
`cursor.messagesConsumedCounter` this way: `{new value} = {old value} - {how 
many positions the old value is larger than the new value}`. 
   - The method `managedLegder.getNumberOfEntries` is used to calculate the 
number between two positions, but it has a bug, which will get a larger value 
than expected if the entry ID is a negative value.
   - You can reproduce the issue by the new test
   
   - **[1]** : 
https://github.com/apache/pulsar/blob/v4.0.7/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerImpl.java#L3730C5-L3764C6
   ```java
   public long getNumberOfEntries(Range<Position> range) {
       long count = 0;
       // If the from & to are pointing to different ledgers, then we need to :
       // 1. Add the entries in the ledger pointed by toPosition
       count += toPosition.getEntryId(); // When the entry id is -1, it plush 
"-1" in mistake
       count += toIncluded ? 1 : 0;
       ...
       ...
       return count;
       }
   }
   ```
   
   ### Modifications
   
   - Fix the issue
   - Improve the method `position.comparate`
   
   ### 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: x
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to