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 #729]⚡️Optimize pull message #730

Merged
merged 1 commit into from
Jul 2, 2024
Merged

[ISSUE #729]⚡️Optimize pull message #730

merged 1 commit into from
Jul 2, 2024

Conversation

mxsm
Copy link
Owner

@mxsm mxsm commented Jul 2, 2024

Which Issue(s) This PR Fixes(Closes)

Fixes #729

Brief Description

How Did You Test This Change?

Summary by CodeRabbit

  • New Features

    • Introduced a new function to check metadata prefixes.
    • Added a new field notify_message_arrive_in_batch to enhance message arrival notifications in batch mode.
  • Improvements

    • Enhanced DefaultMessageStore to accommodate batch message notifications.
    • Updated ReputMessageService to support the new message notification feature.
  • Bug Fixes

    • Minor internal adjustments for improved function calls within the broker runtime.

@github-actions github-actions bot requested review from SpaceXCN and TeslaRustor July 2, 2024 15:57
Copy link
Contributor

coderabbitai bot commented Jul 2, 2024

Walkthrough

The changes optimize RocketMQ's message-pulling process. A new boolean flag notify_message_arrive_in_batch has been introduced in multiple structs to control batch notifications for message arrival. Additionally, a helper function is_lmq and other constants have been added for better metadata and group topic handling. These modifications enhance overall efficiency and functionality in message processing and notifying.

Changes

File/Module Change Summary
rocketmq-broker/src/broker_runtime.rs Added a new boolean argument false to a function call in BrokerRuntime.
rocketmq-common/src/common/mix_all.rs Introduced is_lmq function and corresponding test cases.
rocketmq-store/src/message_store/default_message_store.rs Added imports, new field notify_message_arrive_in_batch, updated constructors, and methods to handle this new field.

Sequence Diagram

sequenceDiagram
    participant Client
    participant BrokerRuntime
    participant DefaultMessageStore
    participant ReputMessageService
    Note over Client: Enhanced Pull Message Flow
    Client->>BrokerRuntime: Request messages
    BrokerRuntime->>DefaultMessageStore: Fetch messages (with notify_message_arrive_in_batch)
    DefaultMessageStore-->>ReputMessageService: Notify message arrival
    ReputMessageService-->>DefaultMessageStore: Batch process based on notify_message_arrive_in_batch
    DefaultMessageStore->>BrokerRuntime: Return messages
    BrokerRuntime->>Client: Deliver messages
Loading

Assessment against linked issues

Objective Addressed Explanation
Optimize pull message process (#729)

Poem

In RocketMQ's grand domain,
Optimized paths now reign,
Messages pull with ease,
Batching brings the breeze,
Brokers and stores align,
Efficiency we enshrine.
Code evolved, a pure gain.

Tip

AI model upgrade

gpt-4o model for reviews and chat is now live

OpenAI claims that this model is better at understanding and generating code than the previous models. Please join our Discord Community to provide any feedback or to report any issues.


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

@mxsm
Copy link
Owner Author

mxsm commented Jul 2, 2024

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

@SpaceXCN SpaceXCN added approved PR has approved and removed ready to review labels Jul 2, 2024
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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between dae0faa and 9dc9797.

Files selected for processing (3)
  • rocketmq-broker/src/broker_runtime.rs (1 hunks)
  • rocketmq-common/src/common/mix_all.rs (2 hunks)
  • rocketmq-store/src/message_store/default_message_store.rs (10 hunks)
Additional comments not posted (14)
rocketmq-common/src/common/mix_all.rs (4)

104-109: Function is_lmq looks good.

The function correctly checks if the provided metadata starts with the LMQ prefix. The use of Option is appropriate for handling possible None values.


178-182: Test returns_true_for_lmq_prefixed_metadata looks good.

The test correctly verifies that the function returns true for metadata starting with the LMQ prefix.


184-188: Test returns_false_for_non_lmq_prefixed_metadata looks good.

The test correctly verifies that the function returns false for metadata not starting with the LMQ prefix.


190-193: Test returns_false_for_none_metadata looks good.

The test correctly verifies that the function returns false for None metadata.

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

298-298: Ensure the new boolean argument is correctly utilized.

The new boolean argument false has been added to the DefaultMessageStore::new call. Ensure that this argument is correctly utilized within the DefaultMessageStore implementation.

rocketmq-store/src/message_store/default_message_store.rs (9)

35-38: Imports are appropriate.

The new imports are relevant and necessary for the added functionality.


116-116: New field notify_message_arrive_in_batch added to DefaultMessageStore.

This field will likely be used to control batch notifications for message arrival.


144-144: Clone implementation updated to include new field.

The Clone implementation correctly includes the new notify_message_arrive_in_batch field.


155-155: Constructor updated to initialize new field.

The notify_message_arrive_in_batch field is correctly initialized in the constructor.


585-586: start method updated to pass new field.

The notify_message_arrive_in_batch field is correctly passed to the ReputMessageService.


1037-1038: New field notify_message_arrive_in_batch added to ReputMessageService.

This field will likely be used to control batch notifications for message arrival.


1037-1038: start method updated to pass new field.

The notify_message_arrive_in_batch field is correctly passed to the ReputMessageServiceInner.

Also applies to: 1045-1046


1106-1107: New field notify_message_arrive_in_batch added to ReputMessageServiceInner.

This field will likely be used to control batch notifications for message arrival.


1218-1221: do_reput method updated to use new field.

The notify_message_arrive_in_batch field is correctly used to control message arrival notifications.

Comment on lines +1111 to +1158
fn notify_message_arrive4multi_queue(&self, dispatch_request: &mut DispatchRequest) {
let prop = dispatch_request.properties_map.as_ref();
if prop.is_none() || dispatch_request.topic.starts_with(RETRY_GROUP_TOPIC_PREFIX) {
return;
}
let prop = prop.unwrap();
let multi_dispatch_queue = prop.get(MessageConst::PROPERTY_INNER_MULTI_DISPATCH);
let multi_queue_offset = prop.get(MessageConst::PROPERTY_INNER_MULTI_QUEUE_OFFSET);
if multi_dispatch_queue.is_none()
|| multi_queue_offset.is_none()
|| multi_dispatch_queue.as_ref().unwrap().is_empty()
|| multi_queue_offset.as_ref().unwrap().is_empty()
{
return;
}
let queues: Vec<&str> = multi_dispatch_queue
.unwrap()
.split(MULTI_DISPATCH_QUEUE_SPLITTER)
.collect();
let queue_offsets: Vec<&str> = multi_queue_offset
.unwrap()
.split(MULTI_DISPATCH_QUEUE_SPLITTER)
.collect();
if queues.len() != queue_offsets.len() {
return;
}
for i in 0..queues.len() {
let queue_name = queues[i];
let queue_offset: i64 = queue_offsets[i].parse().unwrap();
let mut queue_id = dispatch_request.queue_id;
if self.message_store_config.enable_lmq && is_lmq(Some(queue_name)) {
queue_id = 0;
}
self.message_store
.message_arriving_listener
.as_ref()
.unwrap()
.arriving(
queue_name,
queue_id,
queue_offset + 1,
Some(dispatch_request.tags_code),
dispatch_request.store_timestamp,
dispatch_request.bit_map.clone(),
dispatch_request.properties_map.as_ref(),
);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Handle unwrap calls safely in notify_message_arrive4multi_queue.

The unwrap calls can potentially panic if the values are not present. Consider using safe handling methods like if let or match.

- let prop = prop.unwrap();
- let multi_dispatch_queue = prop.get(MessageConst::PROPERTY_INNER_MULTI_DISPATCH);
- let multi_queue_offset = prop.get(MessageConst::PROPERTY_INNER_MULTI_QUEUE_OFFSET);
+ if let Some(prop) = prop {
+     let multi_dispatch_queue = prop.get(MessageConst::PROPERTY_INNER_MULTI_DISPATCH);
+     let multi_queue_offset = prop.get(MessageConst::PROPERTY_INNER_MULTI_QUEUE_OFFSET);
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
fn notify_message_arrive4multi_queue(&self, dispatch_request: &mut DispatchRequest) {
let prop = dispatch_request.properties_map.as_ref();
if prop.is_none() || dispatch_request.topic.starts_with(RETRY_GROUP_TOPIC_PREFIX) {
return;
}
let prop = prop.unwrap();
let multi_dispatch_queue = prop.get(MessageConst::PROPERTY_INNER_MULTI_DISPATCH);
let multi_queue_offset = prop.get(MessageConst::PROPERTY_INNER_MULTI_QUEUE_OFFSET);
if multi_dispatch_queue.is_none()
|| multi_queue_offset.is_none()
|| multi_dispatch_queue.as_ref().unwrap().is_empty()
|| multi_queue_offset.as_ref().unwrap().is_empty()
{
return;
}
let queues: Vec<&str> = multi_dispatch_queue
.unwrap()
.split(MULTI_DISPATCH_QUEUE_SPLITTER)
.collect();
let queue_offsets: Vec<&str> = multi_queue_offset
.unwrap()
.split(MULTI_DISPATCH_QUEUE_SPLITTER)
.collect();
if queues.len() != queue_offsets.len() {
return;
}
for i in 0..queues.len() {
let queue_name = queues[i];
let queue_offset: i64 = queue_offsets[i].parse().unwrap();
let mut queue_id = dispatch_request.queue_id;
if self.message_store_config.enable_lmq && is_lmq(Some(queue_name)) {
queue_id = 0;
}
self.message_store
.message_arriving_listener
.as_ref()
.unwrap()
.arriving(
queue_name,
queue_id,
queue_offset + 1,
Some(dispatch_request.tags_code),
dispatch_request.store_timestamp,
dispatch_request.bit_map.clone(),
dispatch_request.properties_map.as_ref(),
);
}
}
fn notify_message_arrive4multi_queue(&self, dispatch_request: &mut DispatchRequest) {
let prop = dispatch_request.properties_map.as_ref();
if prop.is_none() || dispatch_request.topic.starts_with(RETRY_GROUP_TOPIC_PREFIX) {
return;
}
if let Some(prop) = prop {
let multi_dispatch_queue = prop.get(MessageConst::PROPERTY_INNER_MULTI_DISPATCH);
let multi_queue_offset = prop.get(MessageConst::PROPERTY_INNER_MULTI_QUEUE_OFFSET);
if multi_dispatch_queue.is_none()
|| multi_queue_offset.is_none()
|| multi_dispatch_queue.as_ref().unwrap().is_empty()
|| multi_queue_offset.as_ref().unwrap().is_empty()
{
return;
}
let queues: Vec<&str> = multi_dispatch_queue
.unwrap()
.split(MULTI_DISPATCH_QUEUE_SPLITTER)
.collect();
let queue_offsets: Vec<&str> = multi_queue_offset
.unwrap()
.split(MULTI_DISPATCH_QUEUE_SPLITTER)
.collect();
if queues.len() != queue_offsets.len() {
return;
}
for i in 0..queues.len() {
let queue_name = queues[i];
let queue_offset: i64 = queue_offsets[i].parse().unwrap();
let mut queue_id = dispatch_request.queue_id;
if self.message_store_config.enable_lmq && is_lmq(Some(queue_name)) {
queue_id = 0;
}
self.message_store
.message_arriving_listener
.as_ref()
.unwrap()
.arriving(
queue_name,
queue_id,
queue_offset + 1,
Some(dispatch_request.tags_code),
dispatch_request.store_timestamp,
dispatch_request.bit_map.clone(),
dispatch_request.properties_map.as_ref(),
);
}
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved PR has approved auto merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Enhancement⚡️] Optimize pull message
2 participants