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 #2052]💫Implement PopBufferMergeService#putAckToStore🚀 #2053

Merged
merged 1 commit into from
Jan 3, 2025

Conversation

mxsm
Copy link
Owner

@mxsm mxsm commented Jan 3, 2025

Which Issue(s) This PR Fixes(Closes)

Fixes #2052

Brief Description

How Did You Test This Change?

Summary by CodeRabbit

  • Improvements
    • Enhanced acknowledgment message processing in the broker service
    • Updated method to support asynchronous message handling
    • Improved support for batch acknowledgment configurations

Copy link
Contributor

coderabbitai bot commented Jan 3, 2025

Walkthrough

The pull request modifies the PopBufferMergeService in the RocketMQ Rust implementation, focusing on enhancing the put_ack_to_store method. The changes transform the method from synchronous to asynchronous, introducing new imports for message handling and improving the logic for processing acknowledgment messages. The modifications aim to provide more flexible and efficient handling of message acknowledgments, particularly with respect to batch acknowledgment configurations.

Changes

File Change Summary
rocketmq-broker/src/processor/processor_service/pop_buffer_merge_service.rs - Updated method signature to async
- Added new imports for message handling
- Modified put_ack_to_store to construct AckMsg and MessageExtBrokerInner
- Updated scan method logic for handling acknowledgment messages

Assessment against linked issues

Objective Addressed Explanation
Implement PopBufferMergeService#putAckToStore [#2052]

Possibly related issues

Possibly related PRs

Suggested labels

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

Suggested reviewers

  • TeslaRustor
  • SpaceXCN
  • rocketmq-rust-bot

Poem

🚀 In the realm of message streams so bright,
A rabbit hops through async light,
Acknowledgments dance, bits align,
RocketMQ's magic starts to shine,
Merging buffers with coding might! 🐰


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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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💥.

@RocketmqRustBot RocketmqRustBot added the feature🚀 Suggest an idea for this project. label Jan 3, 2025
@RocketmqRustBot RocketmqRustBot added this to the v0.4.0 milestone Jan 3, 2025
Copy link

codecov bot commented Jan 3, 2025

Codecov Report

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

Project coverage is 28.40%. Comparing base (b7ac028) to head (7ef1d97).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...ssor/processor_service/pop_buffer_merge_service.rs 0.00% 44 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2053      +/-   ##
==========================================
- Coverage   28.42%   28.40%   -0.02%     
==========================================
  Files         488      488              
  Lines       69129    69170      +41     
==========================================
  Hits        19651    19651              
- Misses      49478    49519      +41     

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

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/processor_service/pop_buffer_merge_service.rs (1)

331-344: Consider parallelizing or adding error handling for single ACK storage.
Currently, the loop calls put_ack_to_store sequentially and does not log or retry on failure. For large numbers of acks, this may be inefficient, and failures will be silently ignored.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b7ac028 and 7ef1d97.

📒 Files selected for processing (1)
  • rocketmq-broker/src/processor/processor_service/pop_buffer_merge_service.rs (3 hunks)
🔇 Additional comments (7)
rocketmq-broker/src/processor/processor_service/pop_buffer_merge_service.rs (7)

27-27: Import of bytes::Bytes looks good.
No issues found. This import is properly utilized at line 511 for setting the message body.


33-33: Import of message_decoder is appropriate.
This import is used later to serialize message properties in message_properties_to_string.


34-34: Import of MessageExtBrokerInner is correct.
It is crucial for constructing broker-specific message structures, as utilized in put_ack_to_store.


35-35: Import of MessageConst is used correctly for setting message properties.
No issues observed; it helps to identify the unique client message ID key.


36-36: Import of MessageTrait is consistent with the overall message-building logic.
Looks good.


40-40: Import of RemotingSerializable is well-aligned with message serialization.
Used in ack_msg.to_json(), enabling JSON serialization for ack messages.


44-44: Import of AckMsg is correct for creating single acknowledgment messages.
This is essential for acknowledgment logic in put_ack_to_store.

Comment on lines +498 to +535
async fn put_ack_to_store(&self, point_wrapper: &PopCheckPointWrapper, index: u8) -> bool {
let point = point_wrapper.get_ck();
let ack_msg = AckMsg {
ack_offset: point.ack_offset_by_index(index),
start_offset: point.start_offset,
consumer_group: point.cid.clone(),
topic: point.topic.clone(),
queue_id: point.queue_id,
pop_time: point.pop_time,
..Default::default()
};
let mut msg = MessageExtBrokerInner::default();
msg.set_topic(self.revive_topic.clone());
msg.set_body(Bytes::from(ack_msg.to_json().unwrap()));
msg.message_ext_inner.queue_id = point_wrapper.revive_queue_id;
msg.set_tags(CheetahString::from_static_str(PopAckConstants::ACK_TAG));
msg.message_ext_inner.born_timestamp = get_current_millis() as i64;
msg.message_ext_inner.born_host = self.store_host;
msg.message_ext_inner.store_host = self.store_host;
msg.set_delay_time_ms(point.get_revive_time() as u64);
msg.put_property(
CheetahString::from_static_str(MessageConst::PROPERTY_UNIQ_CLIENT_MESSAGE_ID_KEYIDX),
CheetahString::from_string(PopMessageProcessor::<MS>::gen_ack_unique_id(&ack_msg)),
);
msg.properties_string = message_decoder::message_properties_to_string(msg.get_properties());

let put_message_result = self
.escape_bridge
.mut_from_ref()
.put_message_to_specific_queue(msg)
.await;
matches!(
put_message_result.put_message_status(),
PutMessageStatus::PutOk
| PutMessageStatus::FlushDiskTimeout
| PutMessageStatus::FlushSlaveTimeout
| PutMessageStatus::SlaveNotAvailable
)
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 risky .unwrap() and handle failures when putting ACK messages.
Relying on ack_msg.to_json().unwrap() can cause panics if serialization fails. Also, no error is logged if the store operation fails. As a result, troubleshooting is harder. Consider logging or applying retry logic for improved reliability.

Below is an example refactor applying safer JSON handling and error logging:

- msg.set_body(Bytes::from(ack_msg.to_json().unwrap()));
+ let ack_msg_json = match ack_msg.to_json() {
+     Ok(json) => json,
+     Err(e) => {
+         error!("AckMsg to_json error: {:?}", e);
+         return false;
+     }
+ };
+ msg.set_body(Bytes::from(ack_msg_json));

- matches!(
-     put_message_result.put_message_status(),
-     PutMessageStatus::PutOk
-         | PutMessageStatus::FlushDiskTimeout
-         | PutMessageStatus::FlushSlaveTimeout
-         | PutMessageStatus::SlaveNotAvailable
- )
+ let success = matches!(
+     put_message_result.put_message_status(),
+     PutMessageStatus::PutOk
+         | PutMessageStatus::FlushDiskTimeout
+         | PutMessageStatus::FlushSlaveTimeout
+         | PutMessageStatus::SlaveNotAvailable
+ );
+ if !success {
+     error!(
+         "put_message_to_specific_queue failed with status: {:?}",
+         put_message_result.put_message_status()
+     );
+ }
+ success
📝 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
async fn put_ack_to_store(&self, point_wrapper: &PopCheckPointWrapper, index: u8) -> bool {
let point = point_wrapper.get_ck();
let ack_msg = AckMsg {
ack_offset: point.ack_offset_by_index(index),
start_offset: point.start_offset,
consumer_group: point.cid.clone(),
topic: point.topic.clone(),
queue_id: point.queue_id,
pop_time: point.pop_time,
..Default::default()
};
let mut msg = MessageExtBrokerInner::default();
msg.set_topic(self.revive_topic.clone());
msg.set_body(Bytes::from(ack_msg.to_json().unwrap()));
msg.message_ext_inner.queue_id = point_wrapper.revive_queue_id;
msg.set_tags(CheetahString::from_static_str(PopAckConstants::ACK_TAG));
msg.message_ext_inner.born_timestamp = get_current_millis() as i64;
msg.message_ext_inner.born_host = self.store_host;
msg.message_ext_inner.store_host = self.store_host;
msg.set_delay_time_ms(point.get_revive_time() as u64);
msg.put_property(
CheetahString::from_static_str(MessageConst::PROPERTY_UNIQ_CLIENT_MESSAGE_ID_KEYIDX),
CheetahString::from_string(PopMessageProcessor::<MS>::gen_ack_unique_id(&ack_msg)),
);
msg.properties_string = message_decoder::message_properties_to_string(msg.get_properties());
let put_message_result = self
.escape_bridge
.mut_from_ref()
.put_message_to_specific_queue(msg)
.await;
matches!(
put_message_result.put_message_status(),
PutMessageStatus::PutOk
| PutMessageStatus::FlushDiskTimeout
| PutMessageStatus::FlushSlaveTimeout
| PutMessageStatus::SlaveNotAvailable
)
async fn put_ack_to_store(&self, point_wrapper: &PopCheckPointWrapper, index: u8) -> bool {
let point = point_wrapper.get_ck();
let ack_msg = AckMsg {
ack_offset: point.ack_offset_by_index(index),
start_offset: point.start_offset,
consumer_group: point.cid.clone(),
topic: point.topic.clone(),
queue_id: point.queue_id,
pop_time: point.pop_time,
..Default::default()
};
let mut msg = MessageExtBrokerInner::default();
msg.set_topic(self.revive_topic.clone());
let ack_msg_json = match ack_msg.to_json() {
Ok(json) => json,
Err(e) => {
error!("AckMsg to_json error: {:?}", e);
return false;
}
};
msg.set_body(Bytes::from(ack_msg_json));
msg.message_ext_inner.queue_id = point_wrapper.revive_queue_id;
msg.set_tags(CheetahString::from_static_str(PopAckConstants::ACK_TAG));
msg.message_ext_inner.born_timestamp = get_current_millis() as i64;
msg.message_ext_inner.born_host = self.store_host;
msg.message_ext_inner.store_host = self.store_host;
msg.set_delay_time_ms(point.get_revive_time() as u64);
msg.put_property(
CheetahString::from_static_str(MessageConst::PROPERTY_UNIQ_CLIENT_MESSAGE_ID_KEYIDX),
CheetahString::from_string(PopMessageProcessor::<MS>::gen_ack_unique_id(&ack_msg)),
);
msg.properties_string = message_decoder::message_properties_to_string(msg.get_properties());
let put_message_result = self
.escape_bridge
.mut_from_ref()
.put_message_to_specific_queue(msg)
.await;
let success = matches!(
put_message_result.put_message_status(),
PutMessageStatus::PutOk
| PutMessageStatus::FlushDiskTimeout
| PutMessageStatus::FlushSlaveTimeout
| PutMessageStatus::SlaveNotAvailable
);
if !success {
error!(
"put_message_to_specific_queue failed with status: {:?}",
put_message_result.put_message_status()
);
}
success

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🚀] Implement PopBufferMergeService#putAckToStore
3 participants