-
Notifications
You must be signed in to change notification settings - Fork 159
[ISSUE #3470]🚀Enhance HAConnectionState with additional methods for state management and transitions✨ #3471
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
…tate management and transitions✨
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.
Copilot reviewed 1 out of 1 changed files in this pull request and generated no comments.
WalkthroughThe Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant StateMachine as HAConnectionStateMachine
participant State as HAConnectionState
participant Error as HAConnectionStateError
Client->>StateMachine: transition_to(new_state)
StateMachine->>State: can_transition_to(new_state)
alt Valid transition
State-->>StateMachine: true
StateMachine->>StateMachine: Update state, increment count
StateMachine-->>Client: Ok
else Invalid transition
State-->>StateMachine: false
StateMachine->>Error: Create InvalidTransition error
StateMachine-->>Client: Err(InvalidTransition)
end
Assessment against linked issues
Poem
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
Documentation and Community
|
🔊@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.
Actionable comments posted: 1
🧹 Nitpick comments (3)
rocketmq-store/src/ha/ha_connection_state.rs (3)
360-365
: Remove redundant pattern inis_regression_transition
(Transfer, Shutdown)
is already covered by(_, Shutdown)
.
Keeping both is harmless but noisy; dropping the specific arm reduces cognitive load.
163-174
: Question default-to-Ready on unknown stringsSilently mapping unknown input to
Ready
can hide configuration / deserialization errors.
Consider returning aResult
or falling back toErr(InvalidValue)
instead of a silent default.
42-53
: Use a const slice instead of allocating aVec
all_states
always returns the same fixed data; a&'static [Self]
avoids allocation:pub const ALL_STATES: &[HAConnectionState] = &[ HAConnectionState::Ready, HAConnectionState::Handshake, HAConnectionState::Transfer, HAConnectionState::Suspend, HAConnectionState::Shutdown, ];Callers can iterate or convert to
Vec
when necessary.
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
rocketmq-store/src/ha/ha_connection_state.rs
(2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (9)
- GitHub Check: auto-approve
- GitHub Check: test
- GitHub Check: build
- GitHub Check: build (windows-latest, nightly)
- GitHub Check: build (macos-latest, stable)
- GitHub Check: build (macos-latest, nightly)
- GitHub Check: build (ubuntu-latest, nightly)
- GitHub Check: build (ubuntu-latest, stable)
- GitHub Check: build (windows-latest, stable)
/// Check if the connection can transition to the given state | ||
pub fn can_transition_to(&self, target: HAConnectionState) -> bool { | ||
use HAConnectionState::*; | ||
|
||
match (self, target) { | ||
// From Ready | ||
(Ready, Handshake) => true, | ||
(Ready, Shutdown) => true, | ||
|
||
// From Handshake | ||
(Handshake, Transfer) => true, | ||
(Handshake, Shutdown) => true, | ||
|
||
// From Transfer | ||
(Transfer, Suspend) => true, | ||
(Transfer, Shutdown) => true, | ||
|
||
// From Suspend | ||
(Suspend, Transfer) => true, | ||
(Suspend, Shutdown) => true, | ||
|
||
// From Shutdown (terminal state) | ||
(Shutdown, _) => false, | ||
|
||
// Same state | ||
(state, target) if state == &target => true, | ||
|
||
// Invalid transitions | ||
_ => false, | ||
} | ||
} |
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.
Fix ordering bug – Shutdown ➜ Shutdown
falsely marked invalid
The (Shutdown, _) => false
arm precedes the “same-state” arm, so
can_transition_to(Shutdown, Shutdown)
wrongly returns false
.
Swap the check order or add a specific (Shutdown, Shutdown)
case before the catch-all.
- // From Shutdown (terminal state)
- (Shutdown, _) => false,
-
- // Same state
- (state, target) if state == &target => true,
+ // Same state
+ (state, target) if state == &target => true,
+
+ // From Shutdown (terminal state) to any **other** state
+ (Shutdown, _) => false,
Without this, the state machine can never acknowledge an already-terminated connection.
📝 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.
/// Check if the connection can transition to the given state | |
pub fn can_transition_to(&self, target: HAConnectionState) -> bool { | |
use HAConnectionState::*; | |
match (self, target) { | |
// From Ready | |
(Ready, Handshake) => true, | |
(Ready, Shutdown) => true, | |
// From Handshake | |
(Handshake, Transfer) => true, | |
(Handshake, Shutdown) => true, | |
// From Transfer | |
(Transfer, Suspend) => true, | |
(Transfer, Shutdown) => true, | |
// From Suspend | |
(Suspend, Transfer) => true, | |
(Suspend, Shutdown) => true, | |
// From Shutdown (terminal state) | |
(Shutdown, _) => false, | |
// Same state | |
(state, target) if state == &target => true, | |
// Invalid transitions | |
_ => false, | |
} | |
} | |
/// Check if the connection can transition to the given state | |
pub fn can_transition_to(&self, target: HAConnectionState) -> bool { | |
use HAConnectionState::*; | |
match (self, target) { | |
// From Ready | |
(Ready, Handshake) => true, | |
(Ready, Shutdown) => true, | |
// From Handshake | |
(Handshake, Transfer) => true, | |
(Handshake, Shutdown) => true, | |
// From Transfer | |
(Transfer, Suspend) => true, | |
(Transfer, Shutdown) => true, | |
// From Suspend | |
(Suspend, Transfer) => true, | |
(Suspend, Shutdown) => true, | |
// Same state | |
(state, target) if state == &target => true, | |
// From Shutdown (terminal state) to any **other** state | |
(Shutdown, _) => false, | |
// Invalid transitions | |
_ => false, | |
} | |
} |
🤖 Prompt for AI Agents
In rocketmq-store/src/ha/ha_connection_state.rs lines 80 to 110, the match arms
in can_transition_to incorrectly return false for the transition from Shutdown
to Shutdown because the catch-all Shutdown arm comes before the same-state
check. Fix this by either moving the same-state arm before the Shutdown
catch-all or adding a specific (Shutdown, Shutdown) arm before the (Shutdown, _)
arm to correctly allow this transition.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3471 +/- ##
==========================================
+ Coverage 26.47% 26.59% +0.11%
==========================================
Files 545 545
Lines 77759 77961 +202
==========================================
+ Hits 20583 20730 +147
- Misses 57176 57231 +55 ☔ 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
Which Issue(s) This PR Fixes(Closes)
Fixes #3470
Brief Description
How Did You Test This Change?
Summary by CodeRabbit