tycho_core/storage/
config.rs1use std::time::Duration;
2
3use bytesize::ByteSize;
4use serde::{Deserialize, Serialize};
5use tycho_util::config::PartialConfig;
6use tycho_util::serde_helpers;
7
8#[derive(Debug, Clone, Serialize, Deserialize, PartialConfig)]
9#[serde(deny_unknown_fields, default)]
10pub struct CoreStorageConfig {
11 #[important]
15 pub cells_cache_size: ByteSize,
16
17 pub drop_interval: u32,
21
22 pub archives_gc: Option<ArchivesGcConfig>,
26
27 pub states_gc: Option<StatesGcConfig>,
31
32 pub blocks_gc: Option<BlocksGcConfig>,
36
37 pub blocks_cache: BlocksCacheConfig,
39
40 pub blob_db: BlobDbConfig,
42}
43
44impl CoreStorageConfig {
45 #[cfg(any(test, feature = "test"))]
46 pub fn new_potato() -> Self {
47 Self {
48 cells_cache_size: ByteSize::kb(1024),
49 blob_db: BlobDbConfig {
50 pre_create_cas_tree: false,
51 },
52 ..Default::default()
53 }
54 }
55}
56
57impl Default for CoreStorageConfig {
58 fn default() -> Self {
59 Self {
60 cells_cache_size: ByteSize::mb(256),
61 drop_interval: 3,
62 archives_gc: Some(ArchivesGcConfig::default()),
63 states_gc: Some(StatesGcConfig::default()),
64 blocks_gc: Some(BlocksGcConfig::default()),
65 blocks_cache: BlocksCacheConfig::default(),
66 blob_db: BlobDbConfig::default(),
67 }
68 }
69}
70
71#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
72#[serde(default, deny_unknown_fields)]
73pub struct ArchivesGcConfig {
74 #[serde(with = "serde_helpers::humantime")]
76 pub persistent_state_offset: Duration,
77}
78
79impl Default for ArchivesGcConfig {
80 fn default() -> Self {
81 Self {
82 persistent_state_offset: Duration::from_secs(300),
83 }
84 }
85}
86
87#[derive(Debug, Copy, Clone, Serialize, Deserialize)]
88#[serde(default, deny_unknown_fields)]
89pub struct StatesGcConfig {
90 pub random_offset: bool,
94 #[serde(with = "serde_helpers::humantime")]
96 pub interval: Duration,
97}
98
99impl Default for StatesGcConfig {
100 fn default() -> Self {
101 Self {
102 random_offset: true,
103 interval: Duration::from_secs(60),
104 }
105 }
106}
107
108#[derive(Debug, Copy, Clone, Serialize, Deserialize)]
109#[serde(default)]
110pub struct BlocksGcConfig {
111 #[serde(flatten)]
116 pub ty: BlocksGcType,
117
118 pub enable_for_sync: bool,
120
121 pub max_blocks_per_batch: Option<usize>,
123}
124
125impl Default for BlocksGcConfig {
126 fn default() -> Self {
127 Self {
128 ty: BlocksGcType::BeforeSafeDistance {
129 safe_distance: 1000,
130 min_interval: Duration::from_secs(60),
131 },
132 enable_for_sync: true,
133 max_blocks_per_batch: Some(100_000),
134 }
135 }
136}
137
138#[derive(Debug, Copy, Clone, Eq, PartialEq, Serialize, Deserialize)]
139#[serde(tag = "type")]
140pub enum BlocksGcType {
141 BeforeSafeDistance {
143 safe_distance: u32,
145 #[serde(with = "serde_helpers::humantime")]
149 min_interval: Duration,
150 },
151 BeforePreviousKeyBlock,
153 BeforePreviousPersistentState,
155}
156
157#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
158#[serde(default, deny_unknown_fields)]
159pub struct BlocksCacheConfig {
160 #[serde(with = "serde_helpers::humantime")]
164 pub ttl: Duration,
165
166 pub size: ByteSize,
170}
171
172impl Default for BlocksCacheConfig {
173 fn default() -> Self {
174 Self {
175 ttl: Duration::from_secs(300),
176 size: ByteSize::mb(500),
177 }
178 }
179}
180
181#[derive(Debug, Clone, Serialize, Deserialize)]
182#[serde(default, deny_unknown_fields)]
183pub struct BlobDbConfig {
184 pub pre_create_cas_tree: bool,
185}
186
187impl Default for BlobDbConfig {
188 fn default() -> Self {
189 Self {
190 pre_create_cas_tree: true,
191 }
192 }
193}