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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
use crate::utils;
use serde::{Deserialize, Serialize};
use std::{
net::{IpAddr, Ipv4Addr, SocketAddr},
path::PathBuf,
};
#[derive(Copy, Clone, Debug, Deserialize, PartialEq, Eq, Serialize)]
#[serde(default, deny_unknown_fields)]
pub struct RocksdbConfig {
pub max_open_files: i32,
pub max_total_wal_size: u64,
}
impl Default for RocksdbConfig {
fn default() -> Self {
Self {
max_open_files: 10_000,
#[allow(clippy::integer_arithmetic)] max_total_wal_size: 1u64 << 30,
}
}
}
#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Serialize)]
#[serde(default, deny_unknown_fields)]
pub struct StorageConfig {
pub address: SocketAddr,
pub backup_service_address: SocketAddr,
pub dir: PathBuf,
pub grpc_max_receive_len: Option<i32>,
pub prune_window: Option<u64>,
#[serde(skip)]
data_dir: PathBuf,
pub timeout_ms: u64,
pub rocksdb_config: RocksdbConfig,
}
impl Default for StorageConfig {
fn default() -> StorageConfig {
StorageConfig {
address: SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), 6666),
backup_service_address: SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), 6186),
dir: PathBuf::from("db"),
grpc_max_receive_len: Some(100_000_000),
prune_window: Some(1_000_000),
data_dir: PathBuf::from("/opt/diem/data"),
timeout_ms: 30_000,
rocksdb_config: RocksdbConfig::default(),
}
}
}
impl StorageConfig {
pub fn dir(&self) -> PathBuf {
if self.dir.is_relative() {
self.data_dir.join(&self.dir)
} else {
self.dir.clone()
}
}
pub fn set_data_dir(&mut self, data_dir: PathBuf) {
self.data_dir = data_dir;
}
pub fn randomize_ports(&mut self) {
self.address.set_port(utils::get_available_port());
self.backup_service_address
.set_port(utils::get_available_port());
}
}