GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [fix][ml] Fix asyncReadEntries might never complete if empty entries are read from BK by BewareMyPower · Pull Request #24515 · apache/pulsar

Conversation

@BewareMyPower

@BewareMyPower BewareMyPower commented Jul 15, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Main Issue: #24497

Motivation

When the OpReadEntry#readEntriesComplete is triggered by RangeEntryCacheImpl#readFromStorage with an empty list of entries, NPE will happen here:

pulsar/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/OpReadEntry.java

Line 95 in bc5b933

? cursor.getNextAvailablePosition(lastPosition) : lastPosition.getNext();

Then updateReadPosition and checkReadCompletion will be skipped, where the result is very similar to #24497 (comment)

  • The callback of asyncReadEntries will never complete
  • The entriesReadCount will be updated but the readPosition won't
  • pendingReadOps will not be reduced to 0

Unfortunately, from the existing analysis, the issue of 24497 might not be caused by this bug, but this NPE is still possible.

Modifications

Remove the confusing lastPosition argument in internalReadEntriesComplete. It's only set when all entries have been filtered out and it needs to reset the readPosition in ManagedLedgerImpl#internalReadFromLedger. It can be replaced by a simple combination of updateReadPosition and checkReadCompletion.

In internalReadEntriesComplete, just call checkReadCompletion when no entries are read to trigger another round of read.

In addition, catch exceptions when triggering user-provided callback and print logs with better information. Without this change, the exception will be caught by SingleThreadTask#safeRunTask and the log will be Error while running task: that does not have description for a specific cursor or read position.

Verifying this change

Make EntryCache configurable in tests add add testReadNoEntries to verify that the asyncReadEntries will eventually succeed even if one read operation returns an empty entry list.

Documentation

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

Matching PR in forked repository

PR in forked repository:

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@BewareMyPower
[fix][ml] Fix asyncReadEntries might never complete if empty entries …
e5289ca
…are read from BK
@github-actions github-actions Bot added the doc-not-needed Your PR changes do not impact docs label Jul 15, 2025
@BewareMyPower
BewareMyPower requested review from Demogorgon314, RobertIndie, Technoboy-, codelipenghui, lhotari, nodece and poorbarcode July 15, 2025 14:58
@BewareMyPower BewareMyPower self-assigned this Jul 15, 2025
@BewareMyPower BewareMyPower added release/3.0.13 release/4.0.6 release/3.3.8 labels Jul 15, 2025
dao-jun
dao-jun approved these changes Jul 15, 2025
View reviewed changes

@dao-jun dao-jun left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

LGTM

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
lhotari
lhotari reviewed Jul 15, 2025
View reviewed changes
Comment thread managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/OpReadEntry.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

@BewareMyPower
Code style change
780a0d2
@BewareMyPower

BewareMyPower commented Jul 16, 2025

Copy link
Copy Markdown
Contributor Author

testScan failed after this change, mark it as drafted first

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@BewareMyPower
BewareMyPower marked this pull request as draft July 16, 2025 02:24
@BewareMyPower BewareMyPower added type/bug The PR fixed a bug or issue reported a bug area/ML labels Jul 16, 2025
@BewareMyPower
Fix testScan
4d4dbda
@BewareMyPower
BewareMyPower marked this pull request as ready for review July 16, 2025 02:58
@BewareMyPower BewareMyPower added the ready-to-test label Jul 16, 2025
@codecov-commenter

codecov-commenter commented Jul 16, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 69.23077% with 20 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.31%. Comparing base (bbc6224) to head (5515e1a).
⚠️ Report is 1266 commits behind head on master.

Files with missing lines Patch % Lines
...rg/apache/bookkeeper/mledger/impl/OpReadEntry.java 62.26% 15 Missing and 5 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##             master   #24515      +/-   ##
============================================
+ Coverage     73.57%   74.31%   +0.74%     
+ Complexity    32624    32552      -72     
============================================
  Files          1877     1869       -8     
  Lines        139502   146089    +6587     
  Branches      15299    16760    +1461     
============================================
+ Hits         102638   108569    +5931     
+ Misses        28908    28900       -8     
- Partials       7956     8620     +664     
Flag Coverage Δ
inttests 26.69% <23.07%> (+2.11%) ⬆️
systests 23.28% <35.38%> (-1.04%) ⬇️
unittests 73.81% <69.23%> (+0.97%) ⬆️

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

Files with missing lines Coverage Δ
...kkeeper/mledger/impl/ManagedLedgerFactoryImpl.java 59.50% <100.00%> (-21.89%) ⬇️
...che/bookkeeper/mledger/impl/ManagedLedgerImpl.java 81.47% <100.00%> (+0.80%) ⬆️
...keeper/mledger/impl/cache/RangeEntryCacheImpl.java 63.86% <ø> (+5.11%) ⬆️
...rg/apache/bookkeeper/mledger/impl/OpReadEntry.java 74.81% <62.26%> (-9.50%) ⬇️

... and 1097 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.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@BewareMyPower

BewareMyPower commented Jul 16, 2025

Copy link
Copy Markdown
Contributor Author

@lhotari Could you take a look again?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

lhotari
lhotari reviewed Jul 16, 2025
View reviewed changes

@lhotari lhotari left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I forgot to submit these minor comments earlier.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

BewareMyPower reacted with eyes emoji
All reactions
  • 👀 1 reaction
Comment thread managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/OpReadEntry.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/OpReadEntry.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

@BewareMyPower
Move recycle() back to try block
2d00fb0
poorbarcode
poorbarcode reviewed Jul 17, 2025
View reviewed changes
Comment thread managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerFactoryImpl.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/OpReadEntry.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/OpReadEntry.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/OpReadEntry.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/OpReadEntry.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

BewareMyPower added 2 commits July 17, 2025 21:02
@BewareMyPower
Improve logs
eed4ff1
@BewareMyPower
Simplify code
d62290c
poorbarcode
poorbarcode approved these changes Jul 18, 2025
View reviewed changes
@BewareMyPower
Merge branch 'master' into bewaremypower/ml-read-stuck
5515e1a
@BewareMyPower
BewareMyPower merged commit eea7c13 into apache:master Jul 19, 2025
@BewareMyPower
BewareMyPower deleted the bewaremypower/ml-read-stuck branch July 19, 2025 04:26
lhotari pushed a commit that referenced this pull request Jul 22, 2025
@BewareMyPower @lhotari
[fix][ml] Fix asyncReadEntries might never complete if empty entries …
f1974aa
…are read from BK (#24515)

(cherry picked from commit eea7c13)
@lhotari lhotari added the cherry-picked/branch-4.0 label Jul 22, 2025
lhotari pushed a commit that referenced this pull request Jul 23, 2025
@BewareMyPower @lhotari
[fix][ml] Fix asyncReadEntries might never complete if empty entries …
c887259
…are read from BK (#24515)

(cherry picked from commit eea7c13)
@lhotari lhotari added the cherry-picked/branch-3.0 label Jul 23, 2025
lhotari pushed a commit that referenced this pull request Jul 23, 2025
@BewareMyPower @lhotari
[fix][ml] Fix asyncReadEntries might never complete if empty entries …
d283d39
…are read from BK (#24515)

(cherry picked from commit eea7c13)
@lhotari lhotari added the cherry-picked/branch-3.3 label Jul 23, 2025
@lhotari

lhotari commented Jul 23, 2025

Copy link
Copy Markdown
Member

@BewareMyPower The "EntryCacheCreator" solution added in this PR is obsolete. There's already a way to intercept reads in Pulsar tests with PulsarMockReadHandleInterceptor.

example usage:

pulsar/managed-ledger/src/test/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerTest.java

Lines 3148 to 3156 in 86b036b

bkc.setReadHandleInterceptor(new PulsarMockReadHandleInterceptor() {
@Override
public CompletableFuture<LedgerEntries> interceptReadAsync(long ledgerId, long firstEntry, long lastEntry,
LedgerEntries entries) {
return CompletableFuture.supplyAsync(() -> {
return entries;
}, CompletableFuture.delayedExecutor(3, TimeUnit.SECONDS));
}
});

Since the changes to add the "EntryCacheCreator" collide with #24363 changes, I'd suggest that we remove the "EntryCacheCreator" and update the tests added in this PR to use PulsarMockReadHandleInterceptor. I can do a PR to handle that.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@lhotari

lhotari commented Jul 23, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

the replacement using ReadHandleInterceptor is

    bkc.setReadHandleInterceptor(new PulsarMockReadHandleInterceptor() {
            @Override
            public CompletableFuture<LedgerEntries> interceptReadAsync(long ledgerId, long firstEntry, long lastEntry,
                                                                       LedgerEntries entries) {
                if (firstRead.compareAndSet(true, false)) {
                    // LedgerEntriesImpl doesn't allow empty entries list.
                    // Implementing a dummy LedgerEntries that returns an empty list.
                    return CompletableFuture.completedFuture(new LedgerEntries() {
                        @Override
                        public org.apache.bookkeeper.client.api.LedgerEntry getEntry(long entryId) {
                            return null;
                        }

                        @Override
                        public Iterator<org.apache.bookkeeper.client.api.LedgerEntry> iterator() {
                            return EmptyIterator.INSTANCE;
                        }

                        @Override
                        public void close() {

                        }
                    });
                } else {
                    return CompletableFuture.completedFuture(entries);
                }
            }
        });
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@BewareMyPower

BewareMyPower commented Jul 23, 2025

Copy link
Copy Markdown
Contributor Author

Let me try this approach tomorrow

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@lhotari lhotari mentioned this pull request Jul 23, 2025
[improve][test] Remove EntryCacheCreator from ManagedLedgerFactoryImpl #24552
Merged
1 of 4 tasks
@lhotari

lhotari commented Jul 23, 2025

Copy link
Copy Markdown
Member

Let me try this approach tomorrow

I already submitted the PR in #24552 since I'll use that to be able to rebase and test #24363.

BewareMyPower reacted with eyes emoji
All reactions
  • 👀 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

priyanshu-ctds pushed a commit to datastax/pulsar that referenced this pull request Jul 24, 2025
@BewareMyPower @priyanshu-ctds
[fix][ml] Fix asyncReadEntries might never complete if empty entries …
7edeff7
…are read from BK (apache#24515)

(cherry picked from commit eea7c13)
(cherry picked from commit c887259)
priyanshu-ctds pushed a commit to datastax/pulsar that referenced this pull request Jul 24, 2025
@BewareMyPower @priyanshu-ctds
[fix][ml] Fix asyncReadEntries might never complete if empty entries …
c2ffd4e
…are read from BK (apache#24515)

(cherry picked from commit eea7c13)
(cherry picked from commit c887259)
priyanshu-ctds pushed a commit to datastax/pulsar that referenced this pull request Jul 24, 2025
@BewareMyPower @priyanshu-ctds
[fix][ml] Fix asyncReadEntries might never complete if empty entries …
1b81005
…are read from BK (apache#24515)

(cherry picked from commit eea7c13)
(cherry picked from commit f1974aa)
srinath-ctds pushed a commit to datastax/pulsar that referenced this pull request Jul 24, 2025
@BewareMyPower @srinath-ctds
[fix][ml] Fix asyncReadEntries might never complete if empty entries …
053d541
…are read from BK (apache#24515)

(cherry picked from commit eea7c13)
(cherry picked from commit c887259)
srinath-ctds pushed a commit to datastax/pulsar that referenced this pull request Jul 24, 2025
@BewareMyPower @srinath-ctds
[fix][ml] Fix asyncReadEntries might never complete if empty entries …
7c59568
…are read from BK (apache#24515)

(cherry picked from commit eea7c13)
(cherry picked from commit f1974aa)
nodece pushed a commit to ascentstream/pulsar that referenced this pull request Jul 28, 2025
@BewareMyPower @nodece
[fix][ml] Fix asyncReadEntries might never complete if empty entries …
7c37b75
…are read from BK (apache#24515)

(cherry picked from commit eea7c13)
nodece pushed a commit to ascentstream/pulsar that referenced this pull request Jul 28, 2025
@BewareMyPower @nodece
[fix][ml] Fix asyncReadEntries might never complete if empty entries …
75fa9ad
…are read from BK (apache#24515)

(cherry picked from commit eea7c13)
KannarFr pushed a commit to CleverCloud/pulsar that referenced this pull request Sep 22, 2025
@BewareMyPower @KannarFr
[fix][ml] Fix asyncReadEntries might never complete if empty entries …
fcf8792
…are read from BK (apache#24515)
walkinggo pushed a commit to walkinggo/pulsar that referenced this pull request Oct 8, 2025
@BewareMyPower @walkinggo
[fix][ml] Fix asyncReadEntries might never complete if empty entries …
a7db4a8
…are read from BK (apache#24515)
merlimat added a commit to dao-jun/pulsar that referenced this pull request Sep 16, 2026
@merlimat
Hand an empty batch read result over like a regular read result
dfa53e8
A batch read that returns no entries at all is completed with the empty result as-is instead of
failing, matching what a regular read returns, so the existing handling of empty reads in
OpReadEntry (apache#24515, ManagedCursorTest#testReadNoEntries) still applies. A partial result followed
by an empty batch still fails, since the full range cannot be assembled.
@merlimat merlimat mentioned this pull request Sep 16, 2026
[feat][ml] Support Bookkeeper Batch Read API #25280
Merged
1 of 10 tasks
@dragonls dragonls mentioned this pull request Oct 9, 2026
[Bug] Shared subscription stalls forever: havePendingRead=true while the cursor has no read (pendingReadOps=0, waitingReadOp=false) — the #26174 invariant, unguarded on PersistentDispatcherMultipleConsumers #26454
Open
2 of 3 tasks
dao-jun added a commit to dao-jun/pulsar that referenced this pull request Nov 26, 2026
@dao-jun
address review comment
8a31f76
A hole entry that stops being skipped while its range read is in flight
must still be released without delivery: the expected count was reduced
by the holes that the scan found, so delivering the entry could reach the
count while another range is still in flight, and completing the batch
then would advance the read position past that range's entries and drop
them.

buildRanges now records the intervals of the entries it reads through a
merged hole, and BatchReadEntriesCallback always releases those entries,
by the scan's result and not by the skip condition's current value. The
skip condition still drops the entries the scan did not skip, e.g. ones
individually deleted while the read was in flight, and the prefix walk
hops over both. An arrival that the filters emptied no longer completes
the batch while other ranges are in flight: only an empty batch from the
bookie does, as before (apache#24515).
@dao-jun dao-jun mentioned this pull request Nov 26, 2026
[improve][ml] Optimize read entries with skipCondition #22560
Merged
2 of 15 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@lhotari lhotari lhotari left review comments
@dao-jun dao-jun dao-jun approved these changes
@poorbarcode poorbarcode poorbarcode approved these changes
@Technoboy- Technoboy- Awaiting requested review from Technoboy-
@codelipenghui codelipenghui Awaiting requested review from codelipenghui
@nodece nodece Awaiting requested review from nodece
@RobertIndie RobertIndie Awaiting requested review from RobertIndie
@Demogorgon314 Demogorgon314 Awaiting requested review from Demogorgon314

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@BewareMyPower BewareMyPower

Labels

area/ML cherry-picked/branch-3.0 cherry-picked/branch-3.3 cherry-picked/branch-4.0 doc-not-needed Your PR changes do not impact docs ready-to-test release/3.0.13 release/3.3.8 release/4.0.6 type/bug The PR fixed a bug or issue reported a bug

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@BewareMyPower @codecov-commenter @lhotari @dao-jun @poorbarcode
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.