-
Notifications
You must be signed in to change notification settings - Fork 295
/
state_manager.rs
56 lines (49 loc) · 1.67 KB
/
state_manager.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
use crate::flag_status::FlagStatus;
use serde::{Deserialize, Serialize};
use std::path::PathBuf;
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct LsmtConfig {
/// Whether LSMT is enabled or not.
pub lsmt_status: FlagStatus,
/// Number of pages per shard in sharded overlays; u64::MAX if unlimited.
pub shard_num_pages: u64,
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct Config {
pub state_root: PathBuf,
/// A feature flag that enables/disables the file backed memory allocator.
#[serde(default = "file_backed_memory_allocator_default")]
pub file_backed_memory_allocator: FlagStatus,
/// A config for LSMT storage.
#[serde(default = "lsmt_config_default")]
pub lsmt_config: LsmtConfig,
}
impl Config {
pub fn new(state_root: PathBuf) -> Self {
Self {
state_root,
file_backed_memory_allocator: file_backed_memory_allocator_default(),
lsmt_config: lsmt_config_default(),
}
}
pub fn state_root(&self) -> PathBuf {
self.state_root.clone()
}
// The page_deltas directory stores files backing the file
// allocator and is a child of the state directory.
pub fn page_deltas_dirname(&self) -> String {
"page_deltas".to_string()
}
}
fn file_backed_memory_allocator_default() -> FlagStatus {
FlagStatus::Enabled
}
pub fn lsmt_config_default() -> LsmtConfig {
LsmtConfig {
lsmt_status: FlagStatus::Enabled,
// 40GiB
// DO NOT CHANGE after LSMT is enabled, as it would crash the new replica trying to merge
// old data.
shard_num_pages: 10 * 1024 * 1024,
}
}