Skip to content

[ISSUE #1598]🚀Rocketmq-client support Pop consumer-1#1600

Merged
rocketmq-rust-bot merged 1 commit intomainfrom
feature-1598
Dec 6, 2024
Merged

[ISSUE #1598]🚀Rocketmq-client support Pop consumer-1#1600
rocketmq-rust-bot merged 1 commit intomainfrom
feature-1598

Conversation

@mxsm
Copy link
Copy Markdown
Owner

@mxsm mxsm commented Dec 6, 2024

Which Issue(s) This PR Fixes(Closes)

Fixes #1598

Brief Description

How Did You Test This Change?

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced asynchronous handling for pull requests and message queues, enhancing performance.
    • Added new request handling capability for processing reply messages from clients.
    • Implemented methods for managing subscription data and message queue assignments.
  • Bug Fixes

    • Improved error handling and logging for message queue operations.
  • Refactor

    • Updated method signatures to use references instead of ownership, optimizing memory usage.
  • Documentation

    • Enhanced logging for consumer group changes and rebalance notifications.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Dec 6, 2024

Walkthrough

The pull request introduces several changes across multiple files in the RocketMQ client implementation. Key modifications include altering method signatures to use immutable references, changing data types from String to CheetahString, and enhancing the asynchronous capabilities of various methods. Additionally, new methods are added to improve message handling and subscription management, while existing methods are updated to enhance performance and error handling. These changes collectively aim to support the POP consumption model more effectively.

Changes

File Path Change Summary
rocketmq-client/src/consumer/consumer_impl/pop_process_queue.rs Method signature of set_dropped changed from &mut self to &self, commenting out the line that updates the dropped field.
rocketmq-client/src/consumer/consumer_impl/pop_request.rs Field types for topic and consumer_group changed from String to CheetahString. Constructor and setter methods updated to accept CheetahString.
rocketmq-client/src/consumer/consumer_impl/re_balance.rs Method signatures for remove_unnecessary_pop_message_queue and remove_unnecessary_pop_message_queue_pop updated to accept mutable references. dispatch_pop_pull_request changed to asynchronous.
rocketmq-client/src/consumer/consumer_impl/re_balance/rebalance_impl.rs pop_process_queue_table type changed to Arc<RwLock<HashMap<MessageQueue, Arc<PopProcessQueue>>>>. New methods added: remove_subscription_data, update_message_queue_assignment. get_rebalance_result_from_broker updated to accept CheetahString.
rocketmq-client/src/consumer/consumer_impl/re_balance/rebalance_push_impl.rs Method signatures for remove_unnecessary_pop_message_queue and dispatch_pop_pull_request updated to use mutable references and asynchronous respectively.
rocketmq-client/src/implementation/client_remoting_processor.rs New method receive_reply_message added to handle RequestCode::PushReplyMessageToClient, including logic for parsing and decompressing messages.

Assessment against linked issues

Objective Addressed Explanation
Support for POP consumer (Feature #1598)

Possibly related issues

Suggested labels

feature, auto merge, ready to review, waiting-review, AI review first

Suggested reviewers

  • TeslaRustor
  • SpaceXCN

Poem

🐰 In the code where rabbits hop,
Changes made, we’ll never stop.
With Cheetah strings and async flair,
POP support is now laid bare.
So let’s rejoice, both near and far,
For RocketMQ, our shining star! 🌟


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-robot rocketmq-rust-robot added this to the v0.4.0 milestone Dec 6, 2024
@rocketmq-rust-robot rocketmq-rust-robot added the feature🚀 Suggest an idea for this project. label Dec 6, 2024
@rocketmq-rust-bot
Copy link
Copy Markdown
Collaborator

🔊@mxsm 🚀Thanks for your contribution 🎉. CodeRabbit(AI) will review your code first 🔥

Copy link
Copy Markdown
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: 5

🧹 Outside diff range and nitpick comments (3)
rocketmq-client/src/implementation/client_remoting_processor.rs (3)

Line range hint 107-134: Refactor duplicated error handling logic

The error handling code for parsing socket addresses is duplicated for both born_host and store_host. Consider extracting this into a helper function.

+ fn parse_socket_addr(addr: &str, field_name: &str) -> Result<SocketAddr, RemotingCommand> {
+     match addr.parse::<SocketAddr>() {
+         Ok(value) => Ok(value),
+         Err(_) => {
+             warn!("parse {} failed: {}", field_name, addr);
+             Err(RemotingCommand::create_response_command()
+                 .set_code(ResponseCode::SystemError)
+                 .set_remark(&format!("parse {} failed", field_name)))
+         }
+     }
+ }

Then use it like:

msg.born_host = parse_socket_addr(&request_header.born_host, "born_host")?;
msg.store_host = parse_socket_addr(&request_header.store_host, "store_host")?;

Line range hint 135-147: Improve error handling for message decompression

The current implementation silently falls back to using the compressed body when decompression fails. This could lead to issues downstream. Consider either:

  1. Propagating the decompression error
  2. Logging more details about the failure
  3. Adding metrics for failed decompressions
- if let Ok(decompressed) = de_result {
-     msg.message.body = Some(decompressed);
- } else {
-     warn!("err when uncompress constant");
-     msg.message.body = body.cloned();
- }
+ match de_result {
+     Ok(decompressed) => {
+         msg.message.body = Some(decompressed);
+     }
+     Err(e) => {
+         warn!("Failed to decompress message: {}", e);
+         return Ok(Some(
+             response
+                 .set_code(ResponseCode::SystemError)
+                 .set_remark(&format!("Failed to decompress message: {}", e)),
+         ));
+     }
+ }

Line range hint 171-190: Enhance observability for reply message processing

Consider adding more detailed logging and metrics to track:

  1. Success/failure rates of reply message processing
  2. Latency between request and reply
  3. Number of unmatched replies
 async fn process_reply_message(reply_msg: MessageExt) {
+    let start = std::time::Instant::now();
     let correlation_id = reply_msg
         .message
         .get_property(&CheetahString::from_static_str(
             MessageConst::PROPERTY_CORRELATION_ID,
         ))
         .unwrap_or_default();
     if let Some(request_response_future) = REQUEST_FUTURE_HOLDER
         .get_request(correlation_id.as_str())
         .await
     {
         request_response_future.put_response_message(Some(Box::new(reply_msg)));
         if request_response_future.get_request_callback().is_some() {
             request_response_future.on_success();
         }
+        debug!(
+            "Successfully processed reply message for correlation_id={} in {:?}",
+            correlation_id,
+            start.elapsed()
+        );
     } else {
-        warn!(
+        error!(
             "receive reply message, but not matched any request, CorrelationId: {} , reply \
              from host: {}",
             correlation_id, reply_msg.born_host
         );
     }
 }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between d286a91 and 11e29a4.

📒 Files selected for processing (6)
  • rocketmq-client/src/consumer/consumer_impl/pop_process_queue.rs (1 hunks)
  • rocketmq-client/src/consumer/consumer_impl/pop_request.rs (5 hunks)
  • rocketmq-client/src/consumer/consumer_impl/re_balance.rs (2 hunks)
  • rocketmq-client/src/consumer/consumer_impl/re_balance/rebalance_impl.rs (6 hunks)
  • rocketmq-client/src/consumer/consumer_impl/re_balance/rebalance_push_impl.rs (2 hunks)
  • rocketmq-client/src/implementation/client_remoting_processor.rs (1 hunks)
🔇 Additional comments (5)
rocketmq-client/src/consumer/consumer_impl/re_balance.rs (2)

46-50: Method signature updated appropriately

The method remove_unnecessary_pop_message_queue now accepts references to MessageQueue and PopProcessQueue, improving performance by avoiding unnecessary cloning.


72-72: Converted dispatch_pop_pull_request method to async

The dispatch_pop_pull_request method is now asynchronous, enabling non-blocking execution and better performance during pop pull request dispatching.

rocketmq-client/src/consumer/consumer_impl/pop_request.rs (1)

29-30: Updated types to CheetahString for topic and consumer_group

Changing the types of topic and consumer_group to CheetahString can improve performance due to lighter string handling.

rocketmq-client/src/implementation/client_remoting_processor.rs (2)

84-84: LGTM: Clean integration of POP reply message handling

The new request code case is properly integrated into the existing match statement and follows the established pattern.


Line range hint 135-147: Verify security implications of message decompression

The code decompresses messages from potentially untrusted sources. Please verify:

  1. The maximum allowed size for decompressed messages
  2. Protection against zip bomb attacks
  3. Resource limits during decompression
✅ Verification successful

Let me search for more specific information about message size limits and security controls.


Based on the search results, I can now provide a final response:

Message decompression has adequate security controls in place

The codebase implements several safeguards against decompression attacks:

  • Maximum message size limit of 4MB (1024 * 1024 * 4) is enforced by default in both producer and store configurations
  • Message size validation occurs before decompression in MessageExtEncoder
  • Messages exceeding size limits are rejected with MessageIllegal status
  • Compression/decompression is handled by well-tested standard libraries (zlib, lz4, zstd) with built-in safeguards
  • CRC32 checksums are used to verify message integrity

The implementation follows RocketMQ's standard security practices for handling compressed messages from untrusted sources.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for compression-related security measures
rg -A 5 "CompressorFactory|decompress|compress" 

# Look for any size limits or security configurations
rg -A 5 "max.*size|limit|security"

Length of output: 75388


Script:

#!/bin/bash
# Look for message size limits and security controls
rg -A 5 "max_message_size|max_body_size|max_decompressed|max_compressed"

# Search for any security-related configuration or validation
rg -A 5 "validate|check|verify|limit|security" rocketmq-common/src/common/compression/

Length of output: 19009

Comment on lines +246 to +250
fn remove_unnecessary_pop_message_queue(
&mut self,
mq: &MessageQueue,
pq: &PopProcessQueue,
) -> bool {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Implement remove_unnecessary_pop_message_queue method

The remove_unnecessary_pop_message_queue method is currently unimplemented and contains a todo!() placeholder. Please provide the necessary implementation.

Do you need assistance implementing this method, or should I open a GitHub issue to track this task?

Comment on lines +421 to 423
async fn dispatch_pop_pull_request(&self, pull_request_list: Vec<PopRequest>, delay: u64) {
todo!()
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Implement dispatch_pop_pull_request method

The dispatch_pop_pull_request method is currently unimplemented and contains a todo!() placeholder. Implementing this method is essential for proper dispatching of pop pull requests.

Would you like assistance in implementing this method, or should I open a GitHub issue to track this task?

Comment on lines +452 to +456
let sub_rebalance_impl = self.sub_rebalance_impl.as_mut().unwrap().upgrade();
if sub_rebalance_impl.is_none() {
return false;
}
let mut sub_rebalance_impl = sub_rebalance_impl.unwrap();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Handle None case without unwrapping Option

In the update_message_queue_assignment method, unwrapping self.sub_rebalance_impl without checking for None can lead to a panic. Safely handle the None case to maintain robustness.

Apply this diff to fix the issue:

-                let sub_rebalance_impl = self.sub_rebalance_impl.as_mut().unwrap().upgrade();
-                if sub_rebalance_impl.is_none() {
+                let sub_rebalance_impl = match self.sub_rebalance_impl.as_mut() {
+                    Some(sub_rebalance) => sub_rebalance.upgrade(),
+                    None => {
+                        error!("sub_rebalance_impl is None");
+                        return false;
+                    }
+                };
+                if sub_rebalance_impl.is_none() {
                     return false;
                 }
📝 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
let sub_rebalance_impl = self.sub_rebalance_impl.as_mut().unwrap().upgrade();
if sub_rebalance_impl.is_none() {
return false;
}
let mut sub_rebalance_impl = sub_rebalance_impl.unwrap();
let sub_rebalance_impl = match self.sub_rebalance_impl.as_mut() {
Some(sub_rebalance) => sub_rebalance.upgrade(),
None => {
error!("sub_rebalance_impl is None");
return false;
}
};
if sub_rebalance_impl.is_none() {
return false;
}
let mut sub_rebalance_impl = sub_rebalance_impl.unwrap();

Comment on lines +282 to +285
let sub_rebalance_impl = self.sub_rebalance_impl.as_mut().unwrap().upgrade();
if sub_rebalance_impl.is_none() {
return false;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Avoid potential panic by handling Option without unwrapping

At line 282, using unwrap() on self.sub_rebalance_impl.as_mut() can cause a panic if self.sub_rebalance_impl is None. Consider handling the None case to prevent potential crashes.

Apply this diff to fix the issue:

-                let sub_rebalance_impl = self.sub_rebalance_impl.as_mut().unwrap().upgrade();
-                if sub_rebalance_impl.is_none() {
+                let sub_rebalance_impl = match self.sub_rebalance_impl.as_mut() {
+                    Some(sub_rebalance) => sub_rebalance.upgrade(),
+                    None => {
+                        error!("sub_rebalance_impl is None");
+                        return false;
+                    }
+                };
+                if sub_rebalance_impl.is_none() {
                     return false;
                 }
📝 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
let sub_rebalance_impl = self.sub_rebalance_impl.as_mut().unwrap().upgrade();
if sub_rebalance_impl.is_none() {
return false;
}
let sub_rebalance_impl = match self.sub_rebalance_impl.as_mut() {
Some(sub_rebalance) => sub_rebalance.upgrade(),
None => {
error!("sub_rebalance_impl is None");
return false;
}
};
if sub_rebalance_impl.is_none() {
return false;
}

Comment on lines +71 to +72
pub(crate) fn set_dropped(&self, dropped: bool) {
//self.dropped = dropped;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

set_dropped method does not update the dropped flag

The set_dropped method no longer updates the dropped field because the assignment is commented out, and the method now takes &self instead of &mut self. This prevents the method from performing its intended function.

Consider restoring the ability to modify the dropped flag by accepting &mut self and uncommenting the assignment.

Apply this diff to fix the issue:

-pub(crate) fn set_dropped(&self, dropped: bool) {
-    //self.dropped = dropped;
+pub(crate) fn set_dropped(&mut self, dropped: bool) {
+    self.dropped = dropped;
 }
📝 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
pub(crate) fn set_dropped(&self, dropped: bool) {
//self.dropped = dropped;
pub(crate) fn set_dropped(&mut self, dropped: bool) {
self.dropped = dropped;

@codecov
Copy link
Copy Markdown

codecov bot commented Dec 6, 2024

Codecov Report

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

Project coverage is 25.38%. Comparing base (d286a91) to head (11e29a4).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...onsumer/consumer_impl/re_balance/rebalance_impl.rs 0.00% 252 Missing ⚠️
...er/consumer_impl/re_balance/rebalance_push_impl.rs 0.00% 6 Missing ⚠️
...q-client/src/consumer/consumer_impl/pop_request.rs 0.00% 4 Missing ⚠️
...mq-client/src/consumer/consumer_impl/re_balance.rs 0.00% 3 Missing ⚠️
...nt/src/consumer/consumer_impl/pop_process_queue.rs 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1600      +/-   ##
==========================================
- Coverage   25.49%   25.38%   -0.11%     
==========================================
  Files         459      459              
  Lines       60299    60554     +255     
==========================================
  Hits        15371    15371              
- Misses      44928    45183     +255     

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

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 feature🚀 Suggest an idea for this project.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature🚀] Rocketmq-client support Pop consumer-1

4 participants