common_config/
lib.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
15pub mod config;
16pub mod error;
17pub mod utils;
18
19use std::time::Duration;
20
21use common_base::readable_size::ReadableSize;
22pub use config::*;
23use serde::{Deserialize, Serialize};
24
25pub fn metadata_store_dir(store_dir: &str) -> String {
26    format!("{store_dir}/metadata")
27}
28
29/// The default data home directory.
30pub const DEFAULT_DATA_HOME: &str = "./greptimedb_data";
31
32#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
33#[serde(default)]
34pub struct KvBackendConfig {
35    /// The size of the metadata store backend log file.
36    pub file_size: ReadableSize,
37    /// The threshold of the metadata store size to trigger a purge.
38    pub purge_threshold: ReadableSize,
39    /// The interval of the metadata store to trigger a purge.
40    #[serde(with = "humantime_serde")]
41    pub purge_interval: Duration,
42}
43
44impl Default for KvBackendConfig {
45    fn default() -> Self {
46        Self {
47            // The log file size 64MB
48            file_size: ReadableSize::mb(64),
49            // The log purge threshold 256MB
50            purge_threshold: ReadableSize::mb(256),
51            // The log purge interval 1m
52            purge_interval: Duration::from_secs(60),
53        }
54    }
55}