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
// Copyright (c) 2021 Google LLC
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
/*!
This module contains global configuration constants for RainDB.
These values usually correspond to configurable options for LevelDB (in its `options.h` file). To
get to an MVP and iterate, we keep static values here. These may be made configurable in future
versions.
*/
use TryFrom;
use crate;
/// The size of a `u32` in bytes.
pub const SIZE_OF_U32_BYTES: usize = 4;
/**
The number of keys between restart points when prefix compressing keys.
# Legacy
This is synonomous to LevelDB's `Options::block_restart_interval`.
*/
pub const PREFIX_COMPRESSION_RESTART_INTERVAL: usize = 16;
/// The maximum number of SSTable levels that is allowed.
pub const MAX_NUM_LEVELS: usize = 7;
/// Level-0 compaction is started when we hit this many files.
pub const L0_COMPACTION_TRIGGER: usize = 4;
/**
Soft limit on the number of level-0 files.
We slow down writes at this point.
*/
pub const L0_SLOWDOWN_WRITES_TRIGGER: usize = 8;
/**
Maximum number of level-0 files.
We stop writes at this point.
*/
pub const L0_STOP_WRITES_TRIGGER: usize = 12;
/**
The overall maximum group commit batch size.
This is set at 1 MiB.
This limit is so that doing a group commit gives better latency on average but does not affect the
latency of any single write too much.
*/
pub const MAX_GROUP_COMMIT_SIZE_BYTES: usize = 1 * 1024 * 1024;
/**
The upper threshold for a write to be considered a small write.
This is set at 128 KiB.
*/
pub const GROUP_COMMIT_SMALL_WRITE_THRESHOLD_BYTES: usize = 128 * 1024;
/**
The allowable additional bytes to add to a group commit where the first writer is doing a small
write.
This is set at 128 KiB.
If the initial writer of a group commit has a small write
(<= [`GROUP_COMMIT_SMALL_WRITE_THRESHOLD_BYTES`]), then limit the growth of the group commit so that
the small write is not impacted too much.
*/
pub const SMALL_WRITE_ADDITIONAL_GROUP_COMMIT_SIZE_BYTES: usize = 128 * 1024;
/**
Maximum level to which a newly compacted memtable is pushed if it does not create an overlap in
keys.
We try to push to level 2 to avoid the relatively expensive level 0 to level 1 compactions and to
avoid some expensive manifest file operations. We do not push all the way to the largest level since
that can generate a lot of wasted disk space if the same key space is being repeatedly overwritten.
*/
pub const MAX_MEM_COMPACT_LEVEL: usize = 2;
/**
The number of kibibytes that are allowed for a single seek of a table file.
Per LevelDB:
We arrange to automatically compact this file after a certain number of seeks. Let's assume:
(1) One seek costs 10ms
(2) Writing or reading 1MB costs 10ms (100MB/s)
(3) A compaction of 1MB does 25MB of IO:
1MB read from this level
10-12MB read from next level (boundaries may be misaligned)
10-12MB written to next level
This implies that 25 seeks cost the same as the compaction of 1MB of data. I.e., one seek costs
approximately the same as the compaction of 40KB of data. We are a little conservative and allow
approximately one seek for every 16KB of data before triggering a compaction.
TODO: Make allowed_seeks tunable (https://github.com/google/leveldb/issues/229)
*/
pub const SEEK_DATA_SIZE_THRESHOLD_KIB: u64 = 16 * 1024;
/**
The approximate period in bytes between sampling the data read during iteration.
Samples are used to update read statistics for a level and help to determine if a compaction should
be scheduled.
*/
pub const ITERATION_READ_BYTES_PERIOD: u64 = 1 * 1024 * 1024;
/**
The compression types available for blocks within a table file.
# LevelDB's analysis
Typical speeds of Snappy compression on an Intel(R) Core(TM)2 2.4GHz:
~200-500MB/s compression
~400-800MB/s decompression
Note that these speeds are significantly faster than most persistent storage speeds, and
therefore it is typically never worth switching to kNoCompression. Even if the input data is
incompressible, the Snappy compression implementation will efficiently detect that and will switch
to uncompressed mode.
*/
/**
The compression type to use for blocks within a table file.
The default is [`TableFileCompressionType::Snappy`].
*/
pub const TABLE_FILE_COMPRESSION_TYPE: TableFileCompressionType =
Snappy;