Skip to content

Conversation

@poorbarcode
Copy link
Contributor

@poorbarcode poorbarcode commented Nov 3, 2025

Motivation

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

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

Matching PR in forked repository

PR in forked repository: x

@poorbarcode poorbarcode added this to the 4.2.0 milestone Nov 3, 2025
@poorbarcode poorbarcode self-assigned this Nov 3, 2025
@poorbarcode poorbarcode added type/bug The PR fixed a bug or issue reported a bug ready-to-test release/4.1.2 release/4.0.8 labels Nov 3, 2025
@github-actions github-actions bot added the doc-not-needed Your PR changes do not impact docs label Nov 3, 2025
@lhotari lhotari requested a review from Copilot November 12, 2025 09:17
Copilot finished reviewing on behalf of lhotari November 12, 2025 09:19
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes an incorrect backlog calculation bug that occurs when resetting a subscription with negative entry IDs. The root cause was in the getNumberOfEntries method which didn't properly handle positions with negative entry IDs (e.g., -1), causing it to add a negative value to the count instead of treating it as 0.

  • Fixed getNumberOfEntries() to handle negative toPosition entry IDs
  • Added comparePositions() helper method to properly compare positions that may be invalid
  • Added test to reproduce and verify the fix

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
ManagedLedgerImpl.java Fixed getNumberOfEntries() to check if toPosition.getEntryId() < 0 before adding it to count
ManagedCursorImpl.java Added comparePositions() helper method and updated internalResetCursor() to use it for proper position comparison
SimpleProducerConsumerTest.java Added test case with two scenarios (with/without ledger trimming) to verify backlog calculation after subscription creation

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@poorbarcode poorbarcode removed the request for review from lhotari November 12, 2025 16:00
@poorbarcode poorbarcode requested a review from lhotari November 12, 2025 16:00
@codecov-commenter
Copy link

Codecov Report

❌ Patch coverage is 81.81818% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.34%. Comparing base (678db6b) to head (00dc60a).
⚠️ Report is 69 commits behind head on master.

Files with missing lines Patch % Lines
...che/bookkeeper/mledger/impl/ManagedLedgerImpl.java 79.48% 3 Missing and 5 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##             master   #24938      +/-   ##
============================================
- Coverage     74.34%   74.34%   -0.01%     
- Complexity    33496    33700     +204     
============================================
  Files          1913     1920       +7     
  Lines        149315   150282     +967     
  Branches      17331    17444     +113     
============================================
+ Hits         111012   111725     +713     
- Misses        29475    29663     +188     
- Partials       8828     8894      +66     
Flag Coverage Δ
inttests 26.31% <54.54%> (-0.79%) ⬇️
systests 22.85% <43.18%> (-0.17%) ⬇️
unittests 73.87% <81.81%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...che/bookkeeper/mledger/impl/ManagedCursorImpl.java 78.78% <100.00%> (+0.12%) ⬆️
...che/bookkeeper/mledger/impl/ManagedLedgerImpl.java 80.99% <79.48%> (-0.14%) ⬇️

... and 136 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@poorbarcode poorbarcode merged commit ed31d82 into apache:master Nov 16, 2025
98 of 100 checks passed
lhotari pushed a commit that referenced this pull request Nov 17, 2025
lhotari pushed a commit that referenced this pull request Nov 17, 2025
ganesh-ctds pushed a commit to datastax/pulsar that referenced this pull request Nov 24, 2025
(cherry picked from commit ed31d82)
(cherry picked from commit a1f4f42)
srinath-ctds pushed a commit to datastax/pulsar that referenced this pull request Nov 25, 2025
(cherry picked from commit ed31d82)
(cherry picked from commit a1f4f42)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants