Repository navigation
[fix][ml] Fix metadata listener leaks caused by unclosed temporary read handles - #26817
Conversation
Close temporary handles after initialization, LAC rechecks, offline statistics, and abandoned cursor recovery. Keep handles open until their asynchronous users finish and preserve ownership transfers. Main Issue: apache#26815 Assisted-by: OpenAI Codex
Cover synchronous cleanup and LAC failures, offline cursor empty and malformed entries, and successful cursor ownership cleanup. Assisted-by: OpenAI Codex
lhotari
left a comment
There was a problem hiding this comment.
Thanks for tracking down these leaked read handles and for the thorough test class.
I traced each changed path and found no missed close or double close on the paths this PR touches. Each countDown() still runs once. The interceptor chain is equivalent to before. The terminated ledger keeps its handle. Cursor recovery keeps the handle it hands to the recovered cursor.
I agree with the open point about failures after parseFrom() in cursor recovery. Two smaller notes are inline: one adjacent offline-statistics path that still leaves a handle open, and what the new tests can and cannot show.
Handle cursor snapshot recovery failures after decoding, close unclaimed handles, and report the original failure without re-entering callbacks. Own and close the offline backlog retry handle explicitly, releasing each read entry while preserving the iterator's LAC and failure behavior. Add regression coverage for recovery failures, offline retry boundaries, and listener registration and deregistration with real BookKeeper handles. Validation: 48 scoped tests and quickCheck pass. Reverting the cursor fix makes the two new recovery-failure cases time out on the PR head. Assisted-by: Codex
Release recovered read-only cursor ledger handles when the cursor closes, switches ledgers, or is deleted, independently of ledger metadata deletion. Preserve the existing writable-handle lifecycle and deletion retry behavior. Complete offline backlog estimation when opening a cursor ledger fails, without dereferencing the absent handle. Add regression coverage for failed cursor opens and real metadata listener cleanup when deletion fails or remains pending. Assisted-by: Codex
Keep offline cursor metadata callbacks nonblocking and aggregate backlog results on the calling thread. Release late read handles and ledger entries when the accurate-statistics fallback is interrupted. Release recovered cursor read handles when closing cannot persist metadata, while retaining the ledger for recovery. Include pending cursor recovery in managed-ledger close and reject cursor opens that complete after closure. Add controlled regression tests for metadata scheduling, close failures, late recovery, and interrupted open/read results. Assisted-by: Codex
|
I've pushed de8d977 with four follow-up fixes:
Added tests covering actual metadata callback scheduling, listener deregistration, and buffer reference counts. All 95 scoped tests passed locally with retries disabled, along with |
Merge upstream master while retaining temporary-handle ownership and pending cursor cleanup. Keep the upstream asynchronous offline backlog implementation and consolidate its best-effort recovery handle cleanup. Preserve cursor idle-state recovery and reuse an in-flight lazy recovery when concurrent opens retry a previous failure. Update regression tests for asynchronous backlog reads and atomic statistics publication. Assisted-by: Codex
lhotari
left a comment
There was a problem hiding this comment.
The two earlier points are addressed, and the read-handle ownership paths I traced all close the handle once on success, failure and interruption. Two smaller notes on the new close and cursor-open logic are inline.
Merge upstream master. Release handles from late lazy cursor recovery without waiting in managed-ledger close or modifying cursor metadata. Release recovered read handles when writer close fails, preserve the entry fencing check, and share concurrent recovery retries. Assisted-by: Codex (GPT-6.2 Sol)
Keep initialization exception handling aligned with master. Remove extra coverage of upstream offline backlog and LAC recheck logic, and use the listener lifecycle tests for overlapping close scenarios. Assisted-by: Codex (GPT-6.2)
… recovery Release local read handles when cursor metadata deletion fails. Guard eager recovery registration with the same close check as lazy recovery, and preserve Closed when a delayed metadata update fences the old ledger. Assisted-by: Codex (GPT-6.2)
lhotari
left a comment
There was a problem hiding this comment.
LGTM. Close no longer depends on pending cursor recovery, and the late-recovery paths release their handle instead. The completion-time fence check is gone. I mutation-tested each new closeReadOnlyCursorLedger() call site (removing any one makes a lifecycle test fail), so the tests do pin the behavior. One optional note on the fenced-unload path is inline.
…ad handles (apache#26817) (cherry picked from commit 3577758)
Resolve the conflicts in ManagedCursorImpl and adapt the publication path to the cursor changes on master: - apache#27703 rebuilds the cursor properties in updateCursorLedgerStat, so drop adoptStoredCursorInfo and keep only the deletion of retained ledgers there. Sample the version and the properties as one pair in publishCursorLedger as well as in persistPositionMetaStore, and pass them to buildManagedCursorInfo. - apache#27652 assigns a publication ID in MetaStoreImpl during the write. Assign it in publishCursorLedger before taking the attempted bytes, so that reconciliation still recognizes a committed publication. - apache#27671 makes a closing cursor wait for an in-flight ledger switch, so allow that switch to publish while the cursor is Closing. - apache#26817 closes the read-only cursor ledger in asyncDeleteCursorLedger; keep that next to the deletion of retained ledgers. MetaStoreImpl now calls the put overload with options, so the fault-injection stubs in ManagedCursorTest target that overload. Assisted-by: Claude Code (Claude Opus 5.5)
…ad handles (apache#26817) (cherry picked from commit 3577758)
Main Issue: #26815
Motivation
Managed-ledger initialization and cursor recovery open BookKeeper read handles that can keep metadata listeners registered after Pulsar stops using them. This can also happen when cursor metadata deletion fails or when a cursor finishes recovering after its managed ledger has closed.
Modifications
Closedwhen an in-flight metadata write later reportsBadVersion.Verifying this change
Make sure that the change passes the CI checks.
82 focused tests passed locally, along with managed-ledger Spotless and test-source Checkstyle.
The new regressions verify listener deregistration when a cursor metadata deletion fails after unload and when eager recovery succeeds after initialization fails and closes the managed ledger. They also check that the persisted cursor metadata and BookKeeper ledger are preserved.
The lazy recovery regression submits a stale metadata write after a new owner opens. It verifies that the old listener is released, the old open reports that its ledger is closed, and the new owner can still acknowledge entries.
Does this pull request potentially affect one of the following parts: