Skip to content

Commit 644d4ea

Browse files
authored
[ISSUE #3503]🚀Implement General HA components and complete AutoSwitch HA implementation✨ (#3504)
1 parent b48f78b commit 644d4ea

File tree

8 files changed

+153
-1
lines changed

8 files changed

+153
-1
lines changed

rocketmq-store/src/ha.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ pub(crate) mod default_ha_client;
2020
mod default_ha_connection;
2121
pub(crate) mod default_ha_service;
2222
pub(crate) mod flow_monitor;
23+
pub(crate) mod general_ha_client;
24+
pub(crate) mod general_ha_connection;
2325
pub(crate) mod general_ha_service;
2426
pub(crate) mod ha_client;
2527
pub(crate) mod ha_connection;

rocketmq-store/src/ha/auto_switch.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17+
pub(crate) mod auto_switch_ha_client;
18+
pub(crate) mod auto_switch_ha_connection;
1719
pub(crate) mod auto_switch_ha_service;
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
use crate::ha::ha_client::HAClient;
19+
use crate::ha::ha_connection_state::HAConnectionState;
20+
21+
pub struct AutoSwitchHAClient;
22+
23+
impl HAClient for AutoSwitchHAClient {
24+
async fn start(&self) {
25+
todo!()
26+
}
27+
28+
async fn shutdown(&self) {
29+
todo!()
30+
}
31+
32+
async fn wakeup(&self) {
33+
todo!()
34+
}
35+
36+
async fn update_master_address(&self, new_address: &str) {
37+
todo!()
38+
}
39+
40+
async fn update_ha_master_address(&self, new_address: &str) {
41+
todo!()
42+
}
43+
44+
fn get_master_address(&self) -> String {
45+
todo!()
46+
}
47+
48+
fn get_ha_master_address(&self) -> String {
49+
todo!()
50+
}
51+
52+
fn get_last_read_timestamp(&self) -> i64 {
53+
todo!()
54+
}
55+
56+
fn get_last_write_timestamp(&self) -> i64 {
57+
todo!()
58+
}
59+
60+
fn get_current_state(&self) -> HAConnectionState {
61+
todo!()
62+
}
63+
64+
fn change_current_state(&self, ha_connection_state: HAConnectionState) {
65+
todo!()
66+
}
67+
68+
async fn close_master(&self) {
69+
todo!()
70+
}
71+
72+
fn get_transferred_byte_in_second(&self) -> i64 {
73+
todo!()
74+
}
75+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
pub struct AutoSwitchHAConnection;

rocketmq-store/src/ha/default_ha_service.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ use std::sync::atomic::AtomicI64;
3636
use std::sync::Arc;
3737

3838
use rocketmq_remoting::protocol::body::ha_runtime_info::HARuntimeInfo;
39+
use rocketmq_rust::ArcMut;
3940
use tracing::error;
4041

4142
use crate::ha::ha_client::HAClient;
@@ -61,6 +62,11 @@ impl DefaultHAService {
6162
// The actual implementation would depend on the specific requirements of the HA service.
6263
unimplemented!(" notify_transfer_some method is not implemented");
6364
}
65+
66+
pub(crate) fn init(&mut self, message_store: ArcMut<LocalFileMessageStore>) -> HAResult<()> {
67+
// Initialize the DefaultHAService with the provided message store.
68+
Ok(())
69+
}
6470
}
6571

6672
impl HAService for DefaultHAService {
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
use crate::ha::auto_switch::auto_switch_ha_client::AutoSwitchHAClient;
19+
use crate::ha::default_ha_client::DefaultHAClient;
20+
21+
pub struct GeneralHAClient {
22+
default_ha_service: Option<DefaultHAClient>,
23+
auto_switch_ha_service: Option<AutoSwitchHAClient>,
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
use crate::ha::auto_switch::auto_switch_ha_connection::AutoSwitchHAConnection;
19+
use crate::ha::default_ha_connection::DefaultHAConnection;
20+
21+
pub struct GeneralHAConnection {
22+
default_ha_connection: Option<DefaultHAConnection>,
23+
auto_switch_ha_connection: Option<AutoSwitchHAConnection>,
24+
}

rocketmq-store/src/ha/general_ha_service.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ impl GeneralHAService {
4949
{
5050
self.auto_switch_ha_service = Some(AutoSwitchHAService)
5151
} else {
52-
self.default_ha_service = Some(DefaultHAService::default())
52+
let mut default_ha_service = DefaultHAService::default();
53+
default_ha_service.init(message_store)?;
54+
self.default_ha_service = Some(default_ha_service);
5355
}
5456
Ok(())
5557
}

0 commit comments

Comments
 (0)