@@ -36,12 +36,15 @@ use std::sync::atomic::AtomicI64;
3636use std:: sync:: atomic:: AtomicU64 ;
3737use std:: sync:: Arc ;
3838
39+ use rocketmq_common:: common:: broker:: broker_role:: BrokerRole ;
3940use rocketmq_remoting:: protocol:: body:: ha_runtime_info:: HARuntimeInfo ;
4041use rocketmq_rust:: ArcMut ;
4142use tracing:: error;
4243
44+ use crate :: ha:: default_ha_client:: DefaultHAClient ;
4345use crate :: ha:: general_ha_client:: GeneralHAClient ;
4446use crate :: ha:: general_ha_connection:: GeneralHAConnection ;
47+ use crate :: ha:: general_ha_service:: GeneralHAService ;
4548use crate :: ha:: group_transfer_service:: GroupTransferService ;
4649use crate :: ha:: ha_client:: HAClient ;
4750use crate :: ha:: ha_connection:: HAConnection ;
@@ -51,6 +54,7 @@ use crate::ha::ha_service::HAService;
5154use crate :: ha:: wait_notify_object:: WaitNotifyObject ;
5255use crate :: log_file:: flush_manager_impl:: group_commit_request:: GroupCommitRequest ;
5356use crate :: message_store:: local_file_message_store:: LocalFileMessageStore ;
57+ use crate :: store_error:: HAError ;
5458use crate :: store_error:: HAResult ;
5559
5660pub struct DefaultHAService {
@@ -62,7 +66,7 @@ pub struct DefaultHAService {
6266 push2_slave_max_offset : Arc < AtomicU64 > ,
6367 group_transfer_service : Option < GroupTransferService > ,
6468 ha_client : GeneralHAClient ,
65- ha_connection_state_notification_service : HAConnectionStateNotificationService ,
69+ ha_connection_state_notification_service : Option < HAConnectionStateNotificationService > ,
6670}
6771
6872impl DefaultHAService {
@@ -76,7 +80,7 @@ impl DefaultHAService {
7680 push2_slave_max_offset : Arc :: new ( AtomicU64 :: new ( 0 ) ) ,
7781 group_transfer_service : None ,
7882 ha_client : GeneralHAClient :: new ( ) ,
79- ha_connection_state_notification_service : HAConnectionStateNotificationService ,
83+ ha_connection_state_notification_service : None ,
8084 }
8185 }
8286
@@ -91,8 +95,22 @@ impl DefaultHAService {
9195 unimplemented ! ( " notify_transfer_some method is not implemented" ) ;
9296 }
9397
94- pub ( crate ) fn init ( & mut self ) -> HAResult < ( ) > {
98+ pub ( crate ) fn init ( & mut self , this : ArcMut < Self > ) -> HAResult < ( ) > {
9599 // Initialize the DefaultHAService with the provided message store.
100+ let config = self . default_message_store . get_message_store_config ( ) ;
101+ let service = GeneralHAService :: new_with_default_ha_service ( this. clone ( ) ) ;
102+ let group_transfer_service = GroupTransferService :: new ( config. clone ( ) , service. clone ( ) ) ;
103+ self . group_transfer_service = Some ( group_transfer_service) ;
104+
105+ if config. broker_role == BrokerRole :: Slave {
106+ let default_message_store = self . default_message_store . clone ( ) ;
107+ let client = DefaultHAClient :: new ( default_message_store)
108+ . map_err ( |e| HAError :: Service ( format ! ( "Failed to create DefaultHAClient: {e}" ) ) ) ?;
109+ self . ha_client . set_default_ha_service ( client)
110+ }
111+ let state_notification_service =
112+ HAConnectionStateNotificationService :: new ( service, self . default_message_store . clone ( ) ) ;
113+ self . ha_connection_state_notification_service = Some ( state_notification_service) ;
96114 Ok ( ( ) )
97115 }
98116}
0 commit comments