Skip to content

[fix] Avoid negative estimated entry count #24055

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 7, 2025

Conversation

gaoran10
Copy link
Contributor

@gaoran10 gaoran10 commented Mar 5, 2025

Motivation

The estimated entry count may be a negative value in some cases, then the read operation will get an empty result.

Modifications

Add a negative check after the long value converts to an int value.

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
  • The metrics
  • Anything that affects deployment

Documentation

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

Matching PR in forked repository

PR in forked repository:

@gaoran10 gaoran10 requested a review from poorbarcode March 5, 2025 07:30
@github-actions github-actions bot added the doc-not-needed Your PR changes do not impact docs label Mar 5, 2025
@gaoran10 gaoran10 self-assigned this Mar 5, 2025
@gaoran10 gaoran10 closed this Mar 5, 2025
@gaoran10 gaoran10 reopened this Mar 5, 2025
@gaoran10 gaoran10 closed this Mar 5, 2025
@gaoran10 gaoran10 reopened this Mar 5, 2025
@lhotari
Copy link
Member

lhotari commented Mar 5, 2025

The estimated entry count may be a negative value in some cases, then the read operation will get an empty result.

@gaoran10 Just wondering how it could the result could exceed Integer.MAX_VALUE so that the integer value becomes negative in the current logic. Is it the line result += remainEntriesOfLedger; in estimateEntryCountBySize method that causes it? Could we also improve the existing logic and add some test cases to reproduce and prevent such regressions?

@gaoran10
Copy link
Contributor Author

gaoran10 commented Mar 6, 2025

Just wondering how it could the result could exceed Integer.MAX_VALUE so that the integer value becomes negative in the current logic. Is it the line result += remainEntriesOfLedger; in estimateEntryCountBySize method that causes it? Could we also improve the existing logic and add some test cases to reproduce and prevent such regressions?

You can try to use this newly added case in the test, if the bytesSize is a Long max value, the result may beyond the Integer max value.

var ml = (ManagedLedgerImpl) factory.open(mlName);
ml.addEntry(new byte[1000]);
int entryCount11 = ManagedCursorImpl.estimateEntryCountBySize(
        Long.MAX_VALUE, PositionFactory.create(ml.getCurrentLedger().getId(), 0), ml);

BewareMyPower

This comment was marked as resolved.

@BewareMyPower BewareMyPower dismissed their stale review March 6, 2025 03:28

Wrong review

@BewareMyPower
Copy link
Contributor

Add the same release/xxx labels since it's fixing the regression of #23931

@codecov-commenter
Copy link

codecov-commenter commented Mar 7, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 74.20%. Comparing base (bbc6224) to head (475af0b).
Report is 952 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##             master   #24055      +/-   ##
============================================
+ Coverage     73.57%   74.20%   +0.62%     
+ Complexity    32624     2379   -30245     
============================================
  Files          1877     1861      -16     
  Lines        139502   144214    +4712     
  Branches      15299    16434    +1135     
============================================
+ Hits         102638   107008    +4370     
+ Misses        28908    28759     -149     
- Partials       7956     8447     +491     
Flag Coverage Δ
inttests 26.65% <50.00%> (+2.07%) ⬆️
systests 23.09% <50.00%> (-1.24%) ⬇️
unittests 73.72% <100.00%> (+0.88%) ⬆️

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 79.62% <100.00%> (+0.32%) ⬆️

... and 1055 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.

@gaoran10 gaoran10 merged commit 49f6236 into apache:master Mar 7, 2025
53 checks passed
gaoran10 added a commit that referenced this pull request Mar 7, 2025
lhotari pushed a commit that referenced this pull request Mar 17, 2025
lhotari pushed a commit that referenced this pull request Mar 17, 2025
@lhotari
Copy link
Member

lhotari commented Mar 17, 2025

There was an additional regression caused by #23931 changes. I've created a PR #24089 to address it. Please review

nikhil-ctds pushed a commit to datastax/pulsar that referenced this pull request Mar 21, 2025
(cherry picked from commit 49f6236)
(cherry picked from commit a913874)
mukesh-ctds pushed a commit to datastax/pulsar that referenced this pull request Mar 21, 2025
(cherry picked from commit 49f6236)
(cherry picked from commit a913874)
nodece pushed a commit to nodece/pulsar that referenced this pull request Mar 27, 2025
nikhil-ctds pushed a commit to datastax/pulsar that referenced this pull request Mar 29, 2025
(cherry picked from commit 49f6236)
(cherry picked from commit 23fca3d)
srinath-ctds pushed a commit to datastax/pulsar that referenced this pull request Mar 31, 2025
(cherry picked from commit 49f6236)
(cherry picked from commit 23fca3d)
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.

5 participants