Skip to content

[ISSUE #3428]♻️Refactor DefaultTransactionalMessageCheckListener to simplify structure and enhance message handling - #3429

Merged
rocketmq-rust-bot merged 3 commits into
mainfrom
refactor-3428
Jun 9, 2025
Merged

rocketmq-rust-bot merged 3 commits into
mainfrom
refactor-3428

Conversation

@mxsm

@mxsm mxsm commented Jun 9, 2025 •

Copy link
Copy Markdown
Owner

Which Issue(s) This PR Fixes(Closes)

Fixes #3428

Brief Description

How Did You Test This Change?

Summary by CodeRabbit

  • Refactor
    • Simplified transactional message checking by consolidating broker client handling and reorganizing related methods for improved maintainability.
  • New Features
    • Added support for sending check messages and resolving intermediate transactional message states with new asynchronous operations.

…implify structure and enhance message handling
Copilot AI review requested due to automatic review settings June 9, 2025 03:52
@coderabbitai

coderabbitai Bot commented Jun 9, 2025 •

Copy link
Copy Markdown
Contributor

"""

Walkthrough

The code refactors the DefaultTransactionalMessageCheckListener by removing an unnecessary inner struct, directly embedding the broker_client field, and updating related constructors and trait implementations. It also adds new async methods to the TransactionalMessageCheckListenerInner trait and reorganizes method visibility and placement for clarity, without altering core message handling logic.

Changes

File(s) Change Summary
rocketmq-broker/src/transaction/queue/default_transactional_message_check_listener.rs Removed inner field from DefaultTransactionalMessageCheckListener, embedded broker_client directly, updated constructor and Clone implementation, reorganized and updated method signatures (some to async), changed method visibility, and moved methods for clarity.
rocketmq-broker/src/transaction/transactional_message_check_listener.rs Added async methods send_check_message and resolve_half_msg to the TransactionalMessageCheckListenerInner trait.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant DefaultListener
    participant BrokerClient

    Client->>DefaultListener: new()
    DefaultListener->>BrokerClient: store ArcMut<Broker2Client>

    Client->>DefaultListener: send_check_message(msg_ext)
    DefaultListener->>BrokerClient: send check message (async)
    BrokerClient-->>DefaultListener: RocketMQResult

    Client->>DefaultListener: resolve_half_msg(msg_ext)
    DefaultListener->>BrokerClient: resolve half message (async)
    BrokerClient-->>DefaultListener: RocketMQResult
Loading

Assessment against linked issues

Objective (Issue #) Addressed Explanation
Simplify structure of DefaultTransactionalMessageCheckListener (#3428) ✅
Enhance message handling: add/modify async methods for check and resolve (#3428) ✅
Ensure refactor does not introduce new bugs, maintain performance, and update documentation if needed (#3428) ✅

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes were found.

Poem

In fields of code where messages queue,
A rabbit hops, refactoring anew.
No more layers deep inside,
Broker client stands with pride.
Async methods leap and bound,
Transactional checks are safe and sound!
🐇✨
"""


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e3a2957 and 456ad71.

📒 Files selected for processing (1)
  • rocketmq-broker/src/transaction/queue/default_transactional_message_check_listener.rs (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • rocketmq-broker/src/transaction/queue/default_transactional_message_check_listener.rs
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: build (windows-latest, nightly)
  • GitHub Check: build (ubuntu-latest, nightly)
  • GitHub Check: build (macos-latest, nightly)
  • GitHub Check: build (macos-latest, stable)
  • GitHub Check: build (windows-latest, stable)
  • GitHub Check: build
  • GitHub Check: build (ubuntu-latest, stable)
  • GitHub Check: test
  • GitHub Check: auto-approve
✨ 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
Copy Markdown
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💥.

Copilot AI left a comment

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.

Pull Request Overview

This pull request refactors the transactional message check listener structure to simplify its design and enhance message handling for transactional messages.

  • Added async methods (send_check_message and resolve_half_msg) to the TransactionalMessageCheckListenerInner trait for improved message checking.
  • Modified DefaultTransactionalMessageCheckListener to remove the inner field in favor of directly using broker_client and reorganized the inner struct’s definition.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
rocketmq-broker/src/transaction/transactional_message_check_listener.rs Added documentation and new async method signatures to the trait to standardize message checking and resolution.
rocketmq-broker/src/transaction/queue/default_transactional_message_check_listener.rs Refactored the DefaultTransactionalMessageCheckListener by removing the inner field, updating the constructor, and converting resolve_half_msg to an async function.

}

pub fn resolve_half_msg(&self, _msg_ext: MessageExt) -> rocketmq_error::RocketMQResult<()> {
async fn resolve_half_msg(&self, _msg_ext: MessageExt) -> rocketmq_error::RocketMQResult<()> {

Copilot AI Jun 9, 2025

Copy link

Choose a reason for hiding this comment

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

The use of unimplemented!("resolve_half_msg") may lead to runtime panics if this async function is invoked. Consider providing an implementation or clearly documenting that this code path should not be reached in production.

Copilot uses AI. Check for mistakes.
Comment on lines +228 to +235
/* broker_config: Arc<BrokerConfig>,
producer_manager: Arc<ProducerManager>,*/
broker_client: Broker2Client,
broker_runtime_inner: ArcMut<BrokerRuntimeInner<MS>>,
) -> Self {
Self {
/*broker_config,
producer_manager,*/

Copilot AI Jun 9, 2025

Copy link

Choose a reason for hiding this comment

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

[nitpick] There are several commented-out lines in the TransactionalMessageCheckListenerInner::new method. Removing these commented code blocks will improve readability and maintainability.

Suggested change
/* broker_config: Arc<BrokerConfig>,
producer_manager: Arc<ProducerManager>,*/
broker_client: Broker2Client,
broker_runtime_inner: ArcMut<BrokerRuntimeInner<MS>>,
) -> Self {
Self {
/*broker_config,
producer_manager,*/
broker_client: Broker2Client,
broker_runtime_inner: ArcMut<BrokerRuntimeInner<MS>>,
) -> Self {
Self {

Copilot uses AI. Check for mistakes.

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

🔭 Outside diff range comments (3)
rocketmq-broker/src/transaction/queue/default_transactional_message_check_listener.rs (3)

172-180: ⚠️ Potential issue

Handle the error from check_producer_transaction_state.

The error returned by check_producer_transaction_state is currently ignored. This could hide important failures in transaction state checking.

-            let _ = self
+            if let Err(e) = self
                 .broker_client
                 .check_producer_transaction_state(
                     group_id.as_ref().unwrap(),
                     &mut channel,
                     header,
                     msg_ext,
                 )
-                .await;
+                .await {
+                warn!("Failed to check producer transaction state for groupId={:?}: {:?}", group_id, e);
+                return Err(e);
+            }

175-175: ⚠️ Potential issue

Avoid potential panic from unwrap().

While group_id is used to get the channel, calling unwrap() on group_id.as_ref() could panic if group_id is None. The channel existence doesn't guarantee group_id is Some.

-                    group_id.as_ref().unwrap(),
+                    group_id.as_ref().ok_or_else(|| {
+                        rocketmq_error::Error::Custom("Producer group ID is missing".to_string())
+                    })?,

190-199: ⚠️ Potential issue

Implement the resolve_half_msg method.

The method is currently unimplemented and will panic at runtime. Based on the commented code, it seems the intended behavior is to spawn an async task to send check messages.

Would you like me to help implement this method based on the commented logic, or open an issue to track this TODO?

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4223cca and c0a0878.

📒 Files selected for processing (2)
  • rocketmq-broker/src/transaction/queue/default_transactional_message_check_listener.rs (5 hunks)
  • rocketmq-broker/src/transaction/transactional_message_check_listener.rs (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
rocketmq-broker/src/transaction/transactional_message_check_listener.rs (1)
rocketmq-broker/src/transaction/queue/default_transactional_message_check_listener.rs (2)
  • send_check_message (127-188)
  • resolve_half_msg (190-199)
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: build (windows-latest, nightly)
  • GitHub Check: build (macos-latest, nightly)
  • GitHub Check: build (windows-latest, stable)
  • GitHub Check: build (macos-latest, stable)
  • GitHub Check: build (ubuntu-latest, stable)
  • GitHub Check: build (ubuntu-latest, nightly)
  • GitHub Check: test
  • GitHub Check: build
  • GitHub Check: auto-approve
🔇 Additional comments (2)
rocketmq-broker/src/transaction/transactional_message_check_listener.rs (1)

44-79: Well-structured trait additions!

The new async methods send_check_message and resolve_half_msg are properly designed with clear documentation, appropriate error handling, and consistent signatures. The async nature is suitable for these I/O-bound operations.

rocketmq-broker/src/transaction/queue/default_transactional_message_check_listener.rs (1)

43-76: LGTM! Simplified struct design.

The refactoring to remove the inner field and directly embed broker_client simplifies the structure and reduces unnecessary indirection. The Clone implementation and constructor are correctly updated.

@codecov

codecov Bot commented Jun 9, 2025 •

Copy link
Copy Markdown

Codecov Report

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

Project coverage is 25.84%. Comparing base (4223cca) to head (456ad71).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...ue/default_transactional_message_check_listener.rs 0.00% 10 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3429   +/-   ##
=======================================
  Coverage   25.84%   25.84%           
=======================================
  Files         542      542           
  Lines       77056    77032   -24     
=======================================
  Hits        19912    19912           
+ Misses      57144    57120   -24     

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

…ssage_check_listener.rs

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@rocketmq-rust-bot

Copy link
Copy Markdown
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💥.

@rocketmq-rust-bot rocketmq-rust-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

♻️ Duplicate comments (1)
rocketmq-broker/src/transaction/queue/default_transactional_message_check_listener.rs (1)

190-199: ⚠️ Potential issue

Address the unimplemented! macro to prevent runtime panics.

The unimplemented!("resolve_half_msg") will cause runtime panics if this method is called. Either provide a proper implementation or use todo!() with clear documentation about when this will be implemented.

Consider this implementation approach:

-    async fn resolve_half_msg(&self, _msg_ext: MessageExt) -> rocketmq_error::RocketMQResult<()> {
-        /*let this = self.clone();
-        tokio::spawn(async move {
-            if let Err(e) = this.send_check_message(msg_ext).await {
-                warn!("Send check m_msg_extfailed: {:?}", e);
-            }
-        });
-        Ok(())*/
-        unimplemented!("resolve_half_msg")
-    }
+    async fn resolve_half_msg(&self, msg_ext: MessageExt) -> rocketmq_error::RocketMQResult<()> {
+        let this = self.clone();
+        tokio::spawn(async move {
+            if let Err(e) = this.send_check_message(msg_ext).await {
+                warn!("Send check message failed: {:?}", e);
+            }
+        });
+        Ok(())
+    }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c0a0878 and e3a2957.

📒 Files selected for processing (1)
  • rocketmq-broker/src/transaction/queue/default_transactional_message_check_listener.rs (5 hunks)
🧰 Additional context used
🪛 GitHub Actions: CI
rocketmq-broker/src/transaction/queue/default_transactional_message_check_listener.rs

[error] 207-207: cargo fmt check failed. Code formatting issues detected. Run 'cargo fmt' to fix formatting.

⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: automerge
  • GitHub Check: test
  • GitHub Check: build
  • GitHub Check: auto-approve
🔇 Additional comments (3)
rocketmq-broker/src/transaction/queue/default_transactional_message_check_listener.rs (3)

47-47: LGTM: Direct broker_client embedding simplifies structure.

The refactoring to directly embed broker_client as ArcMut<Broker2Client> instead of using an inner struct is a good simplification that reduces indirection.


53-53: LGTM: Constructor and clone implementation properly updated.

The updates to both the Clone implementation and constructor correctly handle the direct broker_client field with proper ArcMut wrapping.

Also applies to: 74-74


127-188: LGTM: Well-implemented async message checking logic.

The send_check_message method is well-structured with proper error handling, message property extraction, and asynchronous broker client communication. The logic correctly handles missing channels with appropriate warnings.

Comment on lines +201 to 208
fn as_any(&self) -> &dyn Any {
self
}

fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
}

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

Fix formatting issues flagged by CI.

The pipeline indicates formatting issues at line 207. Run cargo fmt to resolve the formatting problems.

     fn as_any(&self) -> &dyn Any {
         self
     }

     fn as_any_mut(&mut self) -> &mut dyn Any {
         self
     }

Committable suggestion skipped: line range outside the PR's diff.

🧰 Tools
🪛 GitHub Actions: CI

[error] 207-207: cargo fmt check failed. Code formatting issues detected. Run 'cargo fmt' to fix formatting.

🤖 Prompt for AI Agents
In
rocketmq-broker/src/transaction/queue/default_transactional_message_check_listener.rs
around lines 201 to 208, the code formatting does not comply with the project's
style guidelines as flagged by CI. Run `cargo fmt` on this file to automatically
fix the formatting issues, ensuring consistent indentation, spacing, and line
breaks according to Rust's standard formatting rules.

@rocketmq-rust-bot

Copy link
Copy Markdown
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💥.

@rocketmq-rust-bot rocketmq-rust-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@rocketmq-rust-bot
rocketmq-rust-bot merged commit 1e5a57f into main Jun 9, 2025
@rocketmq-rust-bot rocketmq-rust-bot added approved PR has approved and removed ready to review waiting-review waiting review this PR labels Jun 9, 2025
@mxsm
mxsm deleted the refactor-3428 branch June 14, 2025 15:42
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 refactor♻️ refactor code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Refactor♻️]Refactor DefaultTransactionalMessageCheckListener to simplify structure and enhance message handling

4 participants