GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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

@waterWang waterWang commented Aug 10, 2026 •
edited by merlimat
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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.

All reactions
@waterWang
fix: run alignAcknowledgeStatus for every flushed entry, not just the…
a87ca15
… last one (apache#26304)
@nodece

nodece commented Aug 11, 2026

Copy link
Copy Markdown
Member

LGTM, could you add a test for this change.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

merlimat added 2 commits October 21, 2026 16:26
@merlimat
Merge remote-tracking branch 'apache/master' into mmerli/adopt-26305-…
c68c2b1
…cursor-reset-group-flush
@merlimat
[fix][ml] Persist a queued cursor reset instead of the ack queued beh…
da639da
…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 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
@merlimat

merlimat commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

merlimat
merlimat approved these changes Oct 21, 2026
View reviewed changes
@merlimat merlimat added this to the 5.1.0 milestone Oct 21, 2026
@merlimat
merlimat merged commit 33e9b0e into apache:master Oct 22, 2026
44 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@merlimat merlimat mentioned this pull request Oct 22, 2026
[fix][ml] Prevent a durable cursor reset from being silently discarded by concurrent mark-deletes #26318
Closed
10 tasks
lhotari pushed a commit that referenced this pull request Oct 22, 2026
@merlimat @lhotari
[fix][ml] Don't drop a durable cursor reset when an ack is queued beh…
069c0af
…ind it (#26305)

Co-authored-by: Matteo Merli <[email protected]>
(cherry picked from commit 33e9b0e)
@lhotari lhotari added release/5.0.1 cherry-picked/branch-5.0 labels Oct 22, 2026
@Denovo1998 Denovo1998 mentioned this pull request Oct 25, 2026
[fix][ml] Fix cursor reset wrongly persisting pre-reset ACKs that cause messages to be silently skipped after recovery #26973
Merged
11 tasks
This was referenced Nov 21, 2026
[improve][ci] Run CI for the 4.2.6 backports to branch-4.2 (do not merge) #27680
Closed
[improve][ci] Run CI for the 4.2.6 backports to branch-4.2 (do not merge) #27681
Closed
[improve][ci] Run CI for the 4.2.6 backports to branch-4.2 (do not merge) #27684
Closed
@lhotari lhotari added cherry-picked/branch-4.2 release/4.2.6 cherry-picked/branch-4.0 release/4.0.15 labels Nov 21, 2026
poorbarcode pushed a commit to poorbarcode/pulsar that referenced this pull request Nov 26, 2026
@waterWang @merlimat @lhotari
[fix][ml] Don't drop a durable cursor reset when an ack is queued beh…
05798bf
…ind it (apache#26305)

Co-authored-by: Matteo Merli <[email protected]>
(cherry picked from commit 33e9b0e)
poorbarcode pushed a commit to poorbarcode/pulsar that referenced this pull request Nov 26, 2026
@waterWang @merlimat @lhotari
[fix][ml] Don't drop a durable cursor reset when an ack is queued beh…
7e8bb68
…ind it (apache#26305)

Co-authored-by: Matteo Merli <[email protected]>
(cherry picked from commit 33e9b0e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@merlimat merlimat merlimat approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

cherry-picked/branch-4.0 cherry-picked/branch-4.2 cherry-picked/branch-5.0 release/4.0.15 release/4.2.6 release/5.0.1

Projects

None yet

Milestone

5.1.0

Development

Successfully merging this pull request may close these issues.

[Bug] Durable cursor reset (seek / reset-cursor) can be silently discarded while reporting success when another mark-delete is queued after it

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@waterWang @nodece @merlimat @lhotari
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.