GeezerVison is showing github.com — [fix][ml] Don't drop a durable cursor reset when an ack is queued behind it by waterWang · Pull Request #26305 · apache/pulsar
Conversation
waterWang
commented
Aug 10, 2026
•
edited by merlimat
Loading
Uh oh!
There was an error while loading. Please reload this page.
Fixes #26304
Problem
A durable cursor reset (consumer.seek(...), pulsar-admin topics reset-cursor) can be silently dropped while reporting success. Since #25047, all of the reset's state change (read position, mark-delete position, clearing the individual and batch acks) lives in the alignAcknowledgeStatusAfterPersisted runnable of its MarkDeleteEntry. Mark-delete requests are queued while a read is in flight (or while the cursor ledger is switching). internalFlushPendingMarkDeletes() then persists only the last queued entry and runs only that entry's runnable, while triggerComplete() calls the callback of every entry in the group.
So when an acknowledgment is queued behind the reset, the reset's runnable never runs, but its callback reports success. The cursor keeps its old read position, and the ack's later mark-delete position is what gets persisted, so a restart doesn't fix it.
A related path has the same result: internalMarkDelete() skips any entry behind persistentMarkDeletePosition or the in-progress persist position, again completing it without running its runnable. An earlier ack that completes before the reset is flushed re-arms persistentMarkDeletePosition, so a backward reset can be skipped too.
Example
On master, with a read held in flight on a cursor whose mark-delete position is p4:
cursor.asyncResetCursor(p0, false, resetCallback); // queued: entry R
cursor.asyncDelete(p5, deleteCallback, null); // queued behind it: entry A
// read completes -> internalFlushPendingMarkDeletes() persists getLast() == A
// -> only A's runnable runs; resetCallback.resetComplete() still fires
cursor.getReadPosition(); // p6, not p0
Change
MarkDeleteEntry records whether it is a cursor reset (resetsCursor). Only internalResetCursor passes its own runnable, and that runnable replaces the whole acknowledgment state.
internalFlushPendingMarkDeletes() persists the last queued reset if there is one, and the last entry otherwise. Entries queued behind a reset were computed from the acknowledgment state before the reset, so the reset supersedes them. Their callbacks still complete as part of the group, as before.
internalMarkDelete() never skips a reset in favor of a later persisted or in-progress position, because a reset may legitimately move backward.
- The reset's runnable records the persisted mark-delete position. Otherwise an earlier ack that completed first would leave a later
persistentMarkDeletePosition, and the acknowledgments that follow the reset would be skipped instead of persisted.
This replaces the first version of this PR, which ran the runnable of every entry in the group. That applied the reset in memory, but the queued ack's runnable then set persistentMarkDeletePosition to the ack's position, which was also the position persisted. Memory and storage disagreed, and the next acknowledgments below that position were never persisted.
Testing
ManagedCursorTest.testResetCursorIsNotDroppedByAckQueuedBehindIt holds a read, queues a reset to p0 and then an ack of p5, and releases the read. It checks the read, mark-delete and persisted positions, and that a following acknowledgment survives a reopen.
- It fails on master (
expected [3:0] but found [3:6], the reset was dropped).
- It fails with the first version of this PR (
persistentMarkDeletePosition is the ack's 3:5).
- It passes with this change.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
LGTM, could you add a test for this change.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
…cursor-reset-group-flush
…ind it
A flush of the pending mark-delete requests persisted only the last
queued entry and ran only its alignAcknowledgeStatus, so a cursor reset
with an acknowledgment queued behind it was dropped while still
reporting success. Running every entry's alignment instead left the
ack's later position as the persisted one.
Persist the queued reset itself, never skip a reset because a later
position is persisted or in progress, and record the reset position as
persisted. Add a regression test for apache#26304.
merlimat
changed the title
fix: run alignAcknowledgeStatus for every flushed entry, not just the last one
[fix][ml] Don't drop a durable cursor reset when an ack is queued behind it
Oct 21, 2026
|
@waterWang thanks for tracking this down, and for the very thorough analysis in #26304. Since the PR had been idle for a while, I pushed an update to your branch so we can get the fix in. I merged master and changed the approach.
Running every entry's alignAcknowledgeStatus() does apply the reset in memory. But the ack queued behind the reset was computed from the state before the reset, and its runnable then sets persistentMarkDeletePosition to the ack's position, which is also the position written to the cursor ledger. Memory and storage then disagree: a restart goes back to the ack's position, and later acks below it are skipped instead of persisted. So the flush now persists the queued reset itself. A reset is also never skipped by the "persisted/in-progress position is later" guards (the second path described in the issue).
I added the regression test you sketched in the issue (testResetCursorIsNotDroppedByAckQueuedBehindIt). It fails on master, fails with the previous version of this PR, and passes now. I also updated the title to the [fix][ml] convention, which was failing the title check, and replaced the description. Please take a look and let me know if you see any problem with it.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Nov 21, 2026
Reviewers
merlimat
merlimat approved these changes
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|