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 archive_chunk_size: ByteSize,
21
22 pub split_block_tasks: usize,
26
27 pub archives_gc: Option<ArchivesGcConfig>,
31
32 pub states_gc: Option<StatesGcConfig>,
36
37 pub blocks_gc: Option<BlocksGcConfig>,
41
42 pub blocks_cache: BlocksCacheConfig,
44}
45
46impl CoreStorageConfig {
47 #[cfg(any(test, feature = "test"))]
48 pub fn new_potato() -> Self {
49 Self {
50 cells_cache_size: ByteSize::kb(1024),
51 ..Default::default()
52 }
53 }
54}
55
56impl Default for CoreStorageConfig {
57 fn default() -> Self {
58 Self {
59 cells_cache_size: ByteSize::mb(256),
60 split_block_tasks: 100,
61 archive_chunk_size: ByteSize::kb(1024),
62 archives_gc: Some(ArchivesGcConfig::default()),
63 states_gc: Some(StatesGcConfig::default()),
64 blocks_gc: Some(BlocksGcConfig::default()),
65 blocks_cache: BlocksCacheConfig::default(),
66 }
67 }
68}
69
70#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
71#[serde(default, deny_unknown_fields)]
72pub struct ArchivesGcConfig {
73 #[serde(with = "serde_helpers::humantime")]
75 pub persistent_state_offset: Duration,
76}
77
78impl Default for ArchivesGcConfig {
79 fn default() -> Self {
80 Self {
81 persistent_state_offset: Duration::from_secs(300),
82 }
83 }
84}
85
86#[derive(Debug, Copy, Clone, Serialize, Deserialize)]
87#[serde(default, deny_unknown_fields)]
88pub struct StatesGcConfig {
89 pub random_offset: bool,
93 #[serde(with = "serde_helpers::humantime")]
95 pub interval: Duration,
96}
97
98impl Default for StatesGcConfig {
99 fn default() -> Self {
100 Self {
101 random_offset: true,
102 interval: Duration::from_secs(60),
103 }
104 }
105}
106
107#[derive(Debug, Copy, Clone, Serialize, Deserialize)]
108#[serde(default)]
109pub struct BlocksGcConfig {
110 #[serde(flatten)]
115 pub ty: BlocksGcType,
116
117 pub enable_for_sync: bool,
119
120 pub max_blocks_per_batch: Option<usize>,
122}
123
124impl Default for BlocksGcConfig {
125 fn default() -> Self {
126 Self {
127 ty: BlocksGcType::BeforeSafeDistance {
128 safe_distance: 1000,
129 min_interval: Duration::from_secs(60),
130 },
131 enable_for_sync: true,
132 max_blocks_per_batch: Some(100_000),
133 }
134 }
135}
136
137#[derive(Debug, Copy, Clone, Eq, PartialEq, Serialize, Deserialize)]
138#[serde(tag = "type")]
139pub enum BlocksGcType {
140 BeforeSafeDistance {
142 safe_distance: u32,
144 #[serde(with = "serde_helpers::humantime")]
148 min_interval: Duration,
149 },
150 BeforePreviousKeyBlock,
152 BeforePreviousPersistentState,
154}
155
156#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
157#[serde(default, deny_unknown_fields)]
158pub struct BlocksCacheConfig {
159 #[serde(with = "serde_helpers::humantime")]
163 pub ttl: Duration,
164
165 pub size: ByteSize,
169}
170
171impl Default for BlocksCacheConfig {
172 fn default() -> Self {
173 Self {
174 ttl: Duration::from_secs(300),
175 size: ByteSize::mb(500),
176 }
177 }
178}