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] Preserve compaction state on ledger close failure by Denovo1998 · Pull Request #26665 · apache/pulsar

Conversation

@Denovo1998

@Denovo1998 Denovo1998 commented Sep 20, 2026 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

Motivation

StrategicTwoPhaseCompactor acknowledges the compaction subscription with the new ledger ID before closing that ledger. If closing fails after the broker has processed the acknowledgment, the failure cleanup deletes a ledger that the subscription already references.

This follows up on #26576 by fixing the publication order.

Modifications

  • Close the compacted ledger before acknowledging the compaction subscription, matching AbstractTwoPhaseCompactor.
  • If closing fails, skip the acknowledgment, attempt to delete the new ledger, and fail the compaction. The previously published ledger and cursor position remain unchanged.
  • Add a regression test to the existing CompactionConcurrencyTest. It uses a real broker and BookKeeper, persists conflicting ledger metadata to trigger a real close failure, and verifies preservation of the previous compaction state, cleanup of the failed ledger, and successful retry.
  • Use AssertJ future assertions for bounded waits and failure diagnostics, and define the compaction strategy locally in the test.

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] Preserve compaction state on ledger close failure
f4bee10
nodece
nodece reviewed Sep 21, 2026
View reviewed changes

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

Verified the ordering fix — this checks out from my side:

  • The bug is real: with ack-before-close, a close failure routes into the whenComplete cleanup which deletes a ledger the compaction subscription already references. CompactedTopicImpl's no-such-ledger fallback (lines 79-97) is evidence this failure shape is expected in practice.
  • The new order matches AbstractTwoPhaseCompactor (close at line 212, ack at line 213 there); the deviation dates back to #18195, where the phase-two chain was copied with the two steps inverted.
  • Failure-path enumeration: close failure -> unpublished ledger, delete is safe; ack failure -> closed-but-unpublished, delete is safe; flush failure path unchanged.
  • I ran CompactionConcurrencyTest locally on this branch: 2/2 pass, including the new regression test. The metadata-conflict injection through the real ledger manager is a nicely realistic way to trigger an actual BookKeeper close failure.

Two known trade-offs that predate this change (also present in AbstractTwoPhaseCompactor, so not blockers — just noting): a broker crash between close and ack leaves an orphaned closed ledger with no GC, and an ack that persists on the broker but fails the caller can still trigger deleting a published ledger. Both windows existed before; this change strictly narrows them.

Non-code nit: the PR description still has template residue (unchecked verification options, example bullets).

Review assisted by Claude Code (AI-assisted review), posted by @nodece.

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.

Comment thread ...ker/src/test/java/org/apache/pulsar/broker/service/persistent/CompactionConcurrencyTest.java Resolved

Uh oh!

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

Comment thread ...ker/src/test/java/org/apache/pulsar/broker/service/persistent/CompactionConcurrencyTest.java Resolved

Uh oh!

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

@Denovo1998
Extend CompactionConcurrencyTest for close before publish scenario.
d8404cc
@Denovo1998

Denovo1998 commented Sep 21, 2026

Copy link
Copy Markdown
Contributor Author

@nodece Okay, it has already been processed.

All reactions

Sorry, something went wrong.

Uh oh!

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

@Denovo1998
Denovo1998 requested a review from nodece September 21, 2026 11:08
nodece
nodece approved these changes Sep 22, 2026
View reviewed changes
@nodece
nodece merged commit b642e8e into apache:master Sep 22, 2026
43 checks passed

Uh oh!

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

@Denovo1998
Denovo1998 deleted the close-compacted-ledger-before-publish branch September 22, 2026 06:40
@lhotari lhotari added this to the 5.0.0 milestone Sep 23, 2026
@lhotari lhotari added release/4.2.5 release/4.0.14 labels Sep 23, 2026
lhotari pushed a commit that referenced this pull request Sep 23, 2026
@Denovo1998 @lhotari
[fix][broker] Preserve compaction state on ledger close failure (#26665)
8fd3aa1
(cherry picked from commit b642e8e)
@lhotari lhotari added the cherry-picked/branch-4.2 label Sep 23, 2026
lhotari pushed a commit that referenced this pull request Sep 23, 2026
@Denovo1998 @lhotari
[fix][broker] Preserve compaction state on ledger close failure (#26665)
00c8345
(cherry picked from commit b642e8e)
@lhotari lhotari added the cherry-picked/branch-4.0 label Sep 23, 2026
Radiancebobo pushed a commit to Radiancebobo/pulsar that referenced this pull request Oct 8, 2026
@Denovo1998 hechengbo
[fix][broker] Preserve compaction state on ledger close failure (apac…
b99df89
…he#26665)
@nodece nodece mentioned this pull request Nov 5, 2026
[fix][ml][broker][client] Sync branch-as-4.0 with apache branch-4.0 (2026-09 to 2026-11, 159 commits) ascentstream/pulsar#109
Merged
4 of 5 tasks
nodece pushed a commit to ascentstream/pulsar that referenced this pull request Nov 16, 2026
@Denovo1998 @nodece
[fix][broker] Preserve compaction state on ledger close failure (apac…
9bfb16a
…he#26665)

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

Reviewers

@nodece nodece nodece 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 release/4.0.14 release/4.2.5

Projects

None yet

Milestone

5.0.0

Development

Successfully merging this pull request may close these issues.

Uh oh!

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

3 participants

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