Repository navigation
[fix][ml] Serialize individual ACK admission with durable cursor resets - #27693
void-ptr974 wants to merge 12 commits into
Conversation
Order ACK admission and checkpoint submission with durable cursor resets. An overlapping individual ACK can overwrite a backward reset checkpoint or lose its callback when a read is pending. Assisted-by: OpenAI Codex (GPT-6)
Resume individual ACKs after reset and keep their callbacks owned through cursor closure. Settle transaction reservations by their original ownership so a later seek cannot leave stale pending ACKs or remove a replacement reservation. Assisted-by: OpenAI Codex (GPT-6)
Keep normal ACK application and pending-ACK cleanup on the existing paths. Reconcile ordinary ACKs against the reset outcome and retry only the cursor step of a transaction commit. Assisted-by: OpenAI Codex (GPT-6)
lhotari
left a comment
There was a problem hiding this comment.
Thanks for the careful work on this race and for the detailed tests, @void-ptr974. Putting reset admission, ACK application and checkpoint submission under the pendingMarkDeleteOps monitor is a reasonable fix for #27668. The lock order (queue monitor, then cursor write lock) looks consistent with the other paths I checked.
The inline comments are mostly small. Two need attention before this leaves draft:
- The new
PersistentSubscriptionentry points skip thePulsarCompactorSubscriptionoverride. - The reset checkpoint still carries individual ACKs made before the seek. That leaves the restart scenario from the motivation open for those ACKs.
The rest are suggestions for the close and retry paths and for test robustness.
Two related issues already exist on master and are out of scope here. They might be worth follow-ups:
- A forward reset whose write fails leaves its target in
lastMarkDeleteEntryand marks the cursor dirty. A laterflush()can then advance mark-delete to the target of a reset that was reported as failed. - Closing a cursor while a read is in flight never runs the callbacks still queued in
pendingMarkDeleteOps, becausereadOperationCompleted()only flushes inState.Open.closeSettlesResetCompletionWhileReadIsPendingchecks the conflict future but not the reset future itself.
Assisted-by: Codex (GPT-6)
Keep the cursor-ledger switch barrier and order the close checkpoint after a submitted reset. Assisted-by: Codex (GPT-6)
lhotari
left a comment
There was a problem hiding this comment.
Thanks for the thorough follow-up, @void-ptr974. Commit 028faf2 covers every point from the last round:
- The reset checkpoint no longer carries ranges or batch masks from before the seek.
resetCheckpointMatchesAcknowledgmentsAfterSeekchecks this for the ledger, long-array and metadata-store forms, and also recovers from that checkpoint. PulsarCompactorSubscriptionnow overrides the batch-state entry point.- Removing the retry-after-failed-reset path also removes the wrapper default and its batch-mask concern.
- A cursor closing during the commit retry now maps to
ServiceUnitNotReadyException. testResetCursorDrainsQueuedAcknowledgmentAfterReadCountReachesZerocovers the zero-pending-read branch.- The broker tests gate only the cursor ledger.
Keeping ordinary batch ACKs apart from transaction reservations, with a generation that a successful reset bumps, is a cleaner model than the previous retry.
I have one remaining comment, on the robustness of a test in ManagedCursorResetAcknowledgmentTest.
… reset Keep the upstream reset checkpoint snapshot when serializing ACK submission and preserve range-based counting. Hold the new cursor ledger's reset response until close has entered Closing so the test exercises both operations in flight. Assisted-by: Codex (GPT-6)
Fence new ACKs when close is requested. Settle queued compaction ACKs against the shared checkpoint write and restore the previous horizon on failure. Preserve property changes while a reset waits for submission or persistence. Assisted-by: Codex (GPT-6)
Bind ACK admission to the consumer generation and refresh retained failover consumers on their connection threads. Keep ACKs available during timestamp lookup and release the reset fence on submission and disconnect failures. Assisted-by: Codex (GPT-6)
…covery Exercise receipt-less grouped ACKs after redelivery and an ACK queued on a retained Failover connection. Hold one real bookie during reset and recover the cursor through fresh BookKeeper and metadata clients. Assisted-by: Codex (GPT-6)
Keep backward seek with an explicit empty batch mask and recovery before writer close. Rely on the reset durability suite for alternate encodings and metadata fallback. Verify standby ACK ordering separately from client replay and receipt, keeping the replayed message ID assertion in the end-to-end test. Assisted-by: Codex (GPT-6)
Restore the live mark-delete position and consumed count before failing a queued compaction ACK. Otherwise a later seek can persist the advanced position alongside the previous compacted ledger after cursor ledger publication fails. Assisted-by: OpenAI Codex
lhotari
left a comment
There was a problem hiding this comment.
Thanks for the update, @void-ptr974, and for filing #27786 for the double failure callback.
closeWaitsForResetSubmittedAfterCursorLedgerSwitch now holds the reset's add response on the new cursor ledger (ManagedCursorResetAcknowledgmentTest.java:788-815). It then drains the ledger executor and checks Closing while close and reset are both pending, so the test exercises close waiting for a submitted reset.
I also went through the commits since my last review: the ACK admission tied to the consumer generation in PersistentSubscription, the close fence and the compaction checkpoint restore in ManagedCursorImpl, and the master merge, which keeps the reset checkpoint snapshot from #26973. I have no further comments on them.
Fixes #27668
Motivation
A backward seek on a durable subscription can succeed and still skip messages after the cursor reopens. For example, seeking from mark-delete position
3:4to read position3:2writes a checkpoint at3:1. An overlapping individual ACK can append a later record at3:4. Recovery from that record skips entries3:2through3:4.If a read is pending, an individual ACK can instead queue behind the reset and lose its callback. A transaction commit waiting for that ACK can then remain incomplete after seek disconnects the consumers.
Modifications
Related work
master. It determines what a reset writes to BookKeeper or the metadata-store fallback, including clearing old individual ACK ranges and persisting the batch mask supplied by the seek. This PR addresses the ordering around that checkpoint so a concurrent individual ACK cannot overwrite it or lose its callback.asyncClearBacklogloses its callback during close and leaves the broker's backlog-clear fence in place. Both PRs drain the remaining mark-delete queue on close. Here that drain must also settle ACKs left behind by a canceled reset. Whichever PR lands second can reuse the same drain and keep the regression tests for both callers.Verifying this change
69c4b15d8e1(includingmasterata602f161344), all 333 selected Managed Ledger tests and 171 selected broker tests passed locally, along with repository-widequickCheck. Coverage includes cursor recovery and takeover, close during a submitted reset, retained Failover consumers, transaction commits that overlap seek, and cursor-ledger publication failure during compaction.Does this pull request potentially affect one of the following parts?