Skip to content

[ISSUE #6272] Add cleanExpiredCQ broker command with dry-run and topic scope#6311

Merged
mxsm merged 1 commit intomxsm:mainfrom
willwang-io:issue-6272
Feb 15, 2026
Merged

[ISSUE #6272] Add cleanExpiredCQ broker command with dry-run and topic scope#6311
mxsm merged 1 commit intomxsm:mainfrom
willwang-io:issue-6272

Conversation

@willwang-io
Copy link
Contributor

@willwang-io willwang-io commented Feb 13, 2026

Which Issue(s) This PR Fixes(Closes)

Brief Description

Implement cleanExpiredCQ in broker commands, including target resolution by broker, cluster, or topic route, plus dry-run preview and cleanup result summaries.

Because the current broker API only supports broker/global cleanup and returns a boolean result, topic is used only to select target brokers and detailed metrics (space freed, queues removed) are reported as unavailable.

Wire the command into broker command registration and command listing, and update the changelog.

How Did You Test This Change?

Add unit tests for:

  • CLI parsing with -b/--brokerAddr
  • CLI parsing with -c/--cluster, -t/--topic, and --dryRun
  • Parsing with no target arguments (global mode)
  • Conflict validation for -b + -c
  • Input validation rejecting empty/whitespace-only optional args (topic etc.)

Summary by CodeRabbit

  • New Features

    • Added a CLI command to clean expired consumer queues on brokers, targetable by broker address, cluster name, or topic; supports dry-run previews, global or targeted cleanup, concurrent per-target execution, and per-target summary reporting.
    • Improved input normalization and validation for CLI arguments.
  • Tests

    • Added unit tests for CLI parsing, argument validation, and input normalization.
  • Chore

    • Updated changelog with the new feature entry.

@rocketmq-rust-robot rocketmq-rust-robot added Difficulty level/Moderate Moderate difficult ISSUE feature🚀 Suggest an idea for this project. labels Feb 13, 2026
@rocketmq-rust-bot
Copy link
Collaborator

🔊@willwang-io 🚀Thanks for your contribution🎉!

💡CodeRabbit(AI) will review your code first🔥!

Note

🚨The code review suggestions from CodeRabbit are to be used as a reference only, and the PR submitter can decide whether to make changes based on their own judgment. Ultimately, the project management personnel will conduct the final code review💥.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 13, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Adds a new broker CLI command CleanExpiredCQ that scans and (optionally) removes expired ConsumeQueue entries by broker, cluster, or topic; supports dry-run previews; initializes MQAdminExt, resolves targets, performs concurrent per-target scan/cleanups, and reports aggregated results.

Changes

Cohort / File(s) Summary
Changelog
CHANGELOG.md
Added Unreleased → Added entry documenting the CleanExpiredCQ broker command.
Command Registry
rocketmq-tools/rocketmq-admin/rocketmq-admin-core/src/commands.rs
Registered cleanExpiredCQ in the command classification/print table.
Broker Commands Integration
rocketmq-tools/rocketmq-admin/rocketmq-admin-core/src/commands/broker_commands.rs
Added mod clean_expired_cq_sub_command;, imported CleanExpiredCQSubCommand, added BrokerCommands::CleanExpiredCQ(...) Clap variant, and wired its execution arm.
Command Implementation
rocketmq-tools/rocketmq-admin/rocketmq-admin-core/src/commands/broker_commands/clean_expired_cq_sub_command.rs
New module implementing CleanExpiredCQSubCommand with CLI args (brokerAddr, cluster, topic, dryRun), target resolution (broker/cluster/topic), MQAdminExt lifecycle, concurrent per-target scan and optional cleanup, dry-run support, aggregated reporting, error handling, and unit tests.

Sequence Diagram

sequenceDiagram
    participant CLI as CLI / User
    participant Cmd as CleanExpiredCQSubCommand
    participant Admin as MQAdminExt
    participant Broker as Broker RPC
    participant Report as Cleanup Report

    CLI->>Cmd: invoke (broker|cluster|topic, dryRun)
    Cmd->>Cmd: parse & normalize inputs
    Cmd->>Admin: init/start (optional RPC hook)
    Admin->>Broker: establish RPC connections
    Cmd->>Broker: resolve targets & fetch topic/route info
    alt Dry-Run
        Cmd->>Cmd: identify expired ConsumeQueues (no deletion)
        Cmd->>Report: assemble dry-run summary
    else Execute
        Cmd->>Broker: request cleanup of expired ConsumeQueues
        Broker->>Broker: remove expired CQ files/entries
        Broker->>Cmd: return per-target results
        Cmd->>Report: collect execution results
    end
    Cmd->>Admin: shutdown
    Report->>CLI: display summary
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Poem

🐇 I sniffed the queues both far and near,
A dry-run hop, then cleanup cheer!
Old ConsumeQueues tumbled from view,
Brokers lighter, logs anew —
Hooray, I nibbled a crunchy carrot too.

🚥 Pre-merge checks | ✅ 5 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 31.25% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title directly references the issue number and clearly describes the main feature being added: the cleanExpiredCQ broker command with dry-run support and topic scope.
Linked Issues check ✅ Passed The pull request implements all key requirements from issue #6272: cleanExpiredCQ command, broker/cluster/topic target resolution, dry-run mode, cleanup summaries, and proper placement in broker_commands module.
Out of Scope Changes check ✅ Passed All changes directly support the cleanExpiredCQ command feature: new command implementation, broker command registration, commands listing, changelog update, and unit tests for CLI parsing.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into main

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

No actionable comments were generated in the recent review. 🎉


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In
`@rocketmq-tools/rocketmq-admin/rocketmq-admin-core/src/commands/broker_commands/clean_expired_cq_sub_command.rs`:
- Around line 99-133: The report shows scanned_brokers as 0 in non-dry-run
global mode because resolve_targets returns an empty Vec when
broker_addr/cluster_name/topic are all None; fetch_broker_targets is only called
for dry_run. Update the logic around resolve_targets/is_global_mode so that when
is_global_mode is true you call fetch_broker_targets(default_mqadmin_ext,
None).await? to populate targets regardless of command.dry_run (or move the
fetch before constructing CleanExpiredCQReport), then build the
CleanExpiredCQReport using targets.len() so scanned_brokers reflects the actual
brokers that will be cleaned; keep the dry_run early-return behavior intact.
🧹 Nitpick comments (3)
CHANGELOG.md (1)

12-12: Consider adding the issue link for traceability.

Most other entries in this changelog reference their tracking issue (e.g., (#5650)). This entry is missing the link to #6272.

-- **feat(tools):** Add `CleanExpiredCQSubCommand` under broker commands with broker/cluster/topic target scan, dry-run preview, and cleanup summary reporting
+- **feat(tools):** Add `CleanExpiredCQSubCommand` under broker commands with broker/cluster/topic target scan, dry-run preview, and cleanup summary reporting ([`#6272`](https://github.com/mxsm/rocketmq-rust/issues/6272))
rocketmq-tools/rocketmq-admin/rocketmq-admin-core/src/commands/broker_commands/clean_expired_cq_sub_command.rs (2)

384-434: Consider adding unit tests for normalize_optional_arg edge cases and resolve_targets logic.

The current tests cover CLI parsing well but the core logic functions have no coverage. At minimum, normalize_optional_arg could be tested for None input and valid values (cheap to add). Testing resolve_targets and the cleanup flow would require mocking DefaultMQAdminExt, which can be deferred.


161-187: Unbounded concurrency for large broker sets.

join_all fires all cleanup requests concurrently with no limit. For typical deployments this is fine, but for very large clusters it could overwhelm the admin client or network. Consider using futures::stream::iter(...).buffer_unordered(N) if this becomes a concern.

@codecov
Copy link

codecov bot commented Feb 13, 2026

Codecov Report

❌ Patch coverage is 13.33333% with 260 lines in your changes missing coverage. Please review.
✅ Project coverage is 42.56%. Comparing base (8b35652) to head (58fcd3c).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...ds/broker_commands/clean_expired_cq_sub_command.rs 13.60% 254 Missing ⚠️
...rocketmq-admin/rocketmq-admin-core/src/commands.rs 0.00% 5 Missing ⚠️
...ocketmq-admin-core/src/commands/broker_commands.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6311      +/-   ##
==========================================
- Coverage   42.62%   42.56%   -0.07%     
==========================================
  Files         912      913       +1     
  Lines      128056   128356     +300     
==========================================
+ Hits        54590    54632      +42     
- Misses      73466    73724     +258     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

Copy link
Collaborator

@rocketmq-rust-bot rocketmq-rust-bot left a comment

Choose a reason for hiding this comment

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

LGTM - All CI checks passed ✅

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In
`@rocketmq-tools/rocketmq-admin/rocketmq-admin-core/src/commands/broker_commands/clean_expired_cq_sub_command.rs`:
- Around line 353-355: The current condition `is_global_mode && !dry_run` hides
the "Scope: global" label during dry-run; update the check so the label prints
whenever `is_global_mode` is true (regardless of `dry_run`) by removing the
`!dry_run` requirement around the `println!("- Scope: global");` call in the
block that currently references `is_global_mode` and `dry_run` (the branch where
`println!("- Scope: global");` is located).
🧹 Nitpick comments (1)
rocketmq-tools/rocketmq-admin/rocketmq-admin-core/src/commands/broker_commands/clean_expired_cq_sub_command.rs (1)

161-169: Concurrent cleanup fires all RPCs simultaneously.

For typical cluster sizes this is fine, but if the broker list is very large, join_all will fire every RPC at once. Consider whether a bounded concurrency approach (e.g., futures::stream::iter(...).buffer_unordered(N)) would be more appropriate for production clusters with many brokers.

@willwang-io willwang-io changed the title [Issue 6272] Add cleanExpiredCQ broker command with dry-run and topic scope [ISSUE #6272] Add cleanExpiredCQ broker command with dry-run and topic scope Feb 13, 2026
…opic scope

Implement `cleanExpiredCQ` in broker commands, including target
resolution by broker, cluster, or topic route, plus dry-run preview
and cleanup result summaries.

Because the current broker API only supports broker/global cleanup and
returns a boolean result, topic is used only to select target brokers
and detailed metrics (space freed, queues removed) are reported as
unavailable.

Wire the command into broker command registration and command listing,
and update the changelog.
Copy link
Collaborator

@rocketmq-rust-bot rocketmq-rust-bot left a comment

Choose a reason for hiding this comment

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

LGTM - All CI checks passed ✅

@mxsm mxsm merged commit 61c399e into mxsm:main Feb 15, 2026
8 of 13 checks passed
@rocketmq-rust-bot rocketmq-rust-bot added the approved PR has approved label Feb 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI review first Ai review pr first approved PR has approved auto merge Difficulty level/Moderate Moderate difficult ISSUE feature🚀 Suggest an idea for this project.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature🚀] Implement CleanExpiredCQ command in rocketmq-admin-core

4 participants

Comments