-
Notifications
You must be signed in to change notification settings - Fork 159
[ISSUE #3527]⚡️Delegation pattern implementation with error handling for HA connections #3528
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
…for HA connections
🔊@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💥. |
WalkthroughThe changes implement the delegation pattern for Changes
Sequence Diagram(s)sequenceDiagram
participant AcceptSocketService
participant DefaultHAConnection
participant GeneralHAConnection
participant DefaultHAService
AcceptSocketService->>DefaultHAConnection: new()
DefaultHAConnection-->>AcceptSocketService: Result<DefaultHAConnection>
AcceptSocketService->>GeneralHAConnection: new_with_default_ha_connection()
AcceptSocketService->>GeneralHAConnection: start()
alt DefaultHAConnection present
GeneralHAConnection->>DefaultHAConnection: start()
DefaultHAConnection-->>GeneralHAConnection: Result<(), HAConnectionError>
else AutoSwitchHAConnection present
GeneralHAConnection->>AutoSwitchHAConnection: start()
AutoSwitchHAConnection-->>GeneralHAConnection: Result<(), HAConnectionError>
else None present
GeneralHAConnection-->>AcceptSocketService: Err("No HA connection set")
end
alt start() Ok
AcceptSocketService->>DefaultHAService: add_connection(general_conn)
else start() Err
AcceptSocketService->>AcceptSocketService: Log error
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
|
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
The PR implements the delegation pattern in the HA connection startup logic and adds error handling when accepting new HA connections.
- Implements
GeneralHAConnection::start
to delegate to either default or auto-switch connections, returning an error if neither is set. - Updates the accept path in
default_ha_service
to start theGeneralHAConnection
, log failures, and only add the connection on success.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
rocketmq-store/src/ha/general_ha_connection.rs | Adds the body for start , delegating to underlying connections and returning a clear error branch. |
rocketmq-store/src/ha/default_ha_service.rs | Calls start on the new GeneralHAConnection , logs errors, and conditionally registers the connection. |
Comments suppressed due to low confidence (2)
rocketmq-store/src/ha/general_ha_connection.rs:66
- Add unit tests for
GeneralHAConnection::start
to cover all branches (default, auto-switch, and error) to validate the new delegation logic.
if let Some(ref mut connection) = self.default_ha_connection {
rocketmq-store/src/ha/default_ha_service.rs:298
- [nitpick] Align the
if let
formatting by removing extra spaces:if let Err(e) = general_conn.start().await { ... }
to match project style conventions.
if let Err(e) = general_conn.start().await {
if let Some(ref mut connection) = self.default_ha_connection { | ||
connection.start().await | ||
} else if let Some(ref mut connection) = self.auto_switch_ha_connection { | ||
connection.start().await | ||
} else { | ||
Err(HAConnectionError::Connection( | ||
"No HA connection set".to_string(), | ||
)) |
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.
[nitpick] The nested if let
blocks could be refactored into a single match
on both Option
s (or by chaining with or
) to reduce duplication and improve clarity.
if let Some(ref mut connection) = self.default_ha_connection { | |
connection.start().await | |
} else if let Some(ref mut connection) = self.auto_switch_ha_connection { | |
connection.start().await | |
} else { | |
Err(HAConnectionError::Connection( | |
"No HA connection set".to_string(), | |
)) | |
match (&mut self.default_ha_connection, &mut self.auto_switch_ha_connection) { | |
(Some(connection), _) => connection.start().await, | |
(_, Some(connection)) => connection.start().await, | |
(None, None) => Err(HAConnectionError::Connection( | |
"No HA connection set".to_string(), | |
)), |
Copilot uses AI. Check for mistakes.
default_ha_service.add_connection(general_conn).await; | ||
let mut general_conn = GeneralHAConnection::new_with_default_ha_connection(default_conn); | ||
if let Err(e) = general_conn.start().await { | ||
error!("Error starting HAService: {}", e); |
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.
On startup failure, the connection isn't explicitly closed or cleaned up. Consider closing the underlying stream or reporting the error upstream to avoid resource leaks.
error!("Error starting HAService: {}", e); | |
error!("Error starting HAService: {}", e); | |
// Explicitly clean up resources to prevent leaks | |
general_conn.cleanup().await; |
Copilot uses AI. Check for mistakes.
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
🧹 Nitpick comments (1)
rocketmq-store/src/ha/default_ha_service.rs (1)
301-301
: Consider improving the success log message for clarity.The success log message "HAService accept new connection" duplicates the message from line 292. Consider making it more specific to indicate the connection was successfully started.
- info!("HAService accept new connection, {}", addr); + info!("HAService successfully started connection, {}", addr);
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
rocketmq-store/src/ha/default_ha_service.rs
(1 hunks)rocketmq-store/src/ha/general_ha_connection.rs
(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (9)
- 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 (macos-latest, stable)
- GitHub Check: build (ubuntu-latest, nightly)
- GitHub Check: test
- GitHub Check: build
- GitHub Check: auto-approve
🔇 Additional comments (2)
rocketmq-store/src/ha/general_ha_connection.rs (1)
66-74
: Excellent implementation of the delegation pattern with proper error handling.The delegation logic correctly prioritizes
default_ha_connection
overauto_switch_ha_connection
and provides a clear error message when neither connection type is configured. The implementation follows a clean fallback strategy that aligns with the PR objectives.rocketmq-store/src/ha/default_ha_service.rs (1)
297-303
: Robust error handling implementation for connection lifecycle management.The enhancement correctly ensures that only successfully started connections are added to the service. The asynchronous error handling prevents failed connections from being managed, which improves the overall reliability of the HA service.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3528 +/- ##
==========================================
- Coverage 26.18% 26.18% -0.01%
==========================================
Files 556 556
Lines 78641 78651 +10
==========================================
Hits 20593 20593
- Misses 58048 58058 +10 ☔ 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 #3527
Brief Description
How Did You Test This Change?
Summary by CodeRabbit
Bug Fixes
New Features