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            #[serde_with::apply(Option => #[serde(with = "none_as_empty_string")])]
26            #[derive(Clone, Debug, Serialize, Deserialize, DefaultFromSerde, ConfigDoc)]
27            pub struct SystemConfig {
28                $(
29                    #[doc = $doc]
30                    #[serde(default = "default::system::" $field "_opt")]
31                    pub $field: Option<$type>,
32                )*
33            }
34        );
35    };
36}
37
38for_all_params!(define_system_config);
39
40impl SystemConfig {
41    #![allow(deprecated)]
42    pub fn into_init_system_params(self) -> SystemParams {
43        macro_rules! fields {
44            ($({ $field:ident, $($rest:tt)* },)*) => {
45                SystemParams {
46                    $($field: self.$field.map(Into::into),)*
47                    ..Default::default() // deprecated fields
48                }
49            };
50        }
51
52        let mut system_params = for_all_params!(fields);
53
54        // Initialize backup_storage_url and backup_storage_directory if not set.
55        if let Some(state_store) = &system_params.state_store
56            && let Some(data_directory) = &system_params.data_directory
57        {
58            if system_params.backup_storage_url.is_none() {
59                if let Some(hummock_state_store) = state_store.strip_prefix("hummock+") {
60                    system_params.backup_storage_url = Some(hummock_state_store.to_owned());
61                } else {
62                    system_params.backup_storage_url = Some("memory".to_owned());
63                }
64                tracing::info!("initialize backup_storage_url based on state_store");
65            }
66            if system_params.backup_storage_directory.is_none() {
67                system_params.backup_storage_directory = Some(format!("{data_directory}/backup"));
68                tracing::info!("initialize backup_storage_directory based on data_directory");
69            }
70        }
71        system_params
72    }
73}
74
75pub mod default {
76    pub use crate::system_param::default as system;
77}