[do not merge] [branch-2.9] just reproduce issue: ledgers lost #18661
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.
Motivation
In PR #17526, we know that a
topiccan be closed multiple times and that it is possible to have two same-named objects of classPersistenttopicin the samebrokerinstance.We know that closing the
topictriggers the closure of theManagedLedger. Thetopicobject can be closed multiple times which means theManagedLedgercan be closed multiple times. This PR is used to prove: If aManagedLedgeris closed more than once, and switchedledgerHandleoperation ofManagedLedgerand method closed executed concurrently, there will be two of the same-namedManagedledgerin the same broker, possibly with different numbers of cursors.If both Managedledgers are available and there are different numbers of cursors, this can cause the operation
trimLedgersto delete too many ledgers from the meta ofManagedLedger.Here is the process:
managedLedger_1.closeswitch ledgerHandle(managedLedger_1)create managedLedger_2create managedLedger_3LedgerHandleLedgerHandleClosedmanagedLedger_1fromManagedFactory.ledgersLedgerHandleLedgerOpenedmanagedLedger_2managedLedger_2toManagedFactory.ledgersmanagedLedger_2fromManagedFactory.ledgerscursor_1intomanagedLedger_2managedLedger_3managedLedger_3toManagedFactory.ledgerscursor_1from metacursor_2intomanagedLedger_3cursor_1cursor_1,cursor_2How to reproduce
Run the test
LedgerLostTest.testConcurrentCloseLedgerAndSwitchLedgerDocumentation
docdoc-requireddoc-not-neededdoc-completeMatching PR in forked repository
PR in forked repository: