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
/// Configuration properties used to initialize a database instance.
#[derive(Clone)]
pub struct DharmaOpts {
/// Flag specifying whether to bootstrap database from existing store if data has already been persisted at that path.
pub bootstrap: bool,
/// Path at which data is persisted.
pub path: String,
/// Threshold for memtable size. If size exceeds this then memtable will be
/// flushed to disk.
pub memtable_size_in_bytes: usize,
/// block size in bytes
pub block_size_in_bytes: usize,
/// number of blocks in an SSTable
/// This field will be deprecated after we introduced variable sized SSTables
pub blocks_per_sstable: u64,
/// Sparse Index Sampling frequency. On out of all n values
/// is stored in this spares Index
pub sparse_index_sampling_rate: u32,
}
impl DharmaOpts {
/// Create configuration options with default values.
/// Default value for all configuration values are specified below.
///
/// # Defaults
///
/// | Property | Default Value |
/// | :------- | :------------ |
/// | path | /var/lib/dharma |
/// | bootstrap | true |
///
pub fn default() -> DharmaOpts {
DharmaOpts {
bootstrap: true,
path: String::from("/tmp"),
// maximum size of memtable in bytes after which its is flushed to disk
memtable_size_in_bytes: 65536,
// block size is 32KB
block_size_in_bytes: 32768,
// 32 blocks (each block 32k in size) result in 1MB of memory
// overall 32MB per SSTable
blocks_per_sstable: 32 * 32,
sparse_index_sampling_rate: 100,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_default_options() {
let options = DharmaOpts::default();
assert!(options.bootstrap);
assert_eq!(options.path, String::from("/tmp"));
assert_eq!(options.memtable_size_in_bytes, 65536);
assert_eq!(options.block_size_in_bytes, 32768);
assert_eq!(options.blocks_per_sstable, 32 * 32);
assert_eq!(options.sparse_index_sampling_rate, 100);
}
}