Skip to content

[fix][broker] Fix backlog clearing for unloaded namespace bundles - #25272

Merged
nodece merged 8 commits into
apache:masterfrom
zhanghaou:dev-clear-topics-backlog-in-namespace
Apr 7, 2026
Merged

[fix][broker] Fix backlog clearing for unloaded namespace bundles#25272
nodece merged 8 commits into
apache:masterfrom
zhanghaou:dev-clear-topics-backlog-in-namespace

Conversation

@zhanghaou

@zhanghaou zhanghaou commented Feb 27, 2026

Copy link
Copy Markdown
Contributor

Fixes #20706

Motivation

Clearing backlog for a namespace/bundle should work even when the bundle is not loaded on any broker.

Modifications

  1. Convert namespace backlog clear paths to async internal methods and update v1/v2 admin resources to use async-response flow consistent with existing patterns (e.g. getMaxProducersPerTopic).
  2. Ensure bundle backlog clearing can operate when bundles are unloaded by enumerating persistent topics from metadata and loading topics as needed.
  3. Add tests to verify backlog clearing on unloaded bundles (all subscriptions and per-subscription cases).

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

Documentation

  • doc
  • doc-required
  • doc-not-needed
  • doc-complete

Matching PR in forked repository

PR in forked repository:
zhanghaou#2

@lhotari lhotari left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thanks for the contribution @zhanghaou

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a bug where clearing the backlog for a namespace or namespace bundle would silently skip topics whose bundle was not owned by any broker (i.e., unloaded). It refactors four synchronous admin methods into fully-async variants and updates the core backlog clearing logic to fetch topics from metadata (instead of only in-memory loaded topics), loading them on demand when needed.

Changes:

  • Introduce internalClearNamespaceBacklogAsync, internalClearNamespaceBundleBacklogAsync, internalClearNamespaceBacklogForSubscriptionAsync, and internalClearNamespaceBundleBacklogForSubscriptionAsync (replacing their synchronous counterparts) in NamespacesBase.
  • Update v1 and v2 Namespaces REST handlers to use @Suspended AsyncResponse + the new async methods, consistent with existing async patterns (e.g., getMaxProducersPerTopic).
  • Add integration tests verifying bundle backlog clearing works on unloaded bundles (both all-subscriptions and per-subscription cases).

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
NamespacesBase.java Core logic: new async backlog-clear methods, clearBacklogAsync now queries metadata for all persistent topics and filters by bundle, with readOnly=false to allow acquiring ownership of unloaded bundles
v2/Namespaces.java REST layer updated to async response pattern for all four backlog-clear endpoints
v1/Namespaces.java Same async refactoring applied to v1 (deprecated) endpoints
AdminApiTest.java Two new parameterized integration tests verifying unloaded bundle backlog clearing (all subscriptions and per-subscription)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov-commenter

codecov-commenter commented Mar 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 65.97222% with 49 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.73%. Comparing base (735b429) to head (3f022dc).
⚠️ Report is 19 commits behind head on master.

Files with missing lines Patch % Lines
...pache/pulsar/broker/admin/impl/NamespacesBase.java 61.16% 24 Missing and 16 partials ⚠️
.../org/apache/pulsar/broker/admin/v2/Namespaces.java 74.07% 7 Missing ⚠️
...ache/pulsar/broker/namespace/NamespaceService.java 85.71% 1 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##             master   #25272      +/-   ##
============================================
- Coverage     72.97%   72.73%   -0.24%     
+ Complexity    34347    34259      -88     
============================================
  Files          1954     1954              
  Lines        154715   154732      +17     
  Branches      17704    17706       +2     
============================================
- Hits         112898   112548     -350     
- Misses        32816    33129     +313     
- Partials       9001     9055      +54     
Flag Coverage Δ
inttests 25.80% <0.00%> (-0.43%) ⬇️
systests 22.58% <0.00%> (-0.04%) ⬇️
unittests 73.71% <65.97%> (-0.24%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
.../org/apache/pulsar/broker/admin/AdminResource.java 77.32% <ø> (+0.26%) ⬆️
...ache/pulsar/broker/namespace/NamespaceService.java 73.33% <85.71%> (-0.04%) ⬇️
.../org/apache/pulsar/broker/admin/v2/Namespaces.java 91.65% <74.07%> (-0.01%) ⬇️
...pache/pulsar/broker/admin/impl/NamespacesBase.java 78.83% <61.16%> (-0.22%) ⬇️

... and 82 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@zhanghaou

Copy link
Copy Markdown
Contributor Author

Add a new method getOwnedPersistentTopicListForNamespaceBundle to reduce blocking call.

@coderzc coderzc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@coderzc

coderzc commented Mar 15, 2026

Copy link
Copy Markdown
Member

@zhanghaou Please rebase on master.

@zhanghaou
zhanghaou force-pushed the dev-clear-topics-backlog-in-namespace branch from 81019b3 to 006aa91 Compare March 16, 2026 03:07
@zhanghaou

zhanghaou commented Mar 16, 2026

Copy link
Copy Markdown
Contributor Author

@coderzc @lhotari PTAL, rebase the master and convert validation synchronous throws to failed futures in async methods. Personal CI passed.

@nodece
nodece merged commit 8e37e3e into apache:master Apr 7, 2026
54 checks passed
coderzc pushed a commit to coderzc/pulsar that referenced this pull request Apr 15, 2026
…ache#25272)

Co-authored-by: 张浩 <zhanghao60@100.me>
(cherry picked from commit 8e37e3e)
@lhotari lhotari modified the milestones: 4.2.0, 4.3.0 Apr 15, 2026
lhotari added a commit that referenced this pull request Apr 15, 2026
lhotari pushed a commit that referenced this pull request Apr 15, 2026
…5272)

Co-authored-by: 张浩 <zhanghao60@100.me>
(cherry picked from commit 8e37e3e)
lhotari pushed a commit that referenced this pull request Apr 21, 2026
…5272)

Co-authored-by: 张浩 <zhanghao60@100.me>
(cherry picked from commit 8e37e3e)
lhotari pushed a commit that referenced this pull request Apr 21, 2026
…5272)

Co-authored-by: 张浩 <zhanghao60@100.me>
(cherry picked from commit 8e37e3e)
srinath-ctds pushed a commit to datastax/pulsar that referenced this pull request Apr 23, 2026
…ache#25272)

Co-authored-by: 张浩 <zhanghao60@100.me>
(cherry picked from commit 8e37e3e)
(cherry picked from commit 24e7814)
srinath-ctds pushed a commit to datastax/pulsar that referenced this pull request Apr 23, 2026
…ache#25272)

Co-authored-by: 张浩 <zhanghao60@100.me>
(cherry picked from commit 8e37e3e)
(cherry picked from commit eb79b2d)
nodece pushed a commit to ascentstream/pulsar that referenced this pull request May 27, 2026
…ache#25272)

Co-authored-by: 张浩 <zhanghao60@100.me>
(cherry picked from commit 8e37e3e)
nodece pushed a commit to ascentstream/pulsar that referenced this pull request May 27, 2026
nodece pushed a commit to ascentstream/pulsar that referenced this pull request May 27, 2026
…ache#25272)

Co-authored-by: 张浩 <zhanghao60@100.me>
(cherry picked from commit 8e37e3e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Namespace admin cli clear-backlog can not clear unloaded topics' backlog

6 participants