Repository navigation
[fix][ml] Reuse an existing termination attempt after ledger close - #27763
Conversation
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
lhotari
left a comment
There was a problem hiding this comment.
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.
Motivation
A caller can terminate a managed ledger, close it while the termination metadata write is still in flight, and call
asyncTerminateagain. After #26569, the second call immediately fails withManagedLedgerAlreadyClosedException, 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
Closedchecks inasyncTerminate. 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
ManagedLedgerTerminationTestto 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
b8716192295, both variants ofduplicateTerminateAfterCloseSharesExistingAttemptfailed because the duplicate had already completed exceptionally while the metadata write was paused../gradlew quickCheckpassed.Does this pull request potentially affect one of the following parts?