Skip to content

[fix][ml] Wait for durable completion of duplicate ledger termination - #27282

Merged
codelipenghui merged 3 commits into
apache:masterfrom
codelipenghui:penghui/fix-durable-ledger-termination-20261101
Nov 10, 2026
Merged

codelipenghui merged 3 commits into
apache:masterfrom
codelipenghui:penghui/fix-durable-ledger-termination-20261101

Conversation

@codelipenghui

@codelipenghui codelipenghui commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

A duplicate managed-ledger termination currently succeeds as soon as the ledger enters the in-memory Terminated state, 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

  • Share the in-flight termination future across callers, completing all callbacks with the same durable position or failure.
  • Keep writes rejected during termination and allow a later call to retry a failed close or metadata write.
  • Retry a failed ledger close by recovering the ledger. A BookKeeper write handle's close is final even when it fails, and later closes only replay that failure. A retry therefore opens the ledger with recovery, which fences it and closes its metadata, and persists the recovered position. The recovered handle becomes the current ledger, as when a terminated managed ledger is reopened, so closing the managed ledger does not replay the failed close either.
  • Preserve immediate completion for a termination recovered from persisted metadata, and invoke caller callbacks outside the managed-ledger monitor.
  • Make PulsarMockLedgerHandle replay a failed close like LedgerHandle, so that tests model the real handle.
  • Add gated ledger-close and metadata-write regressions, including failure propagation, retry (including recovery after a failed close, and a retried failed recovery), repeated success and reopen.

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

  • Make sure that the change passes the CI checks.

This change added tests and can be verified as follows:

./gradlew :managed-ledger:test --tests 'org.apache.bookkeeper.mledger.impl.ManagedLedgerTerminationTest' -PtestRetryCount=0
./gradlew quickCheck

The 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-ledger test suite (1152 tests, 0 failures/errors, 1 skipped), SchemaServiceTest and the *DelayedDeliveryTest classes in pulsar-broker (the other users of programmed BookKeeper failures, 85 tests, 0 failures/errors), quickCheck and git diff --check passed.

The original five-fix combination (base d6dbbbb16ac, combined head 49d20c20179) 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:

  • 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

Termination callers now share asynchronous completion, and callbacks run outside the managed-ledger monitor.

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
@codelipenghui codelipenghui added ready-to-test type/bug The PR fixed a bug or issue reported a bug labels Nov 1, 2026
@codelipenghui codelipenghui self-assigned this Nov 1, 2026
@codelipenghui codelipenghui added this to the 5.1.0 milestone Nov 1, 2026

@lhotari lhotari left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
@codelipenghui
codelipenghui merged commit b6bfce0 into apache:master Nov 10, 2026
43 checks passed
lhotari pushed a commit that referenced this pull request Nov 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants