GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||
GeezerVison is showing github.com — [fix][ml] Fix cached read handle leaks when closing read-only managed ledgers by void-ptr974 · Pull Request #26816 · apache/pulsar Conversation
|
|
Thanks @Denovo1998 and @lhotari for the detailed reviews. I've pushed
The focused managed-ledger and broker tests pass locally, as does Could you please take another look when convenient? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Reviewed head 401ff9c. No actionable findings identified within the reviewed scope.
Focused validation passed: 18 managed-ledger tests and 1 snapshot-recovery lifecycle test. The scoped cleanup and factory/caller close wiring look sound.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Preserve the expectedReadCount read overload alongside read-only ledger handle cleanup, and add a regression for count propagation. Assisted-by: Codex
Register handle promises before IO, invalidate failed handles by identity, and release cached and temporary resources across close, initialization, and executor failures. Track read-only opens through shutdown, give factory cursors ownership, and dispose isolated entry caches and unreturned entries. Assisted-by: Codex
Release late read-only ledgers and entries after a snapshot recovery wait times out or is interrupted. Preserve the recovery result when cleanup fails, and cover delayed resources and close failures. Assisted-by: Codex
Detach the source watcher immediately after the close gate is claimed, independently of pending BookKeeper or cursor close callbacks. Run the cleanup without holding the managed-ledger monitor and cover a delayed current-handle close. Assisted-by: Codex
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Reviewed head f31fa58. No actionable findings identified within the reviewed scope.
The merge preserves expectedReadCount forwarding and the previously reviewed cleanup behavior. All 23 focused tests passed. The new regression test also failed when forwarding was deliberately removed and passed after restoration.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks for working through the earlier points; each one is addressed.
ReadOnlyManagedLedger.asyncClose() now exists with a no-op default, ReadOnlyManagedLedgerImplWrapper.asyncClose() delegates to the implementation, and SnapshotSegmentAbortedTxnProcessorImpl.readSegmentEntries closes the ledger in a finally, so the production path now releases the cached handles. testFactoryWrapperCloseReleasesCachedHandle goes through the factory API, and SnapshotSegmentAbortedTxnProcessorCloseTest verifies the close call. The race test is deterministic, and the handle-count baseline is now taken after initialize().
Two small, non-blocking notes.
First, testCloseRejectsHandleInsertedAfterCloseStarts pins the failed-future return of the recheck in getLedgerHandle, but not its invalidateReadHandle call. The test pauses inside newOpenLedgerOp(), which runs under the map's write lock, so close's scan waits for the insertion and releases the handle itself. Deleting only the invalidateReadHandle in the recheck keeps all tests green. The window it covers (close finishing its scan before the insertion) needs a pause between the first flag check and the parent lookup. I would not block on it.
Second, a closed read-only ledger can stay the owner of the entry cache that RangeEntryCacheManagerImpl.getEntryCache registers by ledger name. ManagedLedgerFactoryImpl.close(ManagedLedger) returns early for a ledger that is not in its map, so the cache mapping is not removed. A later writable ledger with the same name reuses that cache, and RangeEntryCacheImpl.readFromStorage retries OffloadReadHandleClosedException through ml.reopenReadHandle, which now fails with ManagedLedgerAlreadyClosedException. This needs a read-only ledger to be the first opener, followed by an offloaded-ledger retry, so I consider it low risk. Removing the cache mapping in ReadOnlyManagedLedgerImpl.asyncClose would close it, if you want to.
For #26817: it also changes ReadOnlyManagedLedgerImpl and fixes the handle initialize() opens to read the last add confirmed, which bypasses ledgerCache and is not released by this PR's close. The two touch different methods, so I expect a clean merge, but whichever lands second should rebase and re-run ReadOnlyManagedLedgerHandleCloseTest.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I recommend fixing cache ownership before merge. On '8d448806bc', a focused test reproduced the earlier P2: a writable ledger’s offload retry failed because it used a closed read-only ledger. Moving only the reader’s close until after the retry made the same test pass. All 25 selected checked-in tests passed; none exercises that ownership order. The master merge also made the subclass’s close-time cache scan redundant.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Keep the shared entry cache and scope pending reads and handle retries to the managed ledger that issued the read. Preserve confirmation bounds and cover both cache allocation orders. Delegate read-handle cleanup to the parent close path and release a snapshot recovery ledger when its open finishes after the wait times out. Assisted-by: Codex
Verify that a writable ledger can reopen an offloaded handle after the same-name cache creator closes. Cover requester-specific pending read invalidation and clean up resources in the related ledger and broker tests. Assisted-by: Codex
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks for the quick turnaround on the cache-ownership follow-up.
The retry in RangeEntryCacheImpl.java:770-796 now goes through the ledger that issued the read (reader.reopenReadHandle, reader.invalidateLedgerHandle, reader.reopenLedgerHandleIfReplicated) instead of the ledger that happened to register the shared cache, so a closed read-only owner can no longer fail a writable ledger's offload retry. All production callers in ManagedLedgerImpl pass this, and pending reads are keyed by reader identity and completed on that reader's executor. OffloadPrefixReadTest.testAsyncReadEntryRetriesOffloadAfterSharedCacheOwnerCloses covers the read-only-first order through the public read API, and RangeEntryCacheOwnershipTest covers the retry, coalescing and read-boundary combinations.
ReadOnlyManagedLedgerImpl.asyncClose now only sets the flag and delegates, so the cache is drained once. Every branch of the parent's asyncClose drains (fenced, no current ledger, and the write-handle close callback even on failure), and a handle whose open finishes after the drain is closed by the parent's readHandlesReleased handling. testCloseReleasesHandleInsertedAfterCacheDrain closes the ledger inside openLedgerHandleOnCacheMiss and verifies the late handle's closeAsync, which also settles my earlier note about the recheck: it now only rejects the lookup, and the release is pinned. The snapshot recovery path also releases a ledger whose open completes after the wait timed out.
Two small, non-blocking notes.
First, the shared RangeEntryCacheImpl still keeps the first opener as ml for things other than retries: cache-miss stats go to ml.getMbean() (RangeEntryCacheImpl.java:754), and the interceptor (RangeEntryCacheImpl.java:103) and the message-metadata setting (RangeEntryCacheImpl.java:470) come from its configuration. When the first opener was a read-only ledger, a later writable ledger's cache misses are therefore counted on the closed ledger's MBean. This is not new and not a correctness problem for the snapshot case, whose read-only ledger uses the topic's own configuration, so I would leave it unless you want to follow up.
Second, the cross-reader tests in PendingReadsManagerTest and RangeEntryCacheOwnershipTest use equal or contained ranges. I did not find a test with two readers whose pending ranges only partially overlap, so dropping the reader == other.reader check in PendingReadKey.overlaps (PendingReadsManager.java:148) would likely stay green. A small test would pin it.
The PR has no CI checks reported on this head yet, so the new tests have not run in CI.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…o codex/pr26816-private-read-cache
Give independent read-only ledgers their own entry cache to retain storage retries and read limiting. Clear pending reads on close and keep the existing read signatures for writable ledgers. Assisted-by: Codex
|
Thanks @lhotari for pointing out the first-opener metrics and partial-overlap cases in In Snapshot recovery closes the reader when it finishes. The reader clears its private The regression opens the read-only ledger first and the writer second, closes the reader, and verifies that the writer can retry an expired offload handle through the public read API. Temporarily registering the read-only cache by name again reproduced |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks for reworking this. Opening each read-only ledger with its own unregistered entry cache is simpler than routing the requesting ledger through the shared cache. It also removes the ownership questions from the previous round. ManagedLedgerFactoryImpl.close still removes a named cache only when the closing ledger is the registered instance, so a reader closing can no longer affect a same-name writer. OffloadPrefixReadTest.testAsyncReadEntryRetriesOffloadWithPrivateReadOnlyCache covers the reader-first, writer-second order that failed before.
The remaining CI failure (BrokerServiceTopicDeletionTest.setup, a Mockito WrongTypeOfReturnValue while stubbing getTopicPoliciesService) is in code this PR doesn't touch. A rerun should clear it.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
… branch # Conflicts: # managed-ledger/src/test/java/org/apache/bookkeeper/mledger/impl/OffloadPrefixReadTest.java
|
The only test failure in the CI - Unit - Other job on This also reproduces on |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.