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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
use super::prelude::*;
#[derive(Default, Debug)]
pub struct Builder {
config: Config,
ioring: Option<Rio>,
}
const MAX_POSSIBLE_DATA_IN_BLOB: u64 = u32::MAX as u64;
impl Builder {
#[must_use]
pub fn new() -> Self {
Self::default()
}
pub fn build<K: Key>(self) -> Result<Storage<K>> {
let mut error_params = String::new();
if self.config.work_dir().is_none() {
error_params.push_str("> work_dir\n");
} else if self.config.max_data_in_blob().is_none() {
error_params.push_str("> max_data_in_blob\n");
} else if self.config.max_data_in_blob().unwrap() > MAX_POSSIBLE_DATA_IN_BLOB {
error_params.push_str(&format!(
"> max_data_in_blob must be less than {}",
MAX_POSSIBLE_DATA_IN_BLOB
));
} else if self.config.max_blob_size().is_none() {
error_params.push_str("> max_blob_size\n");
} else if self.config.blob_file_name_prefix().is_none() {
error_params.push_str("> blob_file_name_prefix\n");
}
if error_params.is_empty() {
Ok(Storage::new(self.config, self.ioring))
} else {
error!("{}", error_params);
Err(Error::uninitialized().into())
}
}
pub fn work_dir<S: Into<PathBuf>>(mut self, work_dir: S) -> Self {
let path: PathBuf = work_dir.into();
debug!("work dir set to: {}", path.display());
self.config.set_work_dir(path);
self
}
#[must_use]
pub fn max_blob_size(mut self, max_blob_size: u64) -> Self {
if max_blob_size > 0 {
self.config.set_max_blob_size(max_blob_size);
} else {
error!("zero size blobs is useless, not set");
}
self
}
#[must_use]
pub fn max_data_in_blob(mut self, max_data_in_blob: u64) -> Self {
if max_data_in_blob > 0 {
self.config.set_max_data_in_blob(max_data_in_blob);
} else {
error!("zero size blobs is useless, not set");
}
self
}
pub fn blob_file_name_prefix<U: Into<String>>(mut self, blob_file_name_prefix: U) -> Self {
let prefix = blob_file_name_prefix.into();
if prefix.is_empty() {
error!("passed empty file prefix, not set");
} else {
self.config.set_blob_file_name_prefix(prefix);
}
self
}
#[must_use]
pub fn allow_duplicates(mut self) -> Self {
self.config.set_allow_duplicates(true);
self
}
pub fn ignore_corrupted(mut self) -> Self {
self.config.set_ignore_corrupted(true);
self
}
#[must_use]
pub fn set_filter_config(mut self, config: BloomConfig) -> Self {
self.config.set_filter(config);
self
}
#[must_use]
pub fn enable_aio(mut self, ioring: Rio) -> Self {
self.ioring = Some(ioring);
self
}
#[must_use]
pub fn create_work_dir(mut self, create: bool) -> Self {
self.config.set_create_work_dir(create);
self
}
pub fn set_dump_sem(mut self, dump_sem: Arc<Semaphore>) -> Self {
self.config.set_dump_sem(dump_sem);
self
}
}