Repository navigation
[fix][ml] Fix cursor reset wrongly persisting pre-reset ACKs that cause messages to be silently skipped after recovery - #26973
Conversation
…ring cursor reset Persist the reset target ACK snapshot with the new cursor position in BookKeeper and the Metadata Store fallback. Keep live ACK state unchanged until persistence succeeds, and checkpoint live state when rebuilding a cursor ledger after a failed reset. Cover recovery, persistence failures, fallback, rollover, and batch persistence configuration boundaries with deterministic regression tests. Assisted-by: OpenAI Codex
A concurrent close can checkpoint the reset target with stale live ACKs between the reset append and its completion callback. Wait asynchronously for reset state updates to finish before entering Closing and persisting the cursor. Resume close on reset failure as well. Start close on the ledger executor to preserve the pending-operation and cursor lock order. Cover the race, recovery, backward reset, batch ACKs, metadata fallback, queued reads, and callback reentrancy. Assisted-by: OpenAI Codex
Keep reset persistence state operation-local, publish successful reset checkpoints atomically, and preserve concurrent compaction cursor properties. Assisted-by: Codex/GPT-5
Preserve reset queue ordering, reset-owned ACK snapshots and cursor close ordering. Assisted-by: Codex (GPT-6)
Verify both close persistence backends preserve the reset position and batch bitmap when ordinary ACKs surround a queued reset. Assisted-by: Codex (GPT-6)
Denovo1998
left a comment
There was a problem hiding this comment.
The latest update addresses my previous concern about #26305. The reset ordering and persistence paths look good to me now, and the additional regression coverage is useful.
LGTM, pending CI validation.
lhotari
left a comment
There was a problem hiding this comment.
Thanks for tracking this down and for the thorough deterministic tests around reset, close and rebuild.
The core fix looks right to me. A successful reset now writes its record with the ACK state that belongs to the reset, on both the cursor-ledger path and the metadata-store path. A failed reset no longer publishes its target to lastMarkDeleteEntry, so a later dirty-cursor flush, ledger rebuild or close writes the previous, consistent state. I checked that the new tests pin this. Each of these changes, reverted on its own, makes the new tests fail:
- ignoring the reset snapshot in
serializePositionInfofailstestResetPersistsAcknowledgmentState(2 invocations) - dropping the reset-barrier wait in
internalAsyncClosefails 7ManagedCursorResetCloseRaceTestinvocations - publishing reset entries to
lastMarkDeleteEntrybefore they are persisted failstestRebuildingCursorLedgerAfterFailedResetPreservesAcknowledgmentsandtestCloseWaitingForFailedResetPreservesPreviousAcknowledgments
One thing blocks merging: CI - Unit - Other is red because of this change. ManagedCursorTest.failDuringRecoveryWithEmptyLedger and recoverCursorPropertiesWhenCursorLedgerIsEmpty fail every time on this head and pass with the base ManagedCursorImpl.java. CI only reports the first one. See the first inline comment.
The second inline comment covers a gap this PR leaves open, which is fine to handle in a follow-up.
codelipenghui
left a comment
There was a problem hiding this comment.
Request changes at unchanged head '92a21be7db'. I reproduced both empty-ledger recovery failures: publishing an ordinary ACK before the replacement cursor ledger is created changes the rollback checkpoint. This is no longer just unexplained red CI. The reset-snapshot, failed-reset, and close-ordering fixes remain sound. The separately reported in-flight individual-ACK race predates this PR and can be tracked as a follow-up.
Restore ordinary ACK checkpoint timing and reuse the captured checkpoint during cursor-ledger switches. Coordinate close with submitted resets and ledger switches, cancel queued resets when the owning ledger closes, and preserve explicit compaction property edits. Assisted-by: OpenAI Codex (GPT-6)
Carry the reset ACK snapshot only through its original write and fallback. Keep cursor close and checkpoint publication timing together for separate review, and retain the captured checkpoint used for both replacement ledger initialization and its metadata pointer. Assisted-by: OpenAI Codex (GPT-6)
lhotari
left a comment
There was a problem hiding this comment.
LGTM. Thanks for the quick turnaround on the empty-ledger recovery regression.
The blocker from my previous review is resolved. Ordinary ACKs publish to lastMarkDeleteEntry only when they are submitted again, as on master, so ManagedCursorTest.failDuringRecoveryWithEmptyLedger and recoverCursorPropertiesWhenCursorLedgerIsEmpty pass on this head. The ledger switch now writes the seed entry and the metadata record from the same captured entry (ManagedCursorImpl.java:3869-3875), and the new cursorLedgerSeedAndMetadataUseTheSameCheckpoint test fails if switchToNewLedger re-reads lastMarkDeleteEntry instead.
I ran ManagedCursorTest, the ManagedCursorReset* classes and ManagedLedgerFactoryTest locally on this head with retries disabled: no failures. I have not seen CI on this head yet, so please confirm CI - Unit - Other is green. The in-flight asyncDelete gap in the second thread stays a follow-up, as the description says.
|
@lhotari @codelipenghui Thanks for the earlier reviews. #26973 is ready for another look with a narrower scope. It persists the ACK snapshot supplied by the reset, keeps ordinary ACKs out of the recovery checkpoint until submission, and uses the same checkpoint for the replacement ledger's first record and its Metadata Store pointer. I’ll handle failed-reset checkpoint publication, compaction properties, and reset ordering during close and unload together in a follow-up PR. Cursor ledger creation failure handling will get its own PR. The two in-flight individual ACK cases, including the dropped callback, are tracked together in #27668. I’d appreciate a review of the narrowed diff. |
lhotari
left a comment
There was a problem hiding this comment.
LGTM. The narrowed scope is easier to reason about. The reset write and its metadata-store fallback now persist the reset's own ACK snapshot: no individual ranges, and only the batch ACK set carried by the reset position (ManagedCursorImpl.java:2792-2801, ManagedCursorImpl.java:3904-3922, ManagedCursorImpl.java:3393-3401). Ordinary writes keep using the live state. A rollover triggered by the reset append still waits until the reset's alignment has run, so the replacement ledger is seeded with the post-reset state. The seed and the Metadata Store pointer also share the captured checkpoint (ManagedCursorImpl.java:3696-3702). Thanks for opening #27668 and for listing the remaining close, compaction and ledger-creation cases as follow-ups.
Resolve the conflicts in ManagedCursorImpl with apache#26973: - persistPositionMetaStore now takes a reset ACK-state snapshot. Pass it to buildManagedCursorInfo, which skips the individual ACK ranges and takes the batch indexes from the snapshot, as master does. A publication persists no ACK ranges, so it passes none. - switchToNewLedger now receives the checkpoint written to the new ledger. Publish that checkpoint instead of lastMarkDeleteEntry. Assisted-by: Claude Code (Claude Opus 5.5)
Motivation
A durable cursor reset should recover with the ACK state supplied by the seek. The reset write can pair the new position with ACKs from before the seek, causing recovery to skip messages that should be replayed.
Modifications
Follow-ups
Verifying this change
quickCheckpassed locally. One configuration-dependent case skipped in the full run passed when rerun with common-pool parallelism set to 1.master(38b4615c72b), five cases went from failing to passing and nine continued to pass. The failed forward-reset rebuild case reproduced the same checkpoint error in both runs.Does this pull request potentially affect one of the following parts?