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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
use crate::{
cache::{BlockCache, IndexCache},
RefCounter,
};
use vpb::{ChecksumAlgorithm, Compression, Encryption};
use zallocator::pool::AllocatorPool;
/// Tells when should DB verify checksum for SSTable blocks.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
#[repr(u8)]
pub enum ChecksumVerificationMode {
/// Indicates DB should not verify checksum for SSTable blocks.
NoVerification = 0,
/// Indicates checksum should be verified while opening SSTtable.
OnTableRead = 1,
/// Indicates checksum should be verified on every SSTable block read.
OnBlockRead = 2,
/// Indicates checksum should be verified
/// on SSTable opening and on every block read.
OnTableAndBlockRead = 3,
}
/// Options contains configurable options for Table/Builder.
#[derive(Clone)]
pub struct Options {
// Options for Opening/Building Table.
/// open table in read only mode
ro: bool,
metrics_enabled: bool,
/// maximum size of the table
table_size: u64,
/// checksum_verification_mode is the checksum verification mode for Table.
checksum_verification_mode: ChecksumVerificationMode,
/// Indicates the checksum algorithm used for block compression.
checksum: ChecksumAlgorithm,
/// Indicates the compression algorithm used for block compression.
compression: Compression,
/// Indicates the encryption algorithm used for block encryption.
encryption: Encryption,
// Options for Table builder.
/// The false positive probabiltiy of bloom filter.
bloom_false_positive: f64,
/// the size of each block inside SSTable in bytes.
block_size: usize,
/// Block cache is used to cache decompressed and decrypted blocks.
block_cache: Option<BlockCache>,
index_cache: Option<IndexCache>,
alloc_pool: RefCounter<AllocatorPool>,
}
impl Options {
pub fn default_with_pool(pool: AllocatorPool) -> Self {
Self {
ro: false,
metrics_enabled: true,
table_size: 2 << 20,
checksum_verification_mode: ChecksumVerificationMode::NoVerification,
compression: Compression::new(),
bloom_false_positive: 0.01,
block_size: 4 * 1024,
alloc_pool: RefCounter::new(pool),
encryption: Encryption::new(),
checksum: ChecksumAlgorithm::Crc32c,
block_cache: None,
index_cache: None,
}
}
/// get whether read only or not
#[inline]
pub const fn read_only(&self) -> bool {
self.ro
}
/// set whether read only or not
#[inline]
pub const fn set_read_only(mut self, value: bool) -> Self {
self.ro = value;
self
}
/// get if the metrics enabled
#[inline]
pub const fn metrics_enabled(&self) -> bool {
self.metrics_enabled
}
/// set whether enable metrics or not
#[inline]
pub const fn set_metrics_enabled(mut self, value: bool) -> Self {
self.metrics_enabled = value;
self
}
/// get maximum size of the table
#[inline]
pub const fn table_size(&self) -> u64 {
self.table_size
}
/// set maximum size of the table
#[inline]
pub const fn set_table_size(mut self, val: u64) -> Self {
self.table_size = val;
self
}
/// get maximum capacity of the table, 0.95x of the maximum size of the table
#[cfg(feature = "nightly")]
#[inline]
pub const fn table_capacity(&self) -> u64 {
(self.table_size as f64 * 0.95) as u64
}
/// get maximum capacity of the table, 0.9x of the maximum size of the table
#[cfg(not(feature = "nightly"))]
#[inline]
pub fn table_capacity(&self) -> u64 {
(self.table_size as f64 * 0.95) as u64
}
/// get the compression algorithm used for block compression.
#[inline]
pub const fn compression(&self) -> Compression {
self.compression
}
/// set the compression algorithm used for block compression.
#[inline]
pub const fn set_compression(mut self, compression: Compression) -> Self {
self.compression = compression;
self
}
/// get the encryption algorithm used for block encryption.
#[inline]
pub const fn encryption(&self) -> &Encryption {
&self.encryption
}
/// set the encryption algorithm used for block encryption.
#[inline]
pub fn set_encryption(mut self, encryption: Encryption) -> Self {
self.encryption = encryption;
self
}
/// get the checksum algorithm for `Table`.
#[inline]
pub const fn checksum(&self) -> ChecksumAlgorithm {
self.checksum
}
/// set the checksum algorithm for `Table`.
#[inline]
pub const fn set_checksum(mut self, checksum: ChecksumAlgorithm) -> Self {
self.checksum = checksum;
self
}
/// get the checksum verification mode for `Table`.
#[inline]
pub const fn checksum_verification_mode(&self) -> ChecksumVerificationMode {
self.checksum_verification_mode
}
/// set the checksum verification mode for `Table`.
#[inline]
pub const fn set_checksum_verification_mode(mut self, val: ChecksumVerificationMode) -> Self {
self.checksum_verification_mode = val;
self
}
/// get the false positive probabiltiy of bloom filter.
#[inline]
pub const fn bloom_ratio(&self) -> f64 {
self.bloom_false_positive
}
/// set the false positive probabiltiy of bloom filter.
#[inline]
pub const fn set_bloom_ratio(mut self, val: f64) -> Self {
self.bloom_false_positive = val;
self
}
/// get the block size
#[inline]
pub const fn block_size(&self) -> usize {
self.block_size
}
/// set the block size
#[inline]
pub const fn set_block_size(mut self, val: usize) -> Self {
self.block_size = val;
self
}
/// get the allocator pool
#[inline]
pub fn allocator_pool(&self) -> &AllocatorPool {
&self.alloc_pool
}
/// set the allocator pool
#[inline]
pub fn set_allocator_pool(mut self, val: AllocatorPool) -> Self {
self.alloc_pool = RefCounter::new(val);
self
}
/// get the blocks cache
#[inline]
pub const fn block_cache(&self) -> Option<&BlockCache> {
self.block_cache.as_ref()
}
/// set the blocks cache
#[inline]
pub fn set_block_cache(mut self, cache: BlockCache) -> Self {
self.block_cache = Some(cache);
self
}
/// get the table index cache
#[inline]
pub const fn index_cache(&self) -> Option<&IndexCache> {
self.index_cache.as_ref()
}
/// set the index cache
#[inline]
pub fn set_index_cache(mut self, cache: IndexCache) -> Self {
self.index_cache = Some(cache);
self
}
}