-
Notifications
You must be signed in to change notification settings - Fork 240
[ISSUE #3510]🚀Implement Comprehensive High Availability (HA) Subsystem Architecture with Enhanced Service Infrastructure✨ #3511
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -23,7 +23,6 @@ | |||||||||||||
| use rocketmq_rust::ArcMut; | ||||||||||||||
| use tracing::error; | ||||||||||||||
|
|
||||||||||||||
| use crate::base::message_store::MessageStore; | ||||||||||||||
| use crate::ha::auto_switch::auto_switch_ha_service::AutoSwitchHAService; | ||||||||||||||
| use crate::ha::default_ha_service::DefaultHAService; | ||||||||||||||
| use crate::ha::ha_client::HAClient; | ||||||||||||||
|
|
@@ -36,21 +35,37 @@ | |||||||||||||
| use crate::store_error::HAError; | ||||||||||||||
| use crate::store_error::HAResult; | ||||||||||||||
|
|
||||||||||||||
| #[derive(Clone)] | ||||||||||||||
| pub struct GeneralHAService { | ||||||||||||||
| default_ha_service: Option<DefaultHAService>, | ||||||||||||||
| auto_switch_ha_service: Option<AutoSwitchHAService>, | ||||||||||||||
| default_ha_service: Option<ArcMut<DefaultHAService>>, | ||||||||||||||
| auto_switch_ha_service: Option<ArcMut<AutoSwitchHAService>>, | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| impl GeneralHAService { | ||||||||||||||
| pub fn new() -> Self { | ||||||||||||||
| GeneralHAService { | ||||||||||||||
| default_ha_service: None, | ||||||||||||||
| auto_switch_ha_service: None, | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| pub fn new_with_default_ha_service(default_ha_service: ArcMut<DefaultHAService>) -> Self { | ||||||||||||||
| GeneralHAService { | ||||||||||||||
| default_ha_service: Some(default_ha_service), | ||||||||||||||
| auto_switch_ha_service: None, | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| pub(crate) fn init(&mut self, message_store: ArcMut<LocalFileMessageStore>) -> HAResult<()> { | ||||||||||||||
| if message_store | ||||||||||||||
| .get_message_store_config() | ||||||||||||||
| .enable_controller_mode | ||||||||||||||
| { | ||||||||||||||
| self.auto_switch_ha_service = Some(AutoSwitchHAService) | ||||||||||||||
| self.auto_switch_ha_service = Some(ArcMut::new(AutoSwitchHAService)) | ||||||||||||||
| } else { | ||||||||||||||
| let mut default_ha_service = DefaultHAService::new(message_store); | ||||||||||||||
| default_ha_service.init()?; | ||||||||||||||
| let mut default_ha_service = ArcMut::new(DefaultHAService::new(message_store)); | ||||||||||||||
| let default_ha_service_clone = default_ha_service.clone(); | ||||||||||||||
| DefaultHAService::init(&mut default_ha_service, default_ha_service_clone)?; | ||||||||||||||
|
Comment on lines
+66
to
+68
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix incorrect static method call. The call to - let mut default_ha_service = ArcMut::new(DefaultHAService::new(message_store));
- let default_ha_service_clone = default_ha_service.clone();
- DefaultHAService::init(&mut default_ha_service, default_ha_service_clone)?;
+ let mut default_ha_service = ArcMut::new(DefaultHAService::new(message_store));
+ let default_ha_service_clone = default_ha_service.clone();
+ default_ha_service.init(default_ha_service_clone)?;📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||
| self.default_ha_service = Some(default_ha_service); | ||||||||||||||
| } | ||||||||||||||
| Ok(()) | ||||||||||||||
|
|
||||||||||||||
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.
🛠️ Refactor suggestion
Reconsider Clone derive for shared mutable state.
Adding
Cloneto a struct containingArcMutfields can lead to unexpected behavior where multiple clones share the same mutable state. This could violate Rust's safety guarantees and make reasoning about state mutations difficult.Consider removing the
Clonederive or implementing it explicitly with proper documentation about the shared state implications:-#[derive(Clone)] pub struct GeneralHAService {🤖 Prompt for AI Agents