Skip to content

[fix][ml] Reuse an existing termination attempt after ledger close - #27763

Merged
nodece merged 2 commits into
apache:masterfrom
void-ptr974:fix/ml-reuse-termination-after-close
Nov 27, 2026
Merged

nodece merged 2 commits into
apache:masterfrom
void-ptr974:fix/ml-reuse-termination-after-close

Conversation

@void-ptr974

Copy link
Copy Markdown
Contributor

Motivation

A caller can terminate a managed ledger, close it while the termination metadata write is still in flight, and call asyncTerminate again. After #26569, the second call immediately fails with ManagedLedgerAlreadyClosedException, even if the original write subsequently succeeds. This breaks the behavior covered by #27692, where both callers observe the same termination result.

Modifications

Remove the first of two Closed checks in asyncTerminate. A duplicate can now join a pending termination or reuse its successful result. The remaining check rejects a new attempt on a closed ledger, including a retry after a failed write.

Extend ManagedLedgerTerminationTest to cover both outcomes of the in-flight metadata write, rejection of migration during that write, and closing a ledger before its first termination request. The test verifies that the duplicate issues no second metadata write.

Verifying this change

  • On upstream master at b8716192295, both variants of duplicateTerminateAfterCloseSharesExistingAttempt failed because the duplicate had already completed exceptionally while the metadata write was paused.
  • With the fix, all 65 targeted managed-ledger tests passed with test retries disabled, including both complete termination and property-failure test classes.
  • ./gradlew quickCheck passed.

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

Check for a reusable termination future before rejecting a closed ledger so duplicate callers observe the original durable result.

Assisted-by: OpenAI Codex
Verify that callers joining a pending termination share its metadata failure, while a closed ledger rejects a fresh attempt and migration.

Assisted-by: OpenAI Codex
@namest504

Copy link
Copy Markdown
Contributor

I ran into the same failure on my PRs and bisected it to #26569: duplicateTerminateAfterCloseSharesExistingAttempt passes on 64b91d8 and fails on 67052c8. With this PR (d24d610), ManagedLedgerTerminationTest and ManagedLedgerPropertiesFailureTest pass locally with retries off.

@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.

LGTM. Thanks for tracking this down and for the clear write-up.

The early State.Closed rejection that #26569 added to asyncTerminate ran before the branch that joins an existing terminationFuture, so a duplicate terminate after close() failed even while the first metadata write was still in flight. With it removed, the order in ManagedLedgerImpl.java:1938-1948 is: fenced → recovered terminated position → join an in-flight or successful attempt → reject on Closed → start a new attempt. That restores the behavior from #27692, and the remaining Closed check still rejects a first attempt or a retry after a failed write on a closed ledger. asyncMigrate keeps its own Closed guard, and a migration that reaches a closed ledger after a successful termination fails in asyncUpdateProperties instead of hanging.

The parameterized duplicateTerminateAfterCloseSharesExistingAttempt covers both outcomes of the paused write and asserts a single metadata write, and closedLedgerRejectsFirstTermination covers the case the removed check was guarding.

@nodece
nodece merged commit 48b41f4 into apache:master Nov 27, 2026
44 checks passed
lhotari pushed a commit that referenced this pull request Nov 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants