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][broker] Prevent stale messages from surviving compaction retries by Denovo1998 · Pull Request #26664 · apache/pulsar

Conversation

@Denovo1998

@Denovo1998 Denovo1998 commented Sep 20, 2026

Copy link
Copy Markdown
Contributor

Motivation

StrategicTwoPhaseCompactor shares a batch container across compaction attempts. When flushing a batch fails, the next message can still be added to the container and remain there after the attempt terminates. A subsequent attempt can flush that stale message into its output even if phase one has already removed its key because of a tombstone, restoring a deleted key.

This follows up on #26576 by addressing batch state across attempts.

Modifications

  • Create a separate batch container for each compaction attempt, including its encryption state.
  • Discard buffered messages on failure using the compaction scheduler to serialize cleanup with the write loop.
  • Check the terminal state inside queued phase-two tasks before accessing the container.
  • Add a regression test using SharedPulsarBaseTest with a real broker and BookKeeper. Close the first compaction ledger to trigger a real write failure, publish a tombstone, and verify that retrying with the same compactor persists only the surviving key.

Verifying this change

  • Make sure that the change passes the CI checks.

(Please pick either of the following options)

This change is a trivial rework / code cleanup without any test coverage.

(or)

This change is already covered by existing tests, such as (please describe tests).

(or)

This change added tests and can be verified as follows:

(example:)

  • Added integration tests for end-to-end deployment with large payloads (10MB)
  • Extended integration test for recovery after broker failure

Does this pull request potentially affect one of the following parts:

If the box was checked, please highlight the changes

  • Dependencies (add or upgrade a dependency)
  • The public API
  • The schema
  • The default values of configurations
  • The threading model
  • The binary protocol
  • The REST endpoints
  • The admin CLI options
  • The metrics
  • Anything that affects deployment

Sorry, something went wrong.

Uh oh!

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

All reactions
@Denovo1998
[fix][broker] Prevent stale messages from surviving compaction retries
e27b5a4
void-ptr974
void-ptr974 approved these changes Sep 21, 2026
View reviewed changes
@lhotari lhotari added the release/5.0.1 label Oct 1, 2026
lhotari
lhotari approved these changes Oct 6, 2026
View reviewed changes

@lhotari lhotari left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for tracking down this retry corruption and for adding a real-broker regression test. The per-attempt container looks right to me: the key-to-position cache, crypto state and ledger were already per attempt, so the shared batch container was the one piece of state surviving a failed attempt. On the production single-thread compactor executor, the discard in doCompaction is serialized with the phase-two loop, and the isDone() re-check stops queued tasks from adding after cleanup. I found no missed callers of the changed signatures. I have one non-blocking suggestion about test coverage of the discard.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread pulsar-broker/src/main/java/org/apache/pulsar/compaction/StrategicTwoPhaseCompactor.java Resolved

Uh oh!

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

codelipenghui
codelipenghui approved these changes Oct 7, 2026
View reviewed changes
@Denovo1998
test: Verify failed compaction discards buffered batch
f1c74bf
lhotari
lhotari approved these changes Oct 14, 2026
View reviewed changes

@lhotari lhotari left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. The new commit adds the assertion that pins the discard and the scheduler comment I asked for. Both look right to me.

Sorry, something went wrong.

Uh oh!

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

All reactions
@merlimat
merlimat merged commit abc9955 into apache:master Oct 17, 2026
43 checks passed

Uh oh!

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

@merlimat merlimat added this to the 5.1.0 milestone Oct 17, 2026
lhotari pushed a commit that referenced this pull request Oct 17, 2026
@Denovo1998 @lhotari
[fix][broker] Prevent stale messages from surviving compaction retries (
4e729cb
#26664)

(cherry picked from commit abc9955)
@lhotari lhotari added cherry-picked/branch-5.0 release/4.2.6 release/4.0.15 labels Oct 17, 2026
lhotari pushed a commit that referenced this pull request Oct 20, 2026
@Denovo1998 @lhotari
[fix][broker] Prevent stale messages from surviving compaction retries (
beed1bc
#26664)

(cherry picked from commit abc9955)
lhotari pushed a commit that referenced this pull request Oct 20, 2026
@Denovo1998 @lhotari
[fix][broker] Prevent stale messages from surviving compaction retries (
9c2539a
#26664)

(cherry picked from commit abc9955)
@lhotari lhotari added the cherry-picked/branch-4.2 label Oct 20, 2026
lhotari pushed a commit to lhotari/pulsar that referenced this pull request Oct 20, 2026
@Denovo1998 @lhotari
[fix][broker] Prevent stale messages from surviving compaction retries (
e62272e
apache#26664)

(cherry picked from commit abc9955)
lhotari pushed a commit that referenced this pull request Oct 20, 2026
@Denovo1998 @lhotari
[fix][broker] Prevent stale messages from surviving compaction retries (
91abf6f
#26664)

(cherry picked from commit abc9955)
@lhotari lhotari added the cherry-picked/branch-4.0 label Oct 20, 2026
nodece pushed a commit to ascentstream/pulsar that referenced this pull request Nov 16, 2026
@Denovo1998 @nodece
[fix][broker] Prevent stale messages from surviving compaction retries (
6bef418
apache#26664)

(cherry picked from commit abc9955)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@lhotari lhotari lhotari approved these changes
@codelipenghui codelipenghui codelipenghui approved these changes
+1 more reviewer
@void-ptr974 void-ptr974 void-ptr974 approved these changes
Reviewers whose approvals may not affect merge requirements

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.

Uh oh!

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

5 participants

@Denovo1998 @lhotari @codelipenghui @void-ptr974 @merlimat
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.