Skip to content

Conversation

@aditya-rajpurohit
Copy link
Contributor

@aditya-rajpurohit aditya-rajpurohit commented Jan 8, 2026

Which Issue(s) This PR Fixes(Closes)

Fixes #5538

Brief Description

This PR implements handling for the ControllerElectMaster request in ControllerRequestProcessor by adding the missing handle_elect_master logic. This enables the controller to process master election requests for broker groups, which is a core capability for ensuring high availability and automatic failover in the RocketMQ cluster.

  • Decodes ElectMasterRequestHeader from the incoming RemotingCommand
  • Forwards the request to the active controller via controller_manager.controller().elect_master(...)
  • Awaits the asynchronous controller response
  • Returns a RemotingCommand containing:
    • Newly elected master broker information
    • Success or failure status
    • Error details when election fails

How Did You Test This Change?

  • Verified that the project builds successfully using cargo build
  • Ran unit tests with cargo test to ensure no functionality was affected

Summary by CodeRabbit

  • Bug Fixes
    • Implemented master election request handling in the controller, enabling the feature to function properly instead of returning an unimplemented error.

✏️ Tip: You can customize this high-level summary in your review settings.

@rocketmq-rust-bot
Copy link
Collaborator

🔊@aditya-rajpurohit 🚀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💥.

@rocketmq-rust-robot rocketmq-rust-robot added Difficulty level/Hard Hard ISSUE feature🚀 Suggest an idea for this project. labels Jan 8, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 8, 2026

Walkthrough

The handle_elect_master method in the controller request processor has been implemented to replace the previous unimplemented placeholder. The implementation decodes the incoming ElectMasterRequestHeader, forwards it to the controller's elect_master method, and returns the response.

Changes

Cohort / File(s) Summary
Master Election Request Handler
rocketmq-controller/src/processor/controller_request_processor.rs
Added imports for RocketMQError and ElectMasterRequestHeader. Implemented handle_elect_master to decode the request header and delegate to controller_manager.controller().elect_master() for election logic.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Poem

🐰 A button once broken, now springs to life,
Master elections resolved without strife!
Request decoded, forwarded with care,
Raft consensus blooming in the air! 🌟

🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Linked Issues check ❓ Inconclusive The PR implements the handle_elect_master method stub but the changes appear incomplete based on the issue requirements; deeper validation needed on controller implementation. Verify that controller.elect_master() method is properly implemented in both RaftController and DLedgerController with full Raft consensus and ReplicasInfoManager logic as specified in issue #5538.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: implementing the ControllerElectMaster request handler as required by issue #5538.
Out of Scope Changes check ✅ Passed All changes are directly related to implementing the handle_elect_master method as specified in issue #5538; no out-of-scope modifications detected.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing touches
  • 📝 Generate docstrings

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-controller/src/processor/controller_request_processor.rs:
- Around line 317-322: The parameter named `_request` is actually used (see
`_request.decode_command_custom_header::<ElectMasterRequestHeader>()`), so
rename the function parameter from `_request` to `request` in the function
signature and update all usages (e.g., change
`_request.decode_command_custom_header` to
`request.decode_command_custom_header`) to follow Rust naming conventions and
avoid the unused-underscore meaning; ensure any pattern matches, references, and
documentation/comments in that function are updated accordingly.
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 29bfd58 and 1492c00.

📒 Files selected for processing (1)
  • rocketmq-controller/src/processor/controller_request_processor.rs
🧰 Additional context used
🧬 Code graph analysis (1)
rocketmq-controller/src/processor/controller_request_processor.rs (4)
rocketmq-remoting/src/protocol/remoting_command.rs (1)
  • request_code (710-712)
rocketmq-controller/src/heartbeat/broker_live_info.rs (1)
  • channel (108-110)
rocketmq-controller/src/controller/controller_manager.rs (1)
  • controller (620-622)
rocketmq-error/src/unified.rs (1)
  • request_header_error (471-473)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Check (fmt + clippy)
  • GitHub Check: auto-approve
🔇 Additional comments (2)
rocketmq-controller/src/processor/controller_request_processor.rs (2)

91-91: LGTM! Necessary imports added.

The imports for RocketMQError and ElectMasterRequestHeader are correctly added and used in the handle_elect_master implementation.

Also applies to: 96-96


324-332: Implementation follows the correct pattern.

The forwarding to the controller and response handling are implemented correctly. The async elect_master method with signature async fn elect_master(&self, request: &ElectMasterRequestHeader) -> RocketMQResult<Option<RemotingCommand>> is properly called, awaited, and the result is correctly propagated using the ? operator before being wrapped in Ok() for return.

Comment on lines +317 to +322
// Decode request header
let request_header = _request
.decode_command_custom_header::<ElectMasterRequestHeader>()
.map_err(|e| {
RocketMQError::request_header_error(format!("Failed to decode ElectMasterRequestHeader: {:?}", e))
})?;
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Fix parameter naming: remove underscore prefix from used parameter.

The _request parameter is actually used (lines 318-319), so the underscore prefix violates Rust's naming convention. In Rust, the underscore prefix signals that a parameter is intentionally unused to suppress compiler warnings. Since _request is used here, it should be renamed to request.

🔧 Proposed fix
 async fn handle_elect_master(
     &mut self,
     _channel: Channel,
     _ctx: ConnectionHandlerContext,
-    _request: &mut RemotingCommand,
+    request: &mut RemotingCommand,
 ) -> RocketMQResult<Option<RemotingCommand>> {
     // Decode request header
-    let request_header = _request
+    let request_header = request
         .decode_command_custom_header::<ElectMasterRequestHeader>()
         .map_err(|e| {
             RocketMQError::request_header_error(format!("Failed to decode ElectMasterRequestHeader: {:?}", e))
         })?;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Decode request header
let request_header = _request
.decode_command_custom_header::<ElectMasterRequestHeader>()
.map_err(|e| {
RocketMQError::request_header_error(format!("Failed to decode ElectMasterRequestHeader: {:?}", e))
})?;
async fn handle_elect_master(
&mut self,
_channel: Channel,
_ctx: ConnectionHandlerContext,
request: &mut RemotingCommand,
) -> RocketMQResult<Option<RemotingCommand>> {
// Decode request header
let request_header = request
.decode_command_custom_header::<ElectMasterRequestHeader>()
.map_err(|e| {
RocketMQError::request_header_error(format!("Failed to decode ElectMasterRequestHeader: {:?}", e))
})?;
🤖 Prompt for AI Agents
In @rocketmq-controller/src/processor/controller_request_processor.rs around
lines 317 - 322, The parameter named `_request` is actually used (see
`_request.decode_command_custom_header::<ElectMasterRequestHeader>()`), so
rename the function parameter from `_request` to `request` in the function
signature and update all usages (e.g., change
`_request.decode_command_custom_header` to
`request.decode_command_custom_header`) to follow Rust naming conventions and
avoid the unused-underscore meaning; ensure any pattern matches, references, and
documentation/comments in that function are updated accordingly.

@codecov
Copy link

codecov bot commented Jan 8, 2026

Codecov Report

❌ Patch coverage is 0% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 38.51%. Comparing base (0c28fd0) to head (1492c00).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
...ller/src/processor/controller_request_processor.rs 0.00% 11 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5564      +/-   ##
==========================================
- Coverage   38.54%   38.51%   -0.03%     
==========================================
  Files         816      816              
  Lines      110917   110928      +11     
==========================================
- Hits        42748    42728      -20     
- Misses      68169    68200      +31     

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

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 auto merge Difficulty level/Hard Hard ISSUE feature🚀 Suggest an idea for this project. ready to review waiting-review waiting review this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature🚀] Implement ControllerElectMaster Request Handler

3 participants