-
Notifications
You must be signed in to change notification settings - Fork 174
[ISSUE #4025]Introduce ChannelId type alias for improved clarity in channel struct #4026
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
Conversation
WalkthroughIntroduces a ChannelId type alias, updates Channel struct’s channel_id field to use it, adds a Channel::new constructor that assigns a UUID string to channel_id, and adds a setter method to update channel_id. The existing channel_id accessor continues returning &str. Changes
Sequence Diagram(s)sequenceDiagram
participant Caller
participant Channel
participant UUID as UUID Generator
Caller->>Channel: Channel::new(inner, local_addr, remote_addr)
activate Channel
Channel->>UUID: new_v4()
UUID-->>Channel: uuid
Channel->>Channel: channel_id = uuid.to_string()
Channel-->>Caller: Channel { channel_id, ... }
deactivate Channel
Note over Caller,Channel: Setter path
Caller->>Channel: set_channel_id(value)
Channel->>Channel: channel_id = value.into()
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Pre-merge checks (5 passed)✅ Passed checks (5 passed)
Poem
✨ Finishing touches
🧪 Generate unit tests
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. Comment |
🔊@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💥. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces a ChannelId
type alias to improve code clarity and maintainability in the channel module by replacing direct usage of CheetahString
for channel identifiers.
- Introduces
ChannelId
as a type alias forCheetahString
- Updates the
Channel
struct to use the newChannelId
type for thechannel_id
field
Comments suppressed due to low confidence (1)
rocketmq-remoting/src/net/channel.rs:1
- The
set_channel_id
method parameter should useChannelId
orimpl Into<ChannelId>
instead ofimpl Into<CheetahString>
for consistency with the new type alias.
/*
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4026 +/- ##
=======================================
Coverage 26.57% 26.57%
=======================================
Files 565 565
Lines 80722 80722
=======================================
Hits 21453 21453
Misses 59269 59269 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this 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
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
rocketmq-remoting/src/net/channel.rs (1)
73-76
: Avoid mutating fields that participate in Eq/Hash (can corrupt HashMap/HashSet invariants).
Channel
implements Eq/Hash usingchannel_id
(and addresses). Exposingset_channel_id
means aChannel
used as a key in hashed collections can be mutated, breaking lookups. Restrict visibility and add a warning; also acceptInto<ChannelId>
to avoid leaking the underlying alias.Apply:
- #[inline] - pub fn set_channel_id(&mut self, channel_id: impl Into<CheetahString>) { - self.channel_id = channel_id.into(); - } + #[inline] + /// Sets the channel ID. + /// + /// WARNING: Mutating `channel_id` after inserting `Channel` into hashed collections + /// (HashMap/HashSet) will corrupt collection invariants. Prefer setting only during init. + pub(crate) fn set_channel_id(&mut self, channel_id: impl Into<ChannelId>) { + self.channel_id = channel_id.into(); + }Also consider similarly restricting
set_local_address
andset_remote_address
for the same reason.Also applies to: 99-115
🧹 Nitpick comments (2)
rocketmq-remoting/src/net/channel.rs (2)
38-39
: Tiny doc nit: annotate the alias to convey intent.- pub type ChannelId = CheetahString; + /// Logical identifier for a Channel (alias for `CheetahString`). + pub type ChannelId = CheetahString;
49-61
: uuid present in workspace; consider scoping Channel::new
- Root/workspace Cargo.toml includes uuid with the "v4" feature and rocketmq-remoting uses
uuid = { workspace = true }
, soUuid::new_v4()
is supported.- If
Channel::new
is not intended as part of the public API, changepub fn new(...) -> Self
topub(crate) fn new(...) -> Self
in rocketmq-remoting/src/net/channel.rs (lines ~49–61).
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
rocketmq-remoting/src/net/channel.rs
(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
- GitHub Check: build (macos-latest, stable)
- GitHub Check: build (macos-latest, nightly)
- GitHub Check: build (windows-latest, stable)
- GitHub Check: build (windows-latest, nightly)
- 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-remoting/src/net/channel.rs (2)
45-46
: Field type swap to ChannelId improves readability. LGTM.
88-91
: Accessor returning &str keeps callers decoupled from the alias. LGTM.
Which Issue(s) This PR Fixes(Closes)
Fixes #4025
Brief Description
How Did You Test This Change?
Summary by CodeRabbit
New Features
Refactor