Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[ISSUE #1482]♻️Refactor create MQClientErr replace with mq_client_err! macro🔥 #1483

Merged
merged 1 commit into from
Dec 1, 2024

Conversation

mxsm
Copy link
Owner

@mxsm mxsm commented Dec 1, 2024

Which Issue(s) This PR Fixes(Closes)

Fixes #1482

Brief Description

How Did You Test This Change?

Summary by CodeRabbit

  • New Features

    • Introduced a Shutdown struct for managing shutdown signals with a Tokio broadcast channel.
    • Added methods to the Shutdown struct for checking shutdown status and receiving notifications.
  • Bug Fixes

    • Streamlined error handling across various components by replacing verbose error constructions with a new macro mq_client_err!.
  • Documentation

    • Updated import statements to utilize the new error handling macro consistently across multiple files.

Copy link
Contributor

coderabbitai bot commented Dec 1, 2024

Walkthrough

The changes in this pull request primarily focus on refactoring error handling across various components of the RocketMQ client. The existing error handling patterns that utilized MQClientErr and ClientErr have been replaced with a new macro, mq_client_err!, which standardizes and simplifies error reporting. This refactor affects multiple files, particularly in validation, consumer, producer, and utility classes, while maintaining the overall control flow and logic of the methods.

Changes

File Path Change Summary
rocketmq-client/src/base/validators.rs Replaced error handling with mq_client_err! in validation methods.
rocketmq-client/src/consumer/consumer_impl/default_mq_push_consumer_impl.rs Updated error handling in start, shutdown, check_config, and subscribe methods using mq_client_err!.
rocketmq-client/src/consumer/consumer_impl/pull_api_wrapper.rs Modified error handling in pull_kernel_impl and compute_pull_from_which_filter_server using mq_client_err!.
rocketmq-client/src/consumer/consumer_impl/re_balance/rebalance_push_impl.rs Updated error handling in compute_pull_from_where_with_exception using mq_client_err!.
rocketmq-client/src/consumer/store/local_file_offset_store.rs Changed error handling in read_local_offset and read_local_offset_bak using mq_client_err!.
rocketmq-client/src/consumer/store/remote_broker_offset_store.rs Updated error handling for broker not found using mq_client_err!.
rocketmq-client/src/factory/mq_client_instance.rs Replaced error handling in start and check_client_in_broker methods with mq_client_err!.
rocketmq-client/src/implementation/mq_admin_impl.rs Modified error handling in fetch_publish_message_queues using mq_client_err!.
rocketmq-client/src/implementation/mq_client_api_impl.rs Updated multiple methods to use mq_client_err! for error handling.
rocketmq-client/src/producer/default_mq_producer.rs Changed error handling in batch method to use mq_client_err!.
rocketmq-client/src/producer/producer_impl/default_mq_producer_impl.rs Updated several methods to utilize mq_client_err! for error reporting.
rocketmq-client/src/utils/message_util.rs Replaced error handling in create_reply_message with mq_client_err!.
rocketmq/src/shutdown.rs Introduced Shutdown struct with methods for managing shutdown signals using a Tokio broadcast channel.

Assessment against linked issues

Objective Addressed Explanation
Refactor error handling to use mq_client_err! (1482)

Possibly related PRs

Suggested labels

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

Suggested reviewers

  • TeslaRustor
  • SpaceXCN

"In the code where errors did dwell,
A macro emerged, casting its spell.
With mq_client_err!, clarity's gained,
Simplifying the paths where errors had reigned.
A refactor so neat, like a rabbit's quick hop,
In the world of code, we’ll never stop!" 🐇✨


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 🔥

Copy link

codecov bot commented Dec 1, 2024

Codecov Report

Attention: Patch coverage is 8.69565% with 147 lines in your changes missing coverage. Please review.

Project coverage is 22.32%. Comparing base (bd5d50b) to head (1a74476).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...mer/consumer_impl/default_mq_push_consumer_impl.rs 0.00% 43 Missing ⚠️
...producer/producer_impl/default_mq_producer_impl.rs 0.00% 33 Missing ⚠️
rocketmq-client/src/base/validators.rs 43.75% 18 Missing ⚠️
...er/consumer_impl/re_balance/rebalance_push_impl.rs 0.00% 17 Missing ⚠️
...mq-client/src/implementation/mq_client_api_impl.rs 0.00% 15 Missing ⚠️
...ent/src/consumer/consumer_impl/pull_api_wrapper.rs 0.00% 7 Missing ⚠️
...ient/src/consumer/store/local_file_offset_store.rs 0.00% 3 Missing ⚠️
rocketmq-client/src/factory/mq_client_instance.rs 0.00% 3 Missing ⚠️
rocketmq-client/src/utils/message_util.rs 0.00% 3 Missing ⚠️
...t/src/consumer/store/remote_broker_offset_store.rs 0.00% 2 Missing ⚠️
... and 2 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1483      +/-   ##
==========================================
+ Coverage   22.30%   22.32%   +0.02%     
==========================================
  Files         450      450              
  Lines       58309    58244      -65     
==========================================
- Hits        13006    13004       -2     
+ Misses      45303    45240      -63     

☔ 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: 0

🧹 Outside diff range and nitpick comments (6)
rocketmq-client/src/implementation/mq_admin_impl.rs (1)

Line range hint 123-124: Add TODO comment for unimplemented method.

Consider adding a TODO comment explaining the intended implementation and tracking it with an issue.

 pub async fn search_offset(&mut self, mq: &MessageQueue, timestamp: u64) -> Result<i64> {
-    unimplemented!("max_offset")
+    // TODO: Implement search_offset functionality
+    // See issue #<number> for implementation details
+    unimplemented!("search_offset")
 }
rocketmq-client/src/base/validators.rs (1)

39-39: Consider enhancing error message clarity.

The error message could be more specific about the requirements.

-            return mq_client_err!("the specified group is blank");
+            return mq_client_err!("the specified group cannot be empty or contain only whitespace");
rocketmq-client/src/consumer/store/local_file_offset_store.rs (1)

103-106: Enhance error message clarity

Consider including the deserialization error in the message for better debugging.

-                Err(_) => mq_client_err!(format!(
-                    "read local offset bak failed, content: {}",
-                    content
-                )),
+                Err(e) => mq_client_err!(format!(
+                    "Failed to deserialize backup local offset. Error: {}, Content: {}",
+                    e, content
+                )),
rocketmq-client/src/consumer/store/remote_broker_offset_store.rs (1)

320-320: Consider extracting common error handling

This error message is identical to the one in fetch_consume_offset_from_broker. Consider extracting it to a helper function.

fn broker_not_found_error(broker_name: &str) -> crate::Result<()> {
    mq_client_err!(format!("broker not found, {}", broker_name))
}
rocketmq-client/src/consumer/consumer_impl/pull_api_wrapper.rs (2)

363-363: Remove trailing comma in error message

There's an unnecessary trailing comma in the format string.

-            mq_client_err!(format!("The broker[{}] not exist", mq.get_broker_name(),))
+            mq_client_err!(format!("The broker[{}] not exist", mq.get_broker_name()))

380-390: Consolidate duplicate error messages

The same error message is repeated twice. Consider extracting it to a helper function.

fn filter_server_not_found_error(broker_addr: &str, topic: &str) -> crate::Result<CheetahString> {
    mq_client_err!(format!(
        "Find Filter Server Failed, Broker Addr: {},topic:{}",
        broker_addr, topic
    ))
}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between bd5d50b and 1a74476.

📒 Files selected for processing (13)
  • rocketmq-client/src/base/validators.rs (5 hunks)
  • rocketmq-client/src/consumer/consumer_impl/default_mq_push_consumer_impl.rs (6 hunks)
  • rocketmq-client/src/consumer/consumer_impl/pull_api_wrapper.rs (4 hunks)
  • rocketmq-client/src/consumer/consumer_impl/re_balance/rebalance_push_impl.rs (5 hunks)
  • rocketmq-client/src/consumer/store/local_file_offset_store.rs (3 hunks)
  • rocketmq-client/src/consumer/store/remote_broker_offset_store.rs (3 hunks)
  • rocketmq-client/src/factory/mq_client_instance.rs (3 hunks)
  • rocketmq-client/src/implementation/mq_admin_impl.rs (2 hunks)
  • rocketmq-client/src/implementation/mq_client_api_impl.rs (5 hunks)
  • rocketmq-client/src/producer/default_mq_producer.rs (2 hunks)
  • rocketmq-client/src/producer/producer_impl/default_mq_producer_impl.rs (13 hunks)
  • rocketmq-client/src/utils/message_util.rs (2 hunks)
  • rocketmq/src/shutdown.rs (0 hunks)
💤 Files with no reviewable changes (1)
  • rocketmq/src/shutdown.rs
🔇 Additional comments (24)
rocketmq-client/src/utils/message_util.rs (1)

75-81: LGTM! Error handling refactor looks good.

The error handling has been successfully migrated to use the mq_client_err! macro while maintaining the same error message and semantics.

rocketmq-client/src/implementation/mq_admin_impl.rs (1)

90-93: LGTM! Error handling refactor looks good.

The error handling has been successfully migrated to use the mq_client_err! macro while maintaining clear error messaging.

rocketmq-client/src/base/validators.rs (1)

39-39: LGTM! Error handling refactoring is consistent and well-implemented.

The migration to mq_client_err! macro has been done consistently across all validation methods while maintaining the original error semantics and codes.

Also applies to: 43-43, 47-51, 61-64, 71-74, 79-82, 86-92, 100-107, 116-116, 120-123, 127-131, 139-142, 149-149, 157-160, 169-172

rocketmq-client/src/consumer/store/local_file_offset_store.rs (1)

91-91: LGTM: Clean error handling refactor

The error handling has been cleanly refactored to use the mq_client_err! macro while maintaining clear error messaging.

rocketmq-client/src/consumer/store/remote_broker_offset_store.rs (1)

113-113: LGTM: Clear error message

The error handling is concise and provides the necessary broker information for debugging.

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

302-308: LGTM: Well-formatted error message

The error message is comprehensive and well-formatted, including all necessary details about broker version and tag filtering support.

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

275-275: LGTM! Consistent error handling pattern.

The refactoring to use the mq_client_err! macro across all error cases in the compute_pull_from_where_with_exception method is well-implemented. The error handling is consistent and maintains proper error context.

Also applies to: 306-309, 321-324, 362-365, 370-373

rocketmq-client/src/producer/default_mq_producer.rs (1)

493-493: LGTM! Proper error handling with logging.

The error handling in the batch method appropriately logs the error details before using the mq_client_err! macro to return the error.

rocketmq-client/src/factory/mq_client_instance.rs (1)

333-336: LGTM! Clear and descriptive error handling.

The error handling using the mq_client_err! macro is well-implemented in both methods:

  1. start: Provides clear context about the factory object state
  2. check_client_in_broker: Includes detailed explanation about potential version compatibility issues

Also applies to: 989-989

rocketmq-client/src/implementation/mq_client_api_impl.rs (4)

256-259: LGTM: Error handling refactored consistently

The error handling has been standardized using the mq_client_err! macro while preserving the original error information and behavior.

Also applies to: 262-265


725-728: LGTM: Error handling standardized

The error handling has been appropriately refactored to use the mq_client_err! macro while maintaining the same error information.


764-766: LGTM: Error handling refactored appropriately

The error handling has been standardized using the mq_client_err! macro while preserving the original error behavior.


1263-1266: LGTM: Error handling standardized consistently

The error handling has been appropriately refactored to use the mq_client_err! macro while maintaining the same error information.

rocketmq-client/src/producer/producer_impl/default_mq_producer_impl.rs (7)

429-429: LGTM: Error handling standardized appropriately

The error handling has been refactored to use the mq_client_err! macro while maintaining the original error information.

Also applies to: 433-433


874-896: LGTM: Error handling refactored consistently across multiple cases

The error handling has been standardized using the mq_client_err! macro across multiple error cases while preserving the original error behavior and information.


967-967: LGTM: Error handling standardized

The error handling has been appropriately refactored to use the mq_client_err! macro while maintaining the same error information.


1789-1795: LGTM: Error handling refactored appropriately

The error handling has been standardized using the mq_client_err! macro while preserving the original error information.


1870-1870: LGTM: Error handling standardized

The error handling has been appropriately refactored to use the mq_client_err! macro while maintaining the same error information.


2224-2229: LGTM: Error handling standardized consistently

The error handling has been appropriately refactored to use the mq_client_err! macro across multiple error cases while maintaining the original error information.

Also applies to: 2242-2242, 2245-2245, 2248-2252


2270-2274: LGTM: Error handling refactored appropriately

The error handling has been standardized using the mq_client_err! macro while preserving the original error information.

rocketmq-client/src/consumer/consumer_impl/default_mq_push_consumer_impl.rs (4)

358-358: LGTM: Error handling standardized consistently

The error handling has been appropriately refactored to use the mq_client_err! macro across multiple error cases while maintaining the original error information.

Also applies to: 361-361, 364-368


Line range hint 448-608: LGTM: Error handling refactored consistently across validation checks

The error handling has been standardized using the mq_client_err! macro across multiple validation checks while preserving the original error information and behavior.


673-673: LGTM: Error handling standardized

The error handling has been appropriately refactored to use the mq_client_err! macro while maintaining the same error information.


971-975: LGTM: Error handling refactored appropriately

The error handling has been standardized using the mq_client_err! macro while preserving the original error information.

@rocketmq-rust-bot rocketmq-rust-bot merged commit 2f5f0c6 into main Dec 1, 2024
24 of 25 checks passed
@rocketmq-rust-bot rocketmq-rust-bot added approved PR has approved and removed ready to review waiting-review waiting review this PR labels Dec 1, 2024
@mxsm mxsm deleted the refactor-1482 branch December 3, 2024 14:22
# for free to join this conversation on GitHub. Already have an account? # 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 create MQClientErr replace with mq_client_err! macro
4 participants