Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions rocketmq-store/src/ha.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ pub(crate) mod default_ha_client;
mod default_ha_connection;
pub(crate) mod default_ha_service;
pub(crate) mod flow_monitor;
pub(crate) mod general_ha_client;
pub(crate) mod general_ha_connection;
pub(crate) mod general_ha_service;
pub(crate) mod ha_client;
pub(crate) mod ha_connection;
Expand Down
2 changes: 2 additions & 0 deletions rocketmq-store/src/ha/auto_switch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
pub(crate) mod auto_switch_ha_client;
pub(crate) mod auto_switch_ha_connection;
pub(crate) mod auto_switch_ha_service;
75 changes: 75 additions & 0 deletions rocketmq-store/src/ha/auto_switch/auto_switch_ha_client.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

use crate::ha::ha_client::HAClient;
use crate::ha::ha_connection_state::HAConnectionState;

pub struct AutoSwitchHAClient;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add internal fields to support HA client functionality.

The AutoSwitchHAClient struct is currently empty but needs internal state to manage HA operations like master addresses, connection state, timestamps, etc.

+use std::sync::{Arc, Mutex};
+
-pub struct AutoSwitchHAClient;
+pub struct AutoSwitchHAClient {
+    master_address: Arc<Mutex<String>>,
+    ha_master_address: Arc<Mutex<String>>,
+    last_read_timestamp: Arc<Mutex<i64>>,
+    last_write_timestamp: Arc<Mutex<i64>>,
+    current_state: Arc<Mutex<HAConnectionState>>,
+    transferred_bytes: Arc<Mutex<i64>>,
+}
+
+impl AutoSwitchHAClient {
+    pub fn new() -> Self {
+        Self {
+            master_address: Arc::new(Mutex::new(String::new())),
+            ha_master_address: Arc::new(Mutex::new(String::new())),
+            last_read_timestamp: Arc::new(Mutex::new(0)),
+            last_write_timestamp: Arc::new(Mutex::new(0)),
+            current_state: Arc::new(Mutex::new(HAConnectionState::default())),
+            transferred_bytes: Arc::new(Mutex::new(0)),
+        }
+    }
+}
📝 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.

Suggested change
pub struct AutoSwitchHAClient;
use crate::ha_client::{HAClient, HAConnectionState};
use std::sync::{Arc, Mutex};
pub struct AutoSwitchHAClient {
master_address: Arc<Mutex<String>>,
ha_master_address: Arc<Mutex<String>>,
last_read_timestamp: Arc<Mutex<i64>>,
last_write_timestamp: Arc<Mutex<i64>>,
current_state: Arc<Mutex<HAConnectionState>>,
transferred_bytes: Arc<Mutex<i64>>,
}
impl AutoSwitchHAClient {
pub fn new() -> Self {
Self {
master_address: Arc::new(Mutex::new(String::new())),
ha_master_address: Arc::new(Mutex::new(String::new())),
last_read_timestamp: Arc::new(Mutex::new(0)),
last_write_timestamp: Arc::new(Mutex::new(0)),
current_state: Arc::new(Mutex::new(HAConnectionState::default())),
transferred_bytes: Arc::new(Mutex::new(0)),
}
}
}
🤖 Prompt for AI Agents
In rocketmq-store/src/ha/auto_switch/auto_switch_ha_client.rs at line 21, the
AutoSwitchHAClient struct is empty and lacks the necessary internal fields to
manage HA client functionality. Add fields such as master addresses, connection
state, and timestamps to this struct to properly support HA operations and
maintain internal state.


impl HAClient for AutoSwitchHAClient {
async fn start(&self) {
todo!()

Check warning on line 25 in rocketmq-store/src/ha/auto_switch/auto_switch_ha_client.rs

View check run for this annotation

Codecov / codecov/patch

rocketmq-store/src/ha/auto_switch/auto_switch_ha_client.rs#L24-L25

Added lines #L24 - L25 were not covered by tests
}

async fn shutdown(&self) {
todo!()

Check warning on line 29 in rocketmq-store/src/ha/auto_switch/auto_switch_ha_client.rs

View check run for this annotation

Codecov / codecov/patch

rocketmq-store/src/ha/auto_switch/auto_switch_ha_client.rs#L28-L29

Added lines #L28 - L29 were not covered by tests
Comment on lines +25 to +29
Copy link

Copilot AI Jun 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Multiple functions currently use todo!(); please ensure that these stubs are properly implemented before production deployment to avoid runtime panics.

Suggested change
todo!()
}
async fn shutdown(&self) {
todo!()
// Initialize the client, e.g., set up connections or resources.
println!("AutoSwitchHAClient started.");
}
async fn shutdown(&self) {
// Release resources and close connections.
println!("AutoSwitchHAClient shut down.");

Copilot uses AI. Check for mistakes.
}

async fn wakeup(&self) {
todo!()

Check warning on line 33 in rocketmq-store/src/ha/auto_switch/auto_switch_ha_client.rs

View check run for this annotation

Codecov / codecov/patch

rocketmq-store/src/ha/auto_switch/auto_switch_ha_client.rs#L32-L33

Added lines #L32 - L33 were not covered by tests
}

async fn update_master_address(&self, new_address: &str) {
todo!()

Check warning on line 37 in rocketmq-store/src/ha/auto_switch/auto_switch_ha_client.rs

View check run for this annotation

Codecov / codecov/patch

rocketmq-store/src/ha/auto_switch/auto_switch_ha_client.rs#L36-L37

Added lines #L36 - L37 were not covered by tests
}

async fn update_ha_master_address(&self, new_address: &str) {
todo!()

Check warning on line 41 in rocketmq-store/src/ha/auto_switch/auto_switch_ha_client.rs

View check run for this annotation

Codecov / codecov/patch

rocketmq-store/src/ha/auto_switch/auto_switch_ha_client.rs#L40-L41

Added lines #L40 - L41 were not covered by tests
}

fn get_master_address(&self) -> String {
todo!()

Check warning on line 45 in rocketmq-store/src/ha/auto_switch/auto_switch_ha_client.rs

View check run for this annotation

Codecov / codecov/patch

rocketmq-store/src/ha/auto_switch/auto_switch_ha_client.rs#L44-L45

Added lines #L44 - L45 were not covered by tests
}

fn get_ha_master_address(&self) -> String {
todo!()

Check warning on line 49 in rocketmq-store/src/ha/auto_switch/auto_switch_ha_client.rs

View check run for this annotation

Codecov / codecov/patch

rocketmq-store/src/ha/auto_switch/auto_switch_ha_client.rs#L48-L49

Added lines #L48 - L49 were not covered by tests
}

fn get_last_read_timestamp(&self) -> i64 {
todo!()

Check warning on line 53 in rocketmq-store/src/ha/auto_switch/auto_switch_ha_client.rs

View check run for this annotation

Codecov / codecov/patch

rocketmq-store/src/ha/auto_switch/auto_switch_ha_client.rs#L52-L53

Added lines #L52 - L53 were not covered by tests
}

fn get_last_write_timestamp(&self) -> i64 {
todo!()

Check warning on line 57 in rocketmq-store/src/ha/auto_switch/auto_switch_ha_client.rs

View check run for this annotation

Codecov / codecov/patch

rocketmq-store/src/ha/auto_switch/auto_switch_ha_client.rs#L56-L57

Added lines #L56 - L57 were not covered by tests
}

fn get_current_state(&self) -> HAConnectionState {
todo!()

Check warning on line 61 in rocketmq-store/src/ha/auto_switch/auto_switch_ha_client.rs

View check run for this annotation

Codecov / codecov/patch

rocketmq-store/src/ha/auto_switch/auto_switch_ha_client.rs#L60-L61

Added lines #L60 - L61 were not covered by tests
}

fn change_current_state(&self, ha_connection_state: HAConnectionState) {
todo!()

Check warning on line 65 in rocketmq-store/src/ha/auto_switch/auto_switch_ha_client.rs

View check run for this annotation

Codecov / codecov/patch

rocketmq-store/src/ha/auto_switch/auto_switch_ha_client.rs#L64-L65

Added lines #L64 - L65 were not covered by tests
}

async fn close_master(&self) {
todo!()

Check warning on line 69 in rocketmq-store/src/ha/auto_switch/auto_switch_ha_client.rs

View check run for this annotation

Codecov / codecov/patch

rocketmq-store/src/ha/auto_switch/auto_switch_ha_client.rs#L68-L69

Added lines #L68 - L69 were not covered by tests
}

fn get_transferred_byte_in_second(&self) -> i64 {
todo!()

Check warning on line 73 in rocketmq-store/src/ha/auto_switch/auto_switch_ha_client.rs

View check run for this annotation

Codecov / codecov/patch

rocketmq-store/src/ha/auto_switch/auto_switch_ha_client.rs#L72-L73

Added lines #L72 - L73 were not covered by tests
}
}
Comment on lines +23 to +75
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add documentation explaining the AutoSwitch HA strategy.

The implementation lacks documentation explaining how the AutoSwitch HA client differs from the default HA client and what auto-switching behavior it should provide.

+/// AutoSwitch HA Client that automatically switches between master nodes
+/// based on availability and performance metrics.
+/// 
+/// This client implements intelligent failover logic to ensure high availability
+/// of the RocketMQ broker by monitoring connection health and switching to
+/// backup masters when the primary master becomes unavailable.
 pub struct AutoSwitchHAClient {
     // ... fields
 }

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In rocketmq-store/src/ha/auto_switch/auto_switch_ha_client.rs between lines 23
and 75, add documentation comments to the AutoSwitchHAClient implementation.
Explain the purpose of the AutoSwitch HA client, how it differs from the default
HA client, and describe the auto-switching behavior it provides. Place these
comments above the impl block or each method as appropriate to clarify the
design and functionality for future maintainers.

Comment on lines +24 to +75
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Replace todo!() stubs with basic implementations to prevent runtime panics.

All methods currently use todo!() which will panic if called. Consider implementing basic functionality or at least safe defaults to make the code usable during development.

Here's an example of implementing some basic methods:

 impl HAClient for AutoSwitchHAClient {
     async fn start(&self) {
-        todo!()
+        // TODO: Implement AutoSwitch HA client startup logic
+        println!("AutoSwitchHAClient: start() called");
     }
 
     async fn shutdown(&self) {
-        todo!()
+        // TODO: Implement AutoSwitch HA client shutdown logic
+        println!("AutoSwitchHAClient: shutdown() called");
     }
 
     fn get_master_address(&self) -> String {
-        todo!()
+        self.master_address.lock().unwrap().clone()
     }
 
     fn get_ha_master_address(&self) -> String {
-        todo!()
+        self.ha_master_address.lock().unwrap().clone()
     }
 
     fn get_last_read_timestamp(&self) -> i64 {
-        todo!()
+        *self.last_read_timestamp.lock().unwrap()
     }
 
     fn get_last_write_timestamp(&self) -> i64 {
-        todo!()
+        *self.last_write_timestamp.lock().unwrap()
     }
 
     fn get_current_state(&self) -> HAConnectionState {
-        todo!()
+        *self.current_state.lock().unwrap()
     }
🤖 Prompt for AI Agents
In rocketmq-store/src/ha/auto_switch/auto_switch_ha_client.rs between lines 24
and 75, all methods currently use todo!() which causes runtime panics if called.
Replace these todo!() stubs with basic implementations or safe default returns
to prevent panics during development. For async methods, provide minimal async
blocks that do nothing or log a placeholder; for getters, return default values
like empty strings or zero; for state-related methods, return a default
HAConnectionState or update an internal state variable accordingly. This will
make the code safe to call and easier to extend later.

17 changes: 17 additions & 0 deletions rocketmq-store/src/ha/auto_switch/auto_switch_ha_connection.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
pub struct AutoSwitchHAConnection;
6 changes: 6 additions & 0 deletions rocketmq-store/src/ha/default_ha_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
use std::sync::Arc;

use rocketmq_remoting::protocol::body::ha_runtime_info::HARuntimeInfo;
use rocketmq_rust::ArcMut;
use tracing::error;

use crate::ha::ha_client::HAClient;
Expand All @@ -61,6 +62,11 @@
// The actual implementation would depend on the specific requirements of the HA service.
unimplemented!(" notify_transfer_some method is not implemented");
}

pub(crate) fn init(&mut self, message_store: ArcMut<LocalFileMessageStore>) -> HAResult<()> {

Check warning on line 66 in rocketmq-store/src/ha/default_ha_service.rs

View check run for this annotation

Codecov / codecov/patch

rocketmq-store/src/ha/default_ha_service.rs#L66

Added line #L66 was not covered by tests
// Initialize the DefaultHAService with the provided message store.
Ok(())
}

Check warning on line 69 in rocketmq-store/src/ha/default_ha_service.rs

View check run for this annotation

Codecov / codecov/patch

rocketmq-store/src/ha/default_ha_service.rs#L68-L69

Added lines #L68 - L69 were not covered by tests
}

impl HAService for DefaultHAService {
Expand Down
24 changes: 24 additions & 0 deletions rocketmq-store/src/ha/general_ha_client.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

use crate::ha::auto_switch::auto_switch_ha_client::AutoSwitchHAClient;
use crate::ha::default_ha_client::DefaultHAClient;

pub struct GeneralHAClient {
default_ha_service: Option<DefaultHAClient>,
auto_switch_ha_service: Option<AutoSwitchHAClient>,
Comment on lines +22 to +23
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix naming inconsistency between field names and types.

The field names use "service" suffix but the types are "Client" types. This creates confusion and should be corrected for consistency.

 pub struct GeneralHAClient {
-    default_ha_service: Option<DefaultHAClient>,
-    auto_switch_ha_service: Option<AutoSwitchHAClient>,
+    default_ha_client: Option<DefaultHAClient>,
+    auto_switch_ha_client: Option<AutoSwitchHAClient>,
 }
📝 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.

Suggested change
default_ha_service: Option<DefaultHAClient>,
auto_switch_ha_service: Option<AutoSwitchHAClient>,
pub struct GeneralHAClient {
default_ha_client: Option<DefaultHAClient>,
auto_switch_ha_client: Option<AutoSwitchHAClient>,
}
🤖 Prompt for AI Agents
In rocketmq-store/src/ha/general_ha_client.rs around lines 22 to 23, the field
names use the suffix "service" while their types use "Client," causing
inconsistency. Rename the fields from default_ha_service and
auto_switch_ha_service to default_ha_client and auto_switch_ha_client
respectively to match the type names and maintain clear, consistent naming.

}
Comment on lines +21 to +24
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add constructor methods and accessor functions for the struct.

Similar to GeneralHAConnection, this struct needs constructor methods and accessors to be usable. The implementation pattern should be consistent across both general HA structs.

 pub struct GeneralHAClient {
-    default_ha_service: Option<DefaultHAClient>,
-    auto_switch_ha_service: Option<AutoSwitchHAClient>,
+    default_ha_client: Option<DefaultHAClient>,
+    auto_switch_ha_client: Option<AutoSwitchHAClient>,
 }
+
+impl GeneralHAClient {
+    pub fn new() -> Self {
+        Self {
+            default_ha_client: None,
+            auto_switch_ha_client: None,
+        }
+    }
+
+    pub fn with_default(client: DefaultHAClient) -> Self {
+        Self {
+            default_ha_client: Some(client),
+            auto_switch_ha_client: None,
+        }
+    }
+
+    pub fn with_auto_switch(client: AutoSwitchHAClient) -> Self {
+        Self {
+            default_ha_client: None,
+            auto_switch_ha_client: Some(client),
+        }
+    }
+
+    pub fn get_default_client(&self) -> Option<&DefaultHAClient> {
+        self.default_ha_client.as_ref()
+    }
+
+    pub fn get_auto_switch_client(&self) -> Option<&AutoSwitchHAClient> {
+        self.auto_switch_ha_client.as_ref()
+    }
+}
📝 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.

Suggested change
pub struct GeneralHAClient {
default_ha_service: Option<DefaultHAClient>,
auto_switch_ha_service: Option<AutoSwitchHAClient>,
}
pub struct GeneralHAClient {
default_ha_client: Option<DefaultHAClient>,
auto_switch_ha_client: Option<AutoSwitchHAClient>,
}
impl GeneralHAClient {
/// Creates an empty client with no HA backends configured.
pub fn new() -> Self {
Self {
default_ha_client: None,
auto_switch_ha_client: None,
}
}
/// Creates a client using the given `DefaultHAClient`.
pub fn with_default(client: DefaultHAClient) -> Self {
Self {
default_ha_client: Some(client),
auto_switch_ha_client: None,
}
}
/// Creates a client using the given `AutoSwitchHAClient`.
pub fn with_auto_switch(client: AutoSwitchHAClient) -> Self {
Self {
default_ha_client: None,
auto_switch_ha_client: Some(client),
}
}
/// Returns a reference to the default HA client, if configured.
pub fn get_default_client(&self) -> Option<&DefaultHAClient> {
self.default_ha_client.as_ref()
}
/// Returns a reference to the auto‐switch HA client, if configured.
pub fn get_auto_switch_client(&self) -> Option<&AutoSwitchHAClient> {
self.auto_switch_ha_client.as_ref()
}
}
🤖 Prompt for AI Agents
In rocketmq-store/src/ha/general_ha_client.rs around lines 21 to 24, the
GeneralHAClient struct lacks constructor methods and accessor functions, which
are necessary for consistent usage similar to GeneralHAConnection. Add a
constructor method to initialize GeneralHAClient with appropriate parameters and
implement accessor functions to retrieve references to default_ha_service and
auto_switch_ha_service fields, following the pattern used in GeneralHAConnection
for consistency.

24 changes: 24 additions & 0 deletions rocketmq-store/src/ha/general_ha_connection.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

use crate::ha::auto_switch::auto_switch_ha_connection::AutoSwitchHAConnection;
use crate::ha::default_ha_connection::DefaultHAConnection;

pub struct GeneralHAConnection {
default_ha_connection: Option<DefaultHAConnection>,
auto_switch_ha_connection: Option<AutoSwitchHAConnection>,
}
Comment on lines +21 to +24
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add constructor methods and accessor functions for the struct.

The GeneralHAConnection struct currently has private fields with no way to construct or access them. Consider adding constructor methods and accessors to make the struct usable.

 pub struct GeneralHAConnection {
     default_ha_connection: Option<DefaultHAConnection>,
     auto_switch_ha_connection: Option<AutoSwitchHAConnection>,
 }
+
+impl GeneralHAConnection {
+    pub fn new() -> Self {
+        Self {
+            default_ha_connection: None,
+            auto_switch_ha_connection: None,
+        }
+    }
+
+    pub fn with_default(connection: DefaultHAConnection) -> Self {
+        Self {
+            default_ha_connection: Some(connection),
+            auto_switch_ha_connection: None,
+        }
+    }
+
+    pub fn with_auto_switch(connection: AutoSwitchHAConnection) -> Self {
+        Self {
+            default_ha_connection: None,
+            auto_switch_ha_connection: Some(connection),
+        }
+    }
+
+    pub fn get_default_connection(&self) -> Option<&DefaultHAConnection> {
+        self.default_ha_connection.as_ref()
+    }
+
+    pub fn get_auto_switch_connection(&self) -> Option<&AutoSwitchHAConnection> {
+        self.auto_switch_ha_connection.as_ref()
+    }
+}
📝 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.

Suggested change
pub struct GeneralHAConnection {
default_ha_connection: Option<DefaultHAConnection>,
auto_switch_ha_connection: Option<AutoSwitchHAConnection>,
}
pub struct GeneralHAConnection {
default_ha_connection: Option<DefaultHAConnection>,
auto_switch_ha_connection: Option<AutoSwitchHAConnection>,
}
impl GeneralHAConnection {
pub fn new() -> Self {
Self {
default_ha_connection: None,
auto_switch_ha_connection: None,
}
}
pub fn with_default(connection: DefaultHAConnection) -> Self {
Self {
default_ha_connection: Some(connection),
auto_switch_ha_connection: None,
}
}
pub fn with_auto_switch(connection: AutoSwitchHAConnection) -> Self {
Self {
default_ha_connection: None,
auto_switch_ha_connection: Some(connection),
}
}
pub fn get_default_connection(&self) -> Option<&DefaultHAConnection> {
self.default_ha_connection.as_ref()
}
pub fn get_auto_switch_connection(&self) -> Option<&AutoSwitchHAConnection> {
self.auto_switch_ha_connection.as_ref()
}
}
🤖 Prompt for AI Agents
In rocketmq-store/src/ha/general_ha_connection.rs around lines 21 to 24, the
GeneralHAConnection struct has private fields without any constructor or
accessor methods. Add a constructor method (e.g., new) to initialize the struct
with given DefaultHAConnection and AutoSwitchHAConnection options, and implement
getter methods to access these private fields safely from outside the struct.

4 changes: 3 additions & 1 deletion rocketmq-store/src/ha/general_ha_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@
{
self.auto_switch_ha_service = Some(AutoSwitchHAService)
} else {
self.default_ha_service = Some(DefaultHAService::default())
let mut default_ha_service = DefaultHAService::default();
default_ha_service.init(message_store)?;
self.default_ha_service = Some(default_ha_service);

Check warning on line 54 in rocketmq-store/src/ha/general_ha_service.rs

View check run for this annotation

Codecov / codecov/patch

rocketmq-store/src/ha/general_ha_service.rs#L52-L54

Added lines #L52 - L54 were not covered by tests
}
Ok(())
}
Expand Down
Loading