metric_engine/
config.rs

1// Copyright 2023 Greptime Team
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
15use std::time::Duration;
16
17use common_telemetry::warn;
18use serde::{Deserialize, Serialize};
19
20/// The default flush interval of the metadata region.  
21pub(crate) const DEFAULT_FLUSH_METADATA_REGION_INTERVAL: Duration = Duration::from_secs(30);
22
23/// Configuration for the metric engine.
24#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
25pub struct EngineConfig {
26    /// Experimental feature to use sparse primary key encoding.
27    pub experimental_sparse_primary_key_encoding: bool,
28    /// The flush interval of the metadata region.
29    #[serde(
30        with = "humantime_serde",
31        default = "EngineConfig::default_flush_metadata_region_interval"
32    )]
33    pub flush_metadata_region_interval: Duration,
34}
35
36impl Default for EngineConfig {
37    fn default() -> Self {
38        Self {
39            flush_metadata_region_interval: DEFAULT_FLUSH_METADATA_REGION_INTERVAL,
40            experimental_sparse_primary_key_encoding: false,
41        }
42    }
43}
44
45impl EngineConfig {
46    fn default_flush_metadata_region_interval() -> Duration {
47        DEFAULT_FLUSH_METADATA_REGION_INTERVAL
48    }
49
50    /// Sanitizes the configuration.
51    pub fn sanitize(&mut self) {
52        if self.flush_metadata_region_interval.is_zero() {
53            warn!(
54                "Flush metadata region interval is zero, override with default value: {:?}. Disable metadata region flush is forbidden.",
55                DEFAULT_FLUSH_METADATA_REGION_INTERVAL
56            );
57            self.flush_metadata_region_interval = DEFAULT_FLUSH_METADATA_REGION_INTERVAL;
58        }
59    }
60}