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] Close abandoned managed ledger initialization resources by Denovo1998 · Pull Request #27212 · apache/pulsar

Conversation

@Denovo1998

@Denovo1998 Denovo1998 commented Oct 29, 2026 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

Follow-up to apache/pulsar#23470.

Motivation

An open can remain pending while post-initialization cursor position updates finish, after its pending-initialization record has already been removed. Later opens cannot time out and retry it, and factory shutdown can leave the initialized instance open after stopping its scheduler. A metadata version conflict while publishing a newly created write ledger also fences initialization before ordinary close can release that unpublished handle; with BookKeeper quorum timeouts enabled, its periodic add-timeout task remains scheduled while the client is alive.

Modifications

  • Keep tracking each initialization until cursor position updates finish and the factory open future settles. Close abandoned completions and only trigger load-time offloading for a successfully published open.
  • Track when the ledger itself has initialized, so shutdown closes that instance and its cursors before stopping the scheduler, retaining the existing per-ledger shutdown timeout. Share a per-attempt close future between abandonment and shutdown so both paths wait for the original close completion.
  • Close and delete the newly created, unpublished write ledger when its ledger-list update fails with BadVersion. Close the handle before using the existing concurrency-limited deletion path. Do not delete on ambiguous errors such as a metadata timeout, because the update may already have committed.
  • Add five regression cases to ManagedLedgerBkTest using real BookKeeper and ZooKeeper. Gate delivery of a real mark-delete completion and perform a real competing metadata update; check retry/cache ownership, subsequent writes and acknowledgments, shutdown ordering, unchanged winning metadata, and cancellation of the original write handle's periodic task.

The initialization timeout now also covers post-initialization cursor-position updates. By then the abandoned instance may already have published its new write ledger and may still have a mark-delete in flight while the replacement recovers that ledger. This retains the in-flight overlap described for initializeCursors timeouts in #23470: abandonment does not cancel already-issued BookKeeper or metadata operations. General cursor cleanup after a data-ledger close failure remains outside this change.

Verifying this change

  • Make sure that the change passes the CI checks.

This change added tests and can be verified as follows:

  • Earlier verification of the original three regression cases, with their production fixes removed and the tests unchanged, failed as expected: the second open times out, shutdown leaves the instance in LedgerOpened, and the unpublished write handle retains its periodic add-timeout task.
  • The shutdown/abandonment regression fails on the original PR head (823bbf6b952): the same instance receives two close calls while delivery of the first real close completion is delayed. With the fix, it is closed once and shutdown waits until that callback is delivered.
  • With the new cleanup assertions on pre-review head 6489c2420c5, the BadVersion case fails because the unpublished ledger still exists after its handle closes. The lost-response control performs a real ZooKeeper metadata write before returning a timeout and verifies that the published ledger remains in BookKeeper.
  • After merging current master, all 41 scoped cases pass with retries disabled and zero failures, errors, or skips. This includes the retained cursor activation regressions as well as the initialization and factory shutdown cases.
  • ./gradlew quickCheck passes with an English JVM locale, matching the repository's message-based suppressions. CI validation is reported separately by the PR checks.
./gradlew :managed-ledger:test \
  --tests 'org.apache.bookkeeper.mledger.impl.ManagedLedgerBkTest.testOpenTimesOutDuringCursorPositionUpdate' \
  --tests 'org.apache.bookkeeper.mledger.impl.ManagedLedgerBkTest.testShutdownDuringCursorPositionUpdateClosesLedger' \
  --tests 'org.apache.bookkeeper.mledger.impl.ManagedLedgerBkTest.testShutdownWaitsForAbandonedInitializationClose' \
  --tests 'org.apache.bookkeeper.mledger.impl.ManagedLedgerBkTest.testInitializationMetadataConflictClosesUnpublishedWriteHandle' \
  --tests 'org.apache.bookkeeper.mledger.impl.ManagedLedgerBkTest.testInitializationMetadataWriteTimeoutKeepsPublishedLedger' \
  --tests 'org.apache.bookkeeper.mledger.impl.ManagedLedgerFactoryTest' \
  --tests 'org.apache.bookkeeper.mledger.impl.ManagedLedgerFactoryShutdownTest' \
  --tests 'org.apache.bookkeeper.mledger.impl.ManagedLedgerTest.testFencedManagedLedgerAfterAdd' \
  --tests 'org.apache.bookkeeper.mledger.impl.ManagedLedgerTest.testCloseManagedLedgerAfterRollover' \
  --tests 'org.apache.bookkeeper.mledger.impl.ManagedLedgerTest.testCreateDataLedgerTimeout' \
  --tests 'org.apache.bookkeeper.mledger.impl.ManagedLedgerBkTest.testActivationPreservesConcurrentSeek' \
  --tests 'org.apache.bookkeeper.mledger.impl.ManagedLedgerBkTest.testActiveSeekDoesNotWaitForLifecycleMonitor' \
  --tests 'org.apache.bookkeeper.mledger.impl.ManagedLedgerBkTest.testActivationIgnoresDelayedReadPositionUpdate' \
  --tests 'org.apache.bookkeeper.mledger.impl.ManagedLedgerBkTest.testDelayedReadPositionUpdateReconcilesConcurrentSeek' \
  -PtestRetryCount=0 -PtestFailFast=false -PtestMaxParallelForks=1 --max-workers=1 --no-parallel
./gradlew quickCheck --max-workers=1 --no-parallel \
  -Dorg.gradle.jvmargs='-Xmx2g -Xss2m -XX:+UseG1GC -Duser.language=en -Duser.country=US'

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

Sorry, something went wrong.

Uh oh!

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

All reactions
Denovo1998 added 2 commits October 28, 2026 19:38
@Denovo1998
[fix][ml] Close abandoned managed ledger initialization resources
823bbf6
@Denovo1998
[fix][ml] Close abandoned managed ledger initialization resources
6489c24
merlimat
merlimat approved these changes Oct 30, 2026
View reviewed changes

@merlimat merlimat left a comment

Copy link
Copy Markdown
Contributor

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.

The gaps are real on master.

  • initializeComplete drops the pending entry before maybeUpdateCursorBeforeTrimmingConsumedLedger() finishes, so neither the open timeout nor shutdown can claim that window.
  • A BadVersion while publishing the new write ledger fences the instance, and fenced asyncClose never closes that handle.

Sharing one close future between abandonment and shutdown looks right, given that asyncClose reports success as soon as the state is Closed. Two small points inline.

FYI, #27215 touches the same block (they merge cleanly), and #27205 adds tests at the same spot in ManagedLedgerBkTest.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerImpl.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/ManagedLedgerFactoryImpl.java Resolved

Uh oh!

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

codelipenghui
codelipenghui approved these changes Oct 30, 2026
View reviewed changes

@codelipenghui codelipenghui left a comment

Copy link
Copy Markdown
Contributor

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.

Reviewed head 6489c24. No actionable findings identified within the reviewed scope. All 23 focused lifecycle tests passed, and the three original failures were reproduced with the production fixes removed and tests unchanged.

Sorry, something went wrong.

Uh oh!

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

All reactions
Denovo1998 added 2 commits November 1, 2026 09:56
@Denovo1998
[fix][ml] Close abandoned managed ledger initialization resources
a1afc37
@Denovo1998
[fix][ml] Close abandoned managed ledger initialization resources
4750237
dao-jun
dao-jun approved these changes Nov 1, 2026
View reviewed changes
@codelipenghui
codelipenghui merged commit 0eba160 into apache:master Nov 2, 2026
44 checks passed

Uh oh!

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

lhotari pushed a commit that referenced this pull request Nov 2, 2026
@Denovo1998 @lhotari
[fix][ml] Close abandoned managed ledger initialization resources (#2…
d0af865
…7212)

(cherry picked from commit 0eba160)
@lhotari lhotari added release/5.0.2 cherry-picked/branch-5.0 labels Nov 2, 2026
This was referenced Nov 21, 2026
[improve][ci] Run CI for the 4.2.6 backports to branch-4.2 (do not merge) #27680
Closed
[improve][ci] Run CI for the 4.2.6 backports to branch-4.2 (do not merge) #27681
Closed
[improve][ci] Run CI for the 4.2.6 backports to branch-4.2 (do not merge) #27684
Closed
@lhotari lhotari added cherry-picked/branch-4.2 release/4.2.6 cherry-picked/branch-4.0 release/4.0.15 labels Nov 21, 2026
@carlsverre carlsverre mentioned this pull request Nov 25, 2026
[Bug] Topic partition backlog grows after bookies restart when using ExtensibleLoadManagerImpl #23908
Open
2 of 3 tasks
poorbarcode pushed a commit to poorbarcode/pulsar that referenced this pull request Nov 26, 2026
@Denovo1998 @lhotari
[fix][ml] Close abandoned managed ledger initialization resources (ap…
cdab8c4
…ache#27212)

(cherry picked from commit 0eba160)
poorbarcode pushed a commit to poorbarcode/pulsar that referenced this pull request Nov 26, 2026
@Denovo1998 @lhotari
[fix][ml] Close abandoned managed ledger initialization resources (ap…
ebb37f3
…ache#27212)

(cherry picked from commit 0eba160)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@merlimat merlimat merlimat approved these changes
@codelipenghui codelipenghui codelipenghui approved these changes
@dao-jun dao-jun dao-jun approved these changes

Uh oh!

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

Assignees

No one assigned

Labels

cherry-picked/branch-4.0 cherry-picked/branch-4.2 cherry-picked/branch-5.0 release/4.0.15 release/4.2.6 release/5.0.2

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

@Denovo1998 @merlimat @codelipenghui @dao-jun @lhotari
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.