Skip to content

[ISSUE #6450][Enhancement✨] Remove useless code from pull_message_processor.rs#6524

Merged
mxsm merged 6 commits intomxsm:mainfrom
oopscompiled:issue-6450
Feb 27, 2026
Merged

[ISSUE #6450][Enhancement✨] Remove useless code from pull_message_processor.rs#6524
mxsm merged 6 commits intomxsm:mainfrom
oopscompiled:issue-6450

Conversation

@oopscompiled
Copy link
Contributor

@oopscompiled oopscompiled commented Feb 26, 2026

Which Issue(s) This PR Fixes(Closes)

Brief Description

How Did You Test This Change?

Summary by CodeRabbit

  • Bug Fixes

    • Improved message pull offset handling to ensure consistent processing when end offsets are determined.
    • Adjusted topic-not-found warning behavior so warnings are only emitted when allowed.
  • Refactor

    • Simplified integer encoding iteration for clearer, equivalent behavior.
    • Optimized rebalancing iteration to use key-based traversal with no user-visible changes.
    • Streamlined CLI config extraction internals without altering output.

Copilot AI review requested due to automatic review settings February 26, 2026 11:03
@rocketmq-rust-bot
Copy link
Collaborator

🔊@oopscompiled 🚀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 26, 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

Simplified end-offset handling in broker pull logic and minor refactors: iterator-pattern changes in utilities and map iteration, guarded match patterns for specific response codes, and extraction refactor in admin CLI. No public API signature changes.

Changes

Cohort / File(s) Summary
Broker pull-message logic
rocketmq-broker/src/processor/pull_message_processor.rs
Removed a redundant condition around request_header.max_msg_nums in rewrite_request_for_static_topic; when mapping_item.check_if_end_offset_decided() is true, end-offset handling and max_msg_nums assignment execute unconditionally.
Broker response handling
rocketmq-broker/src/out_api/broker_outer_api.rs, rocketmq-broker/src/processor/default_pull_message_result_handler.rs
Replaced some match arms with guarded patterns to emit warnings only when flags allow (TopicNotExist, PullNotFound), preserving prior control flow while consolidating guards.
Utility integer/short write refactor
rocketmq-common/src/utils/util_all.rs
Refactored write_int and write_short to use zipped iterators over positions and shifts instead of mutating a local index; behavior and public signatures unchanged.
Consumer re-balance iteration
rocketmq-client/src/consumer/consumer_impl/re_balance/rebalance_impl.rs
Switched two HashMap traversals from iter() to keys() to iterate only message-queue keys while keeping filtering logic intact.
Admin CLI config extraction
rocketmq-tools/rocketmq-admin/rocketmq-admin-core/src/cli/commands/get_namesrv_config_command.rs
Changed inner-map extraction to consume values via into_values() and flatten rather than iterating (k,v) pairs; resulting HashMap<String,String> unchanged.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • mxsm
  • TeslaRustor
  • SpaceXCN

Poem

🐰 I hopped through code with nimble paws,
I trimmed a check without a cause.
I zipped the bits, I pruned the keys,
Quiet fixes, gentle breeze.
Carrots crunch for tiny laws.

🚥 Pre-merge checks | ✅ 2 | ❌ 3

❌ Failed checks (2 warnings, 1 inconclusive)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning Changes to five additional files (util_all.rs, rebalance_impl.rs, broker_outer_api.rs, default_pull_message_result_handler.rs, get_namesrv_config_command.rs) appear to be scope-creep refactoring changes unrelated to the stated objective of removing useless code from pull_message_processor.rs. Separate the refactoring changes into distinct PRs or update the PR title and linked issue to reflect all changes included in this commit.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Linked Issues check ❓ Inconclusive The PR addresses the objective from linked issue #6450 by removing useless code from pull_message_processor.rs, though only one file change directly matches the issue scope while other files contain unrelated refactoring changes. Clarify whether the refactoring changes in other files (util_all.rs, rebalance_impl.rs, broker_outer_api.rs, default_pull_message_result_handler.rs, get_namesrv_config_command.rs) are part of issue #6450's scope or should be separated into different PRs.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main change—removing useless code from pull_message_processor.rs—and aligns with the primary modification in the changeset.

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

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

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

Copilot AI left a comment

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 removes a commented-out code fragment from pull_message_processor.rs that was checking if request_header.max_msg_nums.is_some() in a conditional statement. The commented-out condition is unnecessary because max_msg_nums is defined as a non-optional i32 field (marked with #[required]) in the PullMessageRequestHeader struct, meaning it cannot be None and the check would never compile.

Changes:

  • Removed commented-out condition /* && request_header.max_msg_nums.is_some() */ from the if statement on line 230

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

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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
rocketmq-broker/src/processor/pull_message_processor.rs (1)

230-234: ⚠️ Potential issue | 🟠 Major

Prevent i64 -> i32 truncation in max_msg_nums clamp

Line 232 uses as i32 on an offset span without bounds checking. Both end_offset and start_offset are i64, so if the span exceeds i32::MAX (~2.1 billion), the cast silently truncates and produces an invalid max_msg_nums (potentially negative), breaking pull behavior on large queues.

🛠️ Suggested fix
         if mapping_item.check_if_end_offset_decided() {
-            request_header.max_msg_nums = std::cmp::min(
-                (mapping_item.end_offset - mapping_item.start_offset) as i32,
-                request_header.max_msg_nums,
-            );
+            let span = mapping_item
+                .end_offset
+                .saturating_sub(mapping_item.start_offset);
+            let span_i32 = i32::try_from(span).unwrap_or(i32::MAX);
+            request_header.max_msg_nums = span_i32.min(request_header.max_msg_nums);
         }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@rocketmq-broker/src/processor/pull_message_processor.rs` around lines 230 -
234, The span calculation for max_msg_nums casts (mapping_item.end_offset -
mapping_item.start_offset) as i32 which can overflow/truncate; instead compute
the span in i64 using
mapping_item.end_offset.saturating_sub(mapping_item.start_offset), clamp it to
i32::MAX (and to zero) and then convert to i32 safely before taking the min with
request_header.max_msg_nums; update the block around
mapping_item.check_if_end_offset_decided() to use the saturating_sub result, cap
it to i32::MAX, convert to i32, and then set request_header.max_msg_nums =
std::cmp::min(clamped_span_i32, request_header.max_msg_nums) so no silent
truncation or negative values occur (refer to mapping_item.end_offset,
mapping_item.start_offset, and request_header.max_msg_nums).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@rocketmq-broker/src/processor/pull_message_processor.rs`:
- Around line 230-234: The span calculation for max_msg_nums casts
(mapping_item.end_offset - mapping_item.start_offset) as i32 which can
overflow/truncate; instead compute the span in i64 using
mapping_item.end_offset.saturating_sub(mapping_item.start_offset), clamp it to
i32::MAX (and to zero) and then convert to i32 safely before taking the min with
request_header.max_msg_nums; update the block around
mapping_item.check_if_end_offset_decided() to use the saturating_sub result, cap
it to i32::MAX, convert to i32, and then set request_header.max_msg_nums =
std::cmp::min(clamped_span_i32, request_header.max_msg_nums) so no silent
truncation or negative values occur (refer to mapping_item.end_offset,
mapping_item.start_offset, and request_header.max_msg_nums).

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7616f22 and 3da645a.

📒 Files selected for processing (1)
  • rocketmq-broker/src/processor/pull_message_processor.rs

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.

🧹 Nitpick comments (1)
rocketmq-common/src/utils/util_all.rs (1)

214-220: Consider applying the same refactor to write_short for consistency.

The write_short function still uses the old pattern with mutable current_pos. For consistency with write_int, consider refactoring it similarly.

♻️ Suggested refactor for consistency
 pub fn write_short(buffer: &mut [char], pos: usize, value: i16) {
-    let mut current_pos = pos;
-    for move_bits in (0..=12).rev().step_by(4) {
-        buffer[current_pos] = HEX_ARRAY[((value >> move_bits) & 0xF) as usize];
-        current_pos += 1;
+    for (current_pos, move_bits) in (pos..).zip((0..=12).rev().step_by(4)) {
+        buffer[current_pos] = HEX_ARRAY[((value >> move_bits) & 0xF) as usize];
     }
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@rocketmq-common/src/utils/util_all.rs` around lines 214 - 220, The
write_short function uses a mutable current_pos while write_int was refactored
for immutability; update write_short (function write_short) to mirror write_int
by removing current_pos and writing into buffer at pos + i (or equivalent) using
an iterator/enumerate over the 4 nybbles (move_bits 12,8,4,0), computing
HEX_ARRAY[((value >> move_bits) & 0xF) as usize] for each index so the function
is consistent and avoids the mutable position variable.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@rocketmq-common/src/utils/util_all.rs`:
- Around line 214-220: The write_short function uses a mutable current_pos while
write_int was refactored for immutability; update write_short (function
write_short) to mirror write_int by removing current_pos and writing into buffer
at pos + i (or equivalent) using an iterator/enumerate over the 4 nybbles
(move_bits 12,8,4,0), computing HEX_ARRAY[((value >> move_bits) & 0xF) as usize]
for each index so the function is consistent and avoids the mutable position
variable.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3da645a and 0f2b98b.

📒 Files selected for processing (1)
  • rocketmq-common/src/utils/util_all.rs

@codecov
Copy link

codecov bot commented Feb 26, 2026

Codecov Report

❌ Patch coverage is 9.52381% with 19 lines in your changes missing coverage. Please review.
✅ Project coverage is 42.15%. Comparing base (7616f22) to head (7554ba2).
⚠️ Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
...c/processor/default_pull_message_result_handler.rs 0.00% 9 Missing ⚠️
...onsumer/consumer_impl/re_balance/rebalance_impl.rs 0.00% 4 Missing ⚠️
rocketmq-broker/src/out_api/broker_outer_api.rs 0.00% 3 Missing ⚠️
...ore/src/cli/commands/get_namesrv_config_command.rs 0.00% 2 Missing ⚠️
...tmq-broker/src/processor/pull_message_processor.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6524      +/-   ##
==========================================
- Coverage   42.16%   42.15%   -0.01%     
==========================================
  Files         946      946              
  Lines      132145   132140       -5     
==========================================
- Hits        55714    55708       -6     
- Misses      76431    76432       +1     

☔ 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
Owner

@mxsm mxsm left a comment

Choose a reason for hiding this comment

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

LGTM

@mxsm mxsm merged commit cbf6b97 into mxsm:main Feb 27, 2026
7 of 12 checks passed
@rocketmq-rust-bot rocketmq-rust-bot added approved PR has approved and removed ready to review waiting-review waiting review this PR labels Feb 27, 2026
@oopscompiled oopscompiled deleted the issue-6450 branch February 27, 2026 10:33
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.

[Enhancement✨] Remove useless code from pull_message_processor.rs

5 participants