@@ -25,6 +25,7 @@ impl std::fmt::Display for Environment {
2525 }
2626}
2727
28+ /// Doris configuration model with all system settings
2829#[ derive( Debug , Clone ) ]
2930pub struct DorisConfig {
3031 pub environment : Environment ,
@@ -159,8 +160,16 @@ fn clean_process_info(config: &mut DorisConfig) {
159160 config. be_install_dir = None ;
160161}
161162
162- fn update_mixed_deployment ( config : & mut DorisConfig ) -> Result < ( ) > {
163+ /// Update mixed deployment detection and environment setting
164+ fn update_mixed_environment ( config : & mut DorisConfig ) -> Result < ( ) > {
165+ // Detect if both FE and BE processes are running
163166 process_detector:: detect_mixed_deployment ( config) ?;
167+
168+ // Update environment to Mixed if both FE and BE processes are detected
169+ if config. fe_process_pid . is_some ( ) && config. be_process_pid . is_some ( ) {
170+ config. environment = Environment :: Mixed ;
171+ }
172+
164173 Ok ( ( ) )
165174}
166175
@@ -170,13 +179,48 @@ fn persist_configuration(config: &DorisConfig) {
170179 }
171180}
172181
173- /// Update environment to Mixed if both FE and BE processes are detected
174- fn update_environment_for_mixed_deployment ( config : & mut DorisConfig ) {
175- if config. fe_process_pid . is_some ( ) && config. be_process_pid . is_some ( ) {
176- config. environment = Environment :: Mixed ;
182+ /// Apply environment-specific port configurations
183+ fn apply_environment_specific_ports (
184+ config : & mut DorisConfig ,
185+ parsed_config : & DorisConfig ,
186+ env : Environment ,
187+ ) {
188+ match env {
189+ Environment :: BE => {
190+ apply_be_ports ( config, parsed_config) ;
191+ }
192+ Environment :: FE => {
193+ apply_fe_ports ( config, parsed_config) ;
194+ }
195+ Environment :: Mixed => {
196+ // For Mixed environment, apply both BE and FE configurations
197+ apply_be_ports ( config, parsed_config) ;
198+ apply_fe_ports ( config, parsed_config) ;
199+ }
200+ Environment :: Unknown => {
201+ // No specific ports to apply for unknown environment
202+ }
177203 }
178204}
179205
206+ /// Apply BE-specific port configurations
207+ fn apply_be_ports ( config : & mut DorisConfig , parsed_config : & DorisConfig ) {
208+ config. be_port = parsed_config. be_port ;
209+ config. brpc_port = parsed_config. brpc_port ;
210+ config. webserver_port = parsed_config. webserver_port ;
211+ config. heartbeat_service_port = parsed_config. heartbeat_service_port ;
212+ }
213+
214+ /// Apply FE-specific port configurations
215+ fn apply_fe_ports ( config : & mut DorisConfig , parsed_config : & DorisConfig ) {
216+ config. http_port = parsed_config. http_port ;
217+ config. rpc_port = parsed_config. rpc_port ;
218+ config. query_port = parsed_config. query_port ;
219+ config. edit_log_port = parsed_config. edit_log_port ;
220+ config. cloud_http_port = parsed_config. cloud_http_port ;
221+ config. meta_dir = parsed_config. meta_dir . clone ( ) ;
222+ }
223+
180224/// Load configuration, first from persisted file, then detect environment and generate if needed
181225pub fn load_config ( ) -> Result < DorisConfig > {
182226 let mut config = config_persister:: load_persisted_config ( ) . unwrap_or_default ( ) ;
@@ -185,14 +229,10 @@ pub fn load_config() -> Result<DorisConfig> {
185229 Ok ( current_process) => {
186230 if needs_config_update ( & config, & current_process) {
187231 config = update_config_from_process ( config, current_process) ?;
188-
189- let _ = update_mixed_deployment ( & mut config) ;
190- update_environment_for_mixed_deployment ( & mut config) ;
191-
232+ let _ = update_mixed_environment ( & mut config) ;
192233 persist_configuration ( & config) ;
193234 } else {
194- let _ = update_mixed_deployment ( & mut config) ;
195- update_environment_for_mixed_deployment ( & mut config) ;
235+ let _ = update_mixed_environment ( & mut config) ;
196236 }
197237 }
198238 Err ( _) => {
@@ -215,7 +255,7 @@ fn parse_env_specific_config(env: Environment) -> DorisConfig {
215255 let result = match env {
216256 Environment :: BE => config_parser:: parse_be_config ( ) ,
217257 Environment :: FE => config_parser:: parse_fe_config ( ) ,
218- Environment :: Mixed => config_parser:: parse_be_config ( ) , // For Mixed, we'll start with BE config and add FE later
258+ Environment :: Mixed => config_parser:: parse_be_config ( ) ,
219259 Environment :: Unknown => return DorisConfig :: default ( ) ,
220260 } ;
221261 result. unwrap_or_else ( |_| DorisConfig :: default ( ) )
@@ -235,8 +275,7 @@ fn fallback_load_config() -> Result<DorisConfig> {
235275
236276 // If we detect both FE and BE processes, update to Mixed environment
237277 if env != Environment :: Unknown {
238- let _ = update_mixed_deployment ( & mut config) ;
239- update_environment_for_mixed_deployment ( & mut config) ;
278+ let _ = update_mixed_environment ( & mut config) ;
240279 }
241280
242281 persist_configuration ( & config) ;
@@ -253,11 +292,6 @@ pub fn to_app_config(doris_config: DorisConfig) -> crate::config::Config {
253292 }
254293}
255294
256- /// Get the current Doris configuration
257- pub fn get_current_config ( ) -> Result < DorisConfig > {
258- load_config ( )
259- }
260-
261295/// Get current process PID from configuration (convenience function)
262296pub fn get_current_pid ( ) -> Option < u32 > {
263297 load_config ( ) . ok ( ) ?. get_valid_pid ( )
@@ -299,38 +333,8 @@ fn update_config_from_process(
299333 if let Ok ( parsed_config) =
300334 config_parser:: parse_config_from_path ( process. environment , & process. doris_home )
301335 {
302- match process. environment {
303- Environment :: BE => {
304- config. be_port = parsed_config. be_port ;
305- config. brpc_port = parsed_config. brpc_port ;
306- config. webserver_port = parsed_config. webserver_port ;
307- config. heartbeat_service_port = parsed_config. heartbeat_service_port ;
308- }
309- Environment :: FE => {
310- config. http_port = parsed_config. http_port ;
311- config. rpc_port = parsed_config. rpc_port ;
312- config. query_port = parsed_config. query_port ;
313- config. edit_log_port = parsed_config. edit_log_port ;
314- config. cloud_http_port = parsed_config. cloud_http_port ;
315- config. meta_dir = parsed_config. meta_dir ;
316- }
317- Environment :: Mixed => {
318- // For Mixed environment, we'll update both BE and FE ports
319- config. be_port = parsed_config. be_port ;
320- config. brpc_port = parsed_config. brpc_port ;
321- config. webserver_port = parsed_config. webserver_port ;
322- config. heartbeat_service_port = parsed_config. heartbeat_service_port ;
323- config. http_port = parsed_config. http_port ;
324- config. rpc_port = parsed_config. rpc_port ;
325- config. query_port = parsed_config. query_port ;
326- config. edit_log_port = parsed_config. edit_log_port ;
327- config. cloud_http_port = parsed_config. cloud_http_port ;
328- config. meta_dir = parsed_config. meta_dir ;
329- }
330- Environment :: Unknown => {
331- // This shouldn't happen as detect_current_process only returns FE/BE
332- }
333- }
336+ // Apply port configurations based on environment
337+ apply_environment_specific_ports ( & mut config, & parsed_config, process. environment ) ;
334338 }
335339
336340 Ok ( config)
0 commit comments