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 #2349]🤡Connection supports send bytes 🧑‍💻 #2352

Merged
merged 1 commit into from
Jan 20, 2025

Conversation

mxsm
Copy link
Owner

@mxsm mxsm commented Jan 20, 2025

Which Issue(s) This PR Fixes(Closes)

Fixes #2349

Brief Description

How Did You Test This Change?

Summary by CodeRabbit

Release Notes

  • Refactor

    • Updated command handling methods across multiple components
    • Introduced new methods for sending and receiving commands in network connections
    • Replaced existing command codec with a more flexible composite codec
  • Performance

    • Improved command transmission and reception mechanisms
    • Enhanced network communication handling
  • Technical Improvements

    • Streamlined asynchronous command processing
    • Updated error handling for network communication

Copy link
Contributor

coderabbitai bot commented Jan 20, 2025

Walkthrough

The pull request introduces significant changes to the RocketMQ remoting module, focusing on refactoring command handling and communication mechanisms. The primary modifications involve replacing the existing command transmission methods with new receive_command() and send_command() methods across multiple files. A new CompositeCodec is introduced to replace the previous RemotingCommandCodec, suggesting an enhanced approach to encoding and decoding network frames. These changes aim to improve the flexibility and robustness of command processing within the RocketMQ Rust implementation.

Changes

File Change Summary
rocketmq-remoting/src/clients/client.rs - Replaced channel.connection.reader.next() with connection.receive_command()
- Updated command sending method to connection.send_command()
rocketmq-remoting/src/connection.rs - Replaced RemotingCommandCodec with CompositeCodec
- Added new receive_command() and send_command() methods
- Updated reader and writer type signatures
rocketmq-remoting/src/net/channel.rs - Modified command sending to use connection.send_command()
rocketmq-remoting/src/remoting_server/server.rs - Updated ConnectionHandler to use receive_command() and send_command()
- Changed handle() method to be async
rocketmq-remoting/src/runtime/connection_handler_context.rs - Updated command sending method to connection.send_command()

Assessment against linked issues

Objective Addressed Explanation
Connection supports send bytes [#2349]

Possibly related PRs

Suggested labels

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

Suggested reviewers

  • TeslaRustor
  • SpaceXCN
  • rocketmq-rust-bot

Poem

🚀 Bytes dance through the wire's embrace,
Codec's magic leaves no trace,
Commands flow with newfound grace,
RocketMQ's Rust takes quantum's pace,
A symphony of network's lace! 🌟


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.

@RocketmqRustBot RocketmqRustBot added this to the v0.4.0 milestone Jan 20, 2025
@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💥.

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

🧹 Nitpick comments (3)
rocketmq-remoting/src/connection.rs (1)

65-68: Consider deriving Hash and PartialEq instead of manual implementations

The manual implementations of Hash and PartialEq use the addresses of writer and reader, which may not provide consistent behavior and could lead to unexpected results due to pointer uniqueness rather than content. Deriving these traits automatically ensures that hashing and equality checks are based on the content of the fields and reduces the risk of errors.

Apply this diff to derive Hash, PartialEq, and Eq traits:

+#[derive(Hash, PartialEq, Eq)]
 pub struct Connection {
     /// The `Framed` instance used for reading from and writing to the TCP stream.
     //pub(crate) framed: Framed<TcpStream, RemotingCommandCodec>,
     writer: SplitSink<Framed<TcpStream, CompositeCodec>, BytesMut>,
     reader: SplitStream<Framed<TcpStream, CompositeCodec>>,

     /// A boolean flag indicating the current state of the connection.
     /// `true` means the connection is in a good state, while `false` indicates
     /// there are issues with the connection.
     pub(crate) ok: bool,
 }
 
-impl Hash for Connection {
-    fn hash<H: Hasher>(&self, state: &mut H) {
-        // Hash the boolean flag
-        self.ok.hash(state);
-
-        // Use the addresses of writer and reader to hash them (they serve as a unique
-        // identifier for these components)
-        let writer_addr: *const SplitSink<Framed<TcpStream, CompositeCodec>, BytesMut> =
-            &self.writer as *const SplitSink<Framed<TcpStream, CompositeCodec>, BytesMut>;
-        let reader_addr: *const SplitStream<Framed<TcpStream, CompositeCodec>> =
-            &self.reader as *const SplitStream<Framed<TcpStream, CompositeCodec>>;
-
-        writer_addr.hash(state);
-        reader_addr.hash(state);
-    }
-}
-
-impl PartialEq for Connection {
-    fn eq(&self, other: &Self) -> bool {
-        // Compare the boolean flag
-        self.ok == other.ok
-
-        // Compare the addresses of writer and reader
-            && (std::ptr::eq(&self.writer, &other.writer))
-            && (std::ptr::eq(&self.reader, &other.reader))
-    }
-}
-
-impl Eq for Connection {}
rocketmq-remoting/src/remoting_server/server.rs (2)

Line range hint 185-196: Fix spacing in select macro.

There's inconsistent spacing in the select macro. Add a space after result =.

-                result =self.connection_handler_context.channel.connection.send_command(response.set_opaque(opaque))
+                result = self.connection_handler_context.channel.connection.send_command(response.set_opaque(opaque))

Line range hint 217-238: Consider refactoring duplicated error handling.

The error handling pattern is duplicated across multiple select blocks. Consider extracting it into a helper method.

async fn handle_send_error(&mut self, err: RemotingError) -> HandleErrorResult {
    match err {
        RemotingError::Io(io_error) => {
            error!("send response failed: {}", io_error);
            HandleErrorResult::ReturnMethod
        }
        _ => {
            error!("send response failed: {}", err);
            HandleErrorResult::Continue
        }
    }
}

Also, fix the spacing in the select macros:

-                result =self.connection_handler_context.channel.connection.send_command(response.set_opaque(opaque))
+                result = self.connection_handler_context.channel.connection.send_command(response.set_opaque(opaque))
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3fef11a and 2d6e40a.

📒 Files selected for processing (5)
  • rocketmq-remoting/src/clients/client.rs (3 hunks)
  • rocketmq-remoting/src/connection.rs (4 hunks)
  • rocketmq-remoting/src/net/channel.rs (1 hunks)
  • rocketmq-remoting/src/remoting_server/server.rs (4 hunks)
  • rocketmq-remoting/src/runtime/connection_handler_context.rs (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: build (windows-latest, nightly)
  • GitHub Check: build (windows-latest, stable)
  • GitHub Check: build (macos-latest, nightly)
  • GitHub Check: build (macos-latest, stable)
  • GitHub Check: build (ubuntu-latest, nightly)
  • GitHub Check: build
  • GitHub Check: test
  • GitHub Check: auto-approve
  • GitHub Check: build (ubuntu-latest, stable)
🔇 Additional comments (7)
rocketmq-remoting/src/connection.rs (1)

123-147: New methods receive_command and send_command enhance abstraction

The addition of receive_command and send_command methods improves the abstraction for sending and receiving commands over the connection. This encapsulates the underlying implementation details and enhances code readability and maintainability.

rocketmq-remoting/src/runtime/connection_handler_context.rs (1)

Line range hint 47-51: Update to send_command improves error handling consistency

Using the send_command method aligns the command-sending mechanism with the updated Connection API and ensures consistent error handling across the codebase.

rocketmq-remoting/src/net/channel.rs (1)

Line range hint 69-83: Refactored to use send_command method for command transmission

Updating to use send_command method in the run_send function simplifies the code and leverages the encapsulated sending logic within Connection, improving maintainability.

rocketmq-remoting/src/clients/client.rs (3)

72-72: LGTM! Improved method naming.

The change from reader.next() to receive_command() better encapsulates the command reception logic and improves code readability.


194-194: LGTM! Consistent method naming.

The change to send_command() maintains consistency with the receive_command pattern and better represents the method's purpose.


327-327: LGTM! Consistent error handling.

The change to receive_command() maintains consistency with other changes while preserving robust error handling for connection issues.

rocketmq-remoting/src/remoting_server/server.rs (1)

114-114: LGTM! Consistent with client implementation.

The change to receive_command() aligns with the client-side changes while maintaining proper shutdown handling.

Copy link
Collaborator

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

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 7364329 into main Jan 20, 2025
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 Jan 20, 2025
Copy link

codecov bot commented Jan 20, 2025

Codecov Report

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

Project coverage is 28.41%. Comparing base (3fef11a) to head (2d6e40a).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
rocketmq-remoting/src/connection.rs 0.00% 22 Missing ⚠️
rocketmq-remoting/src/remoting_server/server.rs 0.00% 4 Missing ⚠️
rocketmq-remoting/src/clients/client.rs 0.00% 3 Missing ⚠️
rocketmq-remoting/src/net/channel.rs 0.00% 1 Missing ⚠️
...remoting/src/runtime/connection_handler_context.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2352      +/-   ##
==========================================
- Coverage   28.41%   28.41%   -0.01%     
==========================================
  Files         505      505              
  Lines       72835    72847      +12     
==========================================
  Hits        20699    20699              
- Misses      52136    52148      +12     

☔ 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. rocketmq-remoting crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature🚀] Connection supports send bytes
3 participants