risingwave_common/config/
system.rs

1// Copyright 2025 RisingWave Labs
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! [`SystemConfig`] is used to initialize [system parameters](crate::system_param) persisted in Meta store.
16
17use super::*;
18
19macro_rules! define_system_config {
20    ($({ $field:ident, $type:ty, $default:expr, $is_mutable:expr, $doc:literal, $($rest:tt)* },)*) => {
21        paste::paste!(
22            /// The section `[system]` in `risingwave.toml`. All these fields are used to initialize the [system
23            /// parameters](crate::system_param) persisted in Meta store. Most fields are for testing purpose only and should not be
24            /// documented.
25            #[derive(Clone, Debug, Serialize, Deserialize, DefaultFromSerde, ConfigDoc)]
26            pub struct SystemConfig {
27                $(
28                    #[doc = $doc]
29                    #[serde(default = "default::system::" $field "_opt")]
30                    pub $field: Option<$type>,
31                )*
32            }
33        );
34    };
35}
36
37for_all_params!(define_system_config);
38
39impl SystemConfig {
40    #![allow(deprecated)]
41    pub fn into_init_system_params(self) -> SystemParams {
42        macro_rules! fields {
43            ($({ $field:ident, $($rest:tt)* },)*) => {
44                SystemParams {
45                    $($field: self.$field.map(Into::into),)*
46                    ..Default::default() // deprecated fields
47                }
48            };
49        }
50
51        let mut system_params = for_all_params!(fields);
52
53        // Initialize backup_storage_url and backup_storage_directory if not set.
54        if let Some(state_store) = &system_params.state_store
55            && let Some(data_directory) = &system_params.data_directory
56        {
57            if system_params.backup_storage_url.is_none() {
58                if let Some(hummock_state_store) = state_store.strip_prefix("hummock+") {
59                    system_params.backup_storage_url = Some(hummock_state_store.to_owned());
60                } else {
61                    system_params.backup_storage_url = Some("memory".to_owned());
62                }
63                tracing::info!("initialize backup_storage_url based on state_store");
64            }
65            if system_params.backup_storage_directory.is_none() {
66                system_params.backup_storage_directory = Some(format!("{data_directory}/backup"));
67                tracing::info!("initialize backup_storage_directory based on data_directory");
68            }
69        }
70        system_params
71    }
72}
73
74pub mod default {
75    pub use crate::system_param::default as system;
76}