Skip to content

[ISSUE #3405]♻️Refactor PullMessageRequestHeader with derive marco RequestHeaderCodec #3479

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 18, 2025

Conversation

donghao526
Copy link
Contributor

@donghao526 donghao526 commented Jun 18, 2025

Which Issue(s) This PR Fixes(Closes)

Fixes #3405

Brief Description

Refactor PullMessageRequestHeader with derive marco RequestHeaderCodec

How Did You Test This Change?

run the unit tests local

Summary by CodeRabbit

  • Refactor
    • Improved internal handling of message header encoding and decoding for pull message requests, ensuring required fields are clearly marked.
  • Tests
    • Updated tests to align with the new approach for header serialization and deserialization.

Copy link
Contributor

coderabbitai bot commented Jun 18, 2025

Walkthrough

The manual implementations of CommandCustomHeader and FromMap for the PullMessageRequestHeader struct have been removed and replaced with the RequestHeaderCodec derive macro. Several struct fields are now explicitly marked as required. Test code has been minimally updated to specify the type of a map variable.

Changes

File(s) Change Summary
rocketmq-remoting/src/protocol/header/pull_message_request_header.rs Removed manual trait implementations for serialization/deserialization; added RequestHeaderCodec derive macro; marked fields as required; adjusted related imports and test typing.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant PullMessageRequestHeader
    participant MacroGeneratedCodec

    User->>PullMessageRequestHeader: Instantiate struct
    PullMessageRequestHeader->>MacroGeneratedCodec: Serialize/Deserialize (via derived methods)
    MacroGeneratedCodec-->>PullMessageRequestHeader: Resulting struct or map
Loading

Assessment against linked issues

Objective Addressed Explanation
Refactor PullMessageRequestHeader using derive macro RequestHeaderCodec (#3405)
Ensure the refactor does not introduce new bugs, update unit tests if applicable, maintain performance, document new patterns, test in different environments (#3405)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes found.

Possibly related PRs

Suggested labels

refactor♻️, rocketmq-remoting crate, Difficulty level/Easy, AI review first, ready to review

Suggested reviewers

  • TeslaRustor
  • SpaceXCN
  • mxsm

Poem

A macro hops in, so clean and neat,
Manual code now takes a backseat.
Fields marked required, no bugs in sight,
The codec derives—oh what delight!
Rusty bunnies cheer with glee,
For code that’s simple as can be.
🐇✨

✨ 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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@rocketmq-rust-bot
Copy link
Collaborator

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

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: 0

🔭 Outside diff range comments (1)
rocketmq-remoting/src/protocol/header/pull_message_request_header.rs (1)

26-63: topic_request can trigger panics – initialise or handle None safely

All TopicRequestHeaderTrait methods call self.topic_request.as_mut()/as_ref().unwrap().
With the new Default derive (and in tests) topic_request is None, so any external call to those trait methods will panic at runtime.

Option A (preferred): make the field non-optional and populate it via Default:

-#[serde(flatten)]
-pub topic_request: Option<TopicRequestHeader>,
+#[serde(flatten)]
+pub topic_request: TopicRequestHeader,

Option B: lazily create it where needed:

fn set_lo(&mut self, lo: Option<bool>) {
    self.topic_request.get_or_insert_with(Default::default).lo = lo;
}

Either way, eliminate the unconditional unwrap()s.

🧹 Nitpick comments (1)
rocketmq-remoting/src/protocol/header/pull_message_request_header.rs (1)

65-455: Delete the ~800 lines of commented-out legacy code

Keeping the entire manual codec implementation commented out bloats the file and hurts readability. The Git history already preserves it.

-// impl PullMessageRequestHeader {
-//     ...
-// }

Please remove these blocks.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9c00cdc and 13841eb.

📒 Files selected for processing (1)
  • rocketmq-remoting/src/protocol/header/pull_message_request_header.rs (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: build (windows-latest, nightly)
  • GitHub Check: build (windows-latest, stable)
  • GitHub Check: build (macos-latest, stable)
  • GitHub Check: build (macos-latest, nightly)
  • GitHub Check: build (ubuntu-latest, stable)
  • GitHub Check: test
  • GitHub Check: build (ubuntu-latest, nightly)
  • GitHub Check: build
  • GitHub Check: auto-approve
🔇 Additional comments (1)
rocketmq-remoting/src/protocol/header/pull_message_request_header.rs (1)

26-63: Verify macro-generated codec still emits nested keys (lo, ns, nsd, …)

The previous hand-written to_map/encode_fast appended extra flattened fields from TopicRequestHeader ("lo", "ns", "nsd", "bname", "oway").
Ensure RequestHeaderCodec produces identical key names; otherwise existing brokers/clients will break.

Consider adding an integration test that serialises a header containing a populated TopicRequestHeader and asserts that those keys exist.

Copy link

codecov bot commented Jun 18, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 26.40%. Comparing base (9c00cdc) to head (13841eb).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3479      +/-   ##
==========================================
- Coverage   26.47%   26.40%   -0.07%     
==========================================
  Files         547      547              
  Lines       78382    78063     -319     
==========================================
- Hits        20749    20616     -133     
+ Misses      57633    57447     -186     

☔ 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

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 2a65fd0 into mxsm:main Jun 18, 2025
24 of 27 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 Jun 18, 2025
@donghao526 donghao526 deleted the feature/issue-3405 branch June 18, 2025 14:23
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.

[Refactor♻️]Refactor PullMessageRequestHeader with derive marco RequestHeaderCodec
4 participants