Skip to main content

tycho_storage/
config.rs

1use std::path::{Path, PathBuf};
2
3use bytesize::ByteSize;
4use serde::{Deserialize, Serialize};
5use tycho_util::config::PartialConfig;
6
7#[derive(Debug, Clone, Serialize, Deserialize, PartialConfig)]
8#[serde(deny_unknown_fields, default)]
9pub struct StorageConfig {
10    /// Path to the root directory of the storage.
11    ///
12    /// Default: `./db`.
13    #[important]
14    pub root_dir: PathBuf,
15
16    /// Whether to enable `RocksDB` metrics.
17    ///
18    /// Default: `true`.
19    pub rocksdb_enable_metrics: bool,
20
21    /// `RocksDB` LRU cache capacity.
22    ///
23    /// Default: calculated based on the available memory.
24    #[important]
25    pub rocksdb_lru_capacity: ByteSize,
26}
27
28impl StorageConfig {
29    /// Creates a new storage config with very low cache sizes.
30    pub fn new_potato(path: &Path) -> Self {
31        Self {
32            root_dir: path.to_owned(),
33            rocksdb_enable_metrics: false,
34            rocksdb_lru_capacity: ByteSize::mib(1),
35        }
36    }
37}
38
39impl Default for StorageConfig {
40    fn default() -> Self {
41        Self {
42            root_dir: PathBuf::from("./db"),
43            rocksdb_enable_metrics: true,
44            rocksdb_lru_capacity: ByteSize::gib(2),
45        }
46    }
47}