risingwave_common/system_param/
reader.rs1use std::borrow::Borrow;
16use std::str::FromStr;
17
18use risingwave_license::LicenseKeyRef;
19use risingwave_pb::meta::PbSystemParams;
20
21use super::{AdaptiveParallelismStrategy, ParamValue, default};
22use crate::for_all_params;
23
24pub struct ParameterInfo {
28 pub name: &'static str,
29 pub mutable: bool,
30 pub value: String,
35 pub description: &'static str,
36}
37
38macro_rules! define_system_params_read_trait {
39 ($({ $field:ident, $type:ty, $default:expr, $is_mutable:expr, $doc:literal, $($rest:tt)* },)*) => {
40 pub trait SystemParamsRead {
48 $(
49 #[doc = $doc]
50 fn $field(&self) -> <$type as ParamValue>::Borrowed<'_>;
51 )*
52
53 fn get_all(&self) -> Vec<ParameterInfo> {
55 vec![
56 $(
57 ParameterInfo {
58 name: stringify!($field),
59 mutable: $is_mutable,
60 value: self.$field().to_string(), description: $doc,
62 },
63 )*
64 ]
65 }
66 }
67 };
68}
69
70for_all_params!(define_system_params_read_trait);
71
72#[derive(Clone, PartialEq)]
77pub struct SystemParamsReader<I = PbSystemParams> {
78 inner: I,
79}
80
81macro_rules! impl_system_params_reader_debug {
84 ($({ $field:ident, $($rest:tt)* },)*) => {
85 impl<I> std::fmt::Debug for SystemParamsReader<I>
86 where
87 I: Borrow<PbSystemParams>,
88 {
89 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
90 f.debug_struct("SystemParamsReader")
91 $(
92 .field(stringify!($field), &self.$field())
93 )*
94 .finish()
95 }
96 }
97 };
98}
99
100for_all_params!(impl_system_params_reader_debug);
101
102impl<I> From<I> for SystemParamsReader<I>
103where
104 I: Borrow<PbSystemParams>,
105{
106 fn from(inner: I) -> Self {
107 Self { inner }
108 }
109}
110
111impl<I> SystemParamsReader<I>
112where
113 I: Borrow<PbSystemParams>,
114{
115 pub fn new(inner: I) -> Self {
116 Self { inner }
117 }
118
119 pub fn as_ref(&self) -> SystemParamsReader<&PbSystemParams> {
121 SystemParamsReader {
122 inner: self.inner(),
123 }
124 }
125
126 fn inner(&self) -> &PbSystemParams {
127 self.inner.borrow()
128 }
129}
130
131impl<I> SystemParamsRead for SystemParamsReader<I>
136where
137 I: Borrow<PbSystemParams>,
138{
139 fn barrier_interval_ms(&self) -> u32 {
140 self.inner().barrier_interval_ms.unwrap()
141 }
142
143 fn checkpoint_frequency(&self) -> u64 {
144 self.inner().checkpoint_frequency.unwrap()
145 }
146
147 fn parallel_compact_size_mb(&self) -> u32 {
148 self.inner().parallel_compact_size_mb.unwrap()
149 }
150
151 fn sstable_size_mb(&self) -> u32 {
152 self.inner().sstable_size_mb.unwrap()
153 }
154
155 fn block_size_kb(&self) -> u32 {
156 self.inner().block_size_kb.unwrap()
157 }
158
159 fn bloom_false_positive(&self) -> f64 {
160 self.inner().bloom_false_positive.unwrap()
161 }
162
163 fn state_store(&self) -> &str {
164 self.inner().state_store.as_ref().unwrap()
165 }
166
167 fn data_directory(&self) -> &str {
168 self.inner().data_directory.as_ref().unwrap()
169 }
170
171 fn use_new_object_prefix_strategy(&self) -> bool {
172 *self
173 .inner()
174 .use_new_object_prefix_strategy
175 .as_ref()
176 .unwrap()
177 }
178
179 fn backup_storage_url(&self) -> &str {
180 self.inner().backup_storage_url.as_ref().unwrap()
181 }
182
183 fn backup_storage_directory(&self) -> &str {
184 self.inner().backup_storage_directory.as_ref().unwrap()
185 }
186
187 fn max_concurrent_creating_streaming_jobs(&self) -> u32 {
188 self.inner().max_concurrent_creating_streaming_jobs.unwrap()
189 }
190
191 fn pause_on_next_bootstrap(&self) -> bool {
192 self.inner()
193 .pause_on_next_bootstrap
194 .unwrap_or_else(default::pause_on_next_bootstrap)
195 }
196
197 fn enable_tracing(&self) -> bool {
198 self.inner()
199 .enable_tracing
200 .unwrap_or_else(default::enable_tracing)
201 }
202
203 fn license_key(&self) -> LicenseKeyRef<'_> {
204 self.inner()
205 .license_key
206 .as_deref()
207 .unwrap_or_default()
208 .into()
209 }
210
211 fn time_travel_retention_ms(&self) -> u64 {
212 self.inner()
213 .time_travel_retention_ms
214 .unwrap_or_else(default::time_travel_retention_ms)
215 }
216
217 fn adaptive_parallelism_strategy(&self) -> AdaptiveParallelismStrategy {
218 self.inner()
219 .adaptive_parallelism_strategy
220 .as_deref()
221 .and_then(|s| AdaptiveParallelismStrategy::from_str(s).ok())
222 .unwrap_or(AdaptiveParallelismStrategy::Auto)
223 }
224
225 fn per_database_isolation(&self) -> <bool as ParamValue>::Borrowed<'_> {
226 self.inner()
227 .per_database_isolation
228 .unwrap_or_else(default::per_database_isolation)
229 }
230}