Repository navigation
[fix][ml] Wait for durable completion of duplicate ledger termination - #27282
Merged
codelipenghui merged 3 commits intoNov 10, 2026
Merged
codelipenghui merged 3 commits into
codelipenghui merged 3 commits into
Conversation
Share the in-flight termination result so concurrent callers cannot report success before the final metadata update persists. Retry failed persistence and cover delayed and failed metadata writes. Assisted-by: Codex
4 of 11 tasks
lhotari
reviewed
Nov 4, 2026
lhotari
left a comment
Member
There was a problem hiding this comment.
Thanks for tightening up the termination contract here. Sharing one in-flight future so duplicate callers only complete once the close and metadata write are durable is the right shape, and the gated regression tests are a nice touch. One point to address: the retry-after-ledger-close-failure path cannot succeed with a real BookKeeper ledger handle (inline comment).
… close failed A BookKeeper write handle's close is final even when it fails: a later close only replays the stored failure. Retrying the termination therefore opens the ledger with recovery, which fences it and closes its metadata, persists the recovered position, and keeps the recovered handle as the current ledger, as when a terminated managed ledger is reopened. The mock ledger handle now replays a failed close the same way. Assisted-by: Claude Code (Claude Opus 5.5)
…-ledger-termination-20261101
poorbarcode
approved these changes
Nov 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
A duplicate managed-ledger termination currently succeeds as soon as the ledger enters the in-memory
Terminatedstate, even if closing the writing ledger or persisting the final terminated position is still pending. The duplicate can therefore report success before termination is durable, or hide a failed termination attempt. Layout recovery that retries a parent seal needs the durable result.Modifications
PulsarMockLedgerHandlereplay a failed close likeLedgerHandle, so that tests model the real handle.This changes no API signature, wire protocol or persisted format. It can be merged independently; interrupted scalable-topic layout recovery relies on this contract.
Verifying this change
This change added tests and can be verified as follows:
./gradlew :managed-ledger:test --tests 'org.apache.bookkeeper.mledger.impl.ManagedLedgerTerminationTest' -PtestRetryCount=0 ./gradlew quickCheckThe regressions gate the real ledger-close and metadata callbacks; the original implementation reports premature duplicate success. Failure propagation, explicit retry, repeated success and recovered durable termination are also covered. With the mock replaying a failed close, the retry after a ledger-close failure fails if it closes the same handle again, and closing the managed ledger afterwards fails if the recovered handle does not replace the write handle.
Fresh validation of this branch, with retries disabled: the whole
managed-ledgertest suite (1152 tests, 0 failures/errors, 1 skipped),SchemaServiceTestand the*DelayedDeliveryTestclasses inpulsar-broker(the other users of programmed BookKeeper failures, 85 tests, 0 failures/errors),quickCheckandgit diff --checkpassed.The original five-fix combination (base
d6dbbbb16ac, combined head49d20c20179) also passed a 125-minute Docker fault soak: 85 faults across 17 classes, 108 DAG changes, and independent reconciliation of 61,039 logical successes / 61,041 physical records. That is shared integration evidence, not a standalone soak of this rebased branch, and it predates the ledger recovery on retry.Does this pull request potentially affect one of the following parts:
Termination callers now share asynchronous completion, and callbacks run outside the managed-ledger monitor.