Skip to content
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

[ISSUE #1870]⚡️Replace other structs attribute store_host with BrokerRuntime store_host #1871

Merged
merged 1 commit into from
Dec 19, 2024

Conversation

mxsm
Copy link
Owner

@mxsm mxsm commented Dec 19, 2024

Which Issue(s) This PR Fixes(Closes)

Fixes #1870

Brief Description

How Did You Test This Change?

Summary by CodeRabbit

  • New Features

    • Introduced a store_host parameter across multiple processors and the TransactionalMessageBridge, allowing for more straightforward initialization and improved contextual information during message handling.
  • Bug Fixes

    • Streamlined the initialization process for the AckMessageProcessor, ReplyMessageProcessor, and SendMessageProcessor by removing unnecessary parsing logic from the broker configuration.
  • Documentation

    • Updated method signatures to reflect the inclusion of the store_host parameter in relevant constructors.

Copy link
Contributor

coderabbitai bot commented Dec 19, 2024

Walkthrough

The pull request introduces modifications to the RocketMQ broker's runtime and processor components, focusing on the integration of a store_host parameter across multiple structs. The changes primarily involve updating constructor methods to directly accept store_host as a parameter, replacing previous methods of deriving this information from broker configurations. This refactoring aims to streamline the initialization of various message processing components by explicitly passing the store host address.

Changes

File Change Summary
rocketmq-broker/src/broker_runtime.rs Added store_host: SocketAddr field, updated init_processor and initial_transaction methods to incorporate store_host
rocketmq-broker/src/processor/ack_message_processor.rs Updated constructor to accept store_host parameter directly
rocketmq-broker/src/processor/reply_message_processor.rs Modified constructor to include store_host parameter
rocketmq-broker/src/processor/send_message_processor.rs Added store_host field to Inner struct and updated constructor
rocketmq-broker/src/transaction/queue/transactional_message_bridge.rs Updated new method to accept store_host parameter

Assessment against linked issues

Objective Addressed Explanation
Replace store_host attributes with BrokerRuntime store_host [#1870]

Possibly related PRs

Suggested labels

enhancement, auto merge, ready to review, waiting-review, AI review first, rocketmq-broker crate

Suggested reviewers

  • TeslaRustor
  • SpaceXCN
  • RocketmqRustBot

Poem

🚀 Hops of Code, Leaps of Joy
A rabbit's tale of refactoring ploy
Store host dancing, parameters bright
Processors singing with newfound might
Rust's magic weaving, clean and light! 🐰


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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

🔊@mxsm 🚀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: 1

🧹 Nitpick comments (1)
rocketmq-broker/src/processor/send_message_processor.rs (1)

196-196: Consider removing redundant store_host storage

While the addition of store_host is correct, it's currently stored in both the Inner struct and SendMessageProcessor struct. Consider storing it only in the Inner struct since that's where it's primarily used.

pub struct SendMessageProcessor<MS, TS> {
    inner: ArcMut<Inner<MS, TS>>,
-   store_host: SocketAddr,
}

impl<MS, TS> SendMessageProcessor<MS, TS>
where
    MS: MessageStore,
    TS: TransactionalMessageService,
{
    pub fn new(
        // ... other parameters ...
        store_host: SocketAddr,
    ) -> Self {
        Self {
            inner: ArcMut::new(Inner {
                // ... other fields ...
                store_host,
            }),
-           store_host,
        }
    }
}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4f6ec9c and c9413f6.

📒 Files selected for processing (5)
  • rocketmq-broker/src/broker_runtime.rs (4 hunks)
  • rocketmq-broker/src/processor/ack_message_processor.rs (1 hunks)
  • rocketmq-broker/src/processor/reply_message_processor.rs (1 hunks)
  • rocketmq-broker/src/processor/send_message_processor.rs (1 hunks)
  • rocketmq-broker/src/transaction/queue/transactional_message_bridge.rs (1 hunks)
🔇 Additional comments (5)
rocketmq-broker/src/transaction/queue/transactional_message_bridge.rs (1)

78-78: LGTM! Constructor parameter addition is clean.

The addition of the store_host parameter to the constructor aligns with the PR's objective of replacing the store_host attribute handling.

rocketmq-broker/src/processor/ack_message_processor.rs (1)

79-79: LGTM! Verify consistent usage of store_host throughout the processor.

The addition of the store_host parameter to the constructor is clean. The parameter is correctly used in message processing, particularly in the append_ack method.

✅ Verification successful

Let me analyze the usage of store_host across the processors. The search results show that store_host is consistently used in message processing across different processor modules:

  1. ack_message_processor.rs: Sets store_host in message inner during ack processing
  2. reply_message_processor.rs: Sets store_host in message extension inner
  3. send_message_processor.rs: Sets store_host in multiple message processing paths
  4. end_transaction_processor.rs: Copies store_host from existing message
  5. change_invisible_time_processor.rs: Sets store_host in message inner

Let me verify the constructor pattern to ensure consistent initialization:


Let me try a different pattern to check the constructor implementations:


Let me check specifically for the store_host in struct definitions and new implementations with a different pattern:


LGTM! The store_host field is consistently implemented across processors

The verification confirms that store_host is properly and consistently used across the message processing chain:

  • All relevant processors (SendMessageProcessor, ReplyMessageProcessor, AckMessageProcessor, ChangeInvisibleTimeProcessor) correctly:
    • Define store_host: SocketAddr as a struct field
    • Accept store_host in their new() constructors
    • Use store_host consistently when processing messages, setting it in message extensions
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify consistent usage of store_host in message processing
# Test: Search for store_host assignments in message processing
rg -A 2 'store_host\s*=' rocketmq-broker/src/processor/

Length of output: 3267


Script:

#!/bin/bash
# Search for store_host in struct definitions and new implementations
ast-grep --pattern 'impl $_ {
    pub fn new($$$) -> Self {
        $$$
        store_host: $_
        $$$
    }
}'

Length of output: 117


Script:

#!/bin/bash
# Search for processor struct definitions and their new implementations
rg -A 5 'impl \w+Processor' rocketmq-broker/src/processor/

Length of output: 5031


Script:

#!/bin/bash
# Search for processor structs with store_host field and their new implementations
rg -B 3 -A 10 'store_host:.*SocketAddr' rocketmq-broker/src/processor/

Length of output: 10291

rocketmq-broker/src/broker_runtime.rs (3)

Line range hint 476-488: LGTM: Consistent store host propagation to message processors

The change correctly propagates the store_host from BrokerRuntime to the message processors, ensuring consistent broker host information across components.


571-571: LGTM: Consistent store host propagation to AckMessageProcessor

The change correctly propagates the store_host to the AckMessageProcessor, maintaining consistency with other processor initializations.


755-756: LGTM: Consistent store host propagation to TransactionalMessageBridge

The change correctly propagates the store_host to the TransactionalMessageBridge, ensuring consistent broker host information in transaction processing.

@@ -73,10 +73,8 @@ where
broker_stats_manager: Arc<BrokerStatsManager>,
producer_manager: Option<Arc<ProducerManager>>,
transactional_message_service: ArcMut<TS>,
store_host: SocketAddr,
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Remove duplicated store_host field.

The store_host field is duplicated in both the main struct and the inner struct. This could lead to inconsistencies if the values diverge.

Consider this refactor to eliminate the duplication:

 pub struct ReplyMessageProcessor<MS, TS> {
     inner: Inner<MS, TS>,
-    store_host: SocketAddr,
 }

 impl<MS, TS> ReplyMessageProcessor<MS, TS>
 where
     MS: MessageStore,
     TS: TransactionalMessageService,
 {
     pub fn new(
         // ... other parameters ...
         store_host: SocketAddr,
     ) -> Self {
         Self {
             inner: Inner {
                 // ... other fields ...
                 store_host,
             },
-            store_host,
         }
     }
 }

Then update all usages of self.store_host to self.inner.store_host.

Also applies to: 91-91

Copy link

codecov bot commented Dec 19, 2024

Codecov Report

Attention: Patch coverage is 0% with 9 lines in your changes missing coverage. Please review.

Project coverage is 28.47%. Comparing base (4f6ec9c) to head (c9413f6).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
rocketmq-broker/src/broker_runtime.rs 0.00% 5 Missing ⚠️
...etmq-broker/src/processor/ack_message_processor.rs 0.00% 1 Missing ⚠️
...mq-broker/src/processor/reply_message_processor.rs 0.00% 1 Missing ⚠️
...tmq-broker/src/processor/send_message_processor.rs 0.00% 1 Missing ⚠️
.../transaction/queue/transactional_message_bridge.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1871   +/-   ##
=======================================
  Coverage   28.47%   28.47%           
=======================================
  Files         475      475           
  Lines       66802    66798    -4     
=======================================
  Hits        19024    19024           
+ Misses      47778    47774    -4     

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

@mxsm mxsm changed the title [ISSUE #1870]⚡️Replace other structs attribute store_host with Broker… [ISSUE #1870]⚡️Replace other structs attribute store_host with BrokerRuntime store_host Dec 19, 2024
@rocketmq-rust-bot rocketmq-rust-bot merged commit 559e382 into main Dec 19, 2024
28 of 29 checks passed
@mxsm mxsm deleted the op-1870 branch December 19, 2024 08:34
@rocketmq-rust-bot rocketmq-rust-bot added approved PR has approved and removed ready to review waiting-review waiting review this PR labels Dec 19, 2024
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 enhancement⚡️ New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Enhancement⚡️] Replace other structs attribute store_host with BrokerRuntime store_host
3 participants