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
//! Advanced Options
use std::os::raw::c_int;
use rocks_sys as ll;
use crate::to_raw::ToRaw;
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum CompactionStyle {
/// level based compaction style
CompactionStyleLevel = 0x0,
/// Universal compaction style
/// Not supported in ROCKSDB_LITE.
CompactionStyleUniversal = 0x1,
/// FIFO compaction style
/// Not supported in ROCKSDB_LITE
CompactionStyleFIFO = 0x2,
/// Disable background compaction. Compaction jobs are submitted
/// via CompactFiles().
/// Not supported in ROCKSDB_LITE
CompactionStyleNone = 0x3,
}
/// In Level-based comapction, it Determines which file from a level to be
/// picked to merge to the next level. We suggest people try
/// kMinOverlappingRatio first when you tune your database.
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum CompactionPri {
/// Slightly Priotize larger files by size compensated by #deletes
ByCompensatedSize = 0x0,
/// First compact files whose data's latest update time is oldest.
/// Try this if you only update some hot keys in small ranges.
OldestLargestSeqFirst = 0x1,
/// First compact files whose range hasn't been compacted to the next level
/// for the longest. If your updates are random across the key space,
/// write amplification is slightly better with this option.
OldestSmallestSeqFirst = 0x2,
/// First compact files whose ratio between overlapping size in next level
/// and its size is the smallest. It in many cases can optimize write
/// amplification.
MinOverlappingRatio = 0x3,
}
#[repr(C)]
pub struct CompactionOptionsFIFO {
raw: *mut ll::rocks_fifo_compaction_options_t,
}
impl ToRaw<ll::rocks_fifo_compaction_options_t> for CompactionOptionsFIFO {
fn raw(&self) -> *mut ll::rocks_fifo_compaction_options_t {
self.raw
}
}
impl Default for CompactionOptionsFIFO {
fn default() -> Self {
CompactionOptionsFIFO { raw: unsafe { ll::rocks_fifo_compaction_options_create() } }
}
}
impl Drop for CompactionOptionsFIFO {
fn drop(&mut self) {
unsafe { ll::rocks_fifo_compaction_options_destroy(self.raw) }
}
}
impl CompactionOptionsFIFO {
/// once the total sum of table files reaches this, we will delete the oldest
/// table file
///
/// Default: 1GB
pub fn max_table_files_size(self, val: u64) -> Self {
unsafe {
ll::rocks_fifo_compaction_options_set_max_table_files_size(self.raw, val);
}
self
}
/// If true, try to do compaction to compact smaller files into larger ones.
/// Minimum files to compact follows options.level0_file_num_compaction_trigger
/// and compaction won't trigger if average compact bytes per del file is
/// larger than options.write_buffer_size. This is to protect large files
/// from being compacted again.
///
/// Default: false
pub fn allow_compaction(self, val: bool) -> Self {
unsafe {
ll::rocks_fifo_compaction_options_set_allow_compaction(self.raw, val as u8);
}
self
}
}
/// Compression options for different compression algorithms like Zlib
#[repr(C)]
pub struct CompressionOptions {
pub window_bits: c_int,
pub level: c_int,
pub strategy: c_int,
/// Maximum size of dictionary used to prime the compression library. Currently
/// this dictionary will be constructed by sampling the first output file in a
/// subcompaction when the target level is bottommost. This dictionary will be
/// loaded into the compression library before compressing/uncompressing each
/// data block of subsequent files in the subcompaction. Effectively, this
/// improves compression ratios when there are repetitions across data blocks.
/// A value of 0 indicates the feature is disabled.
/// Default: 0.
pub max_dict_bytes: u32,
}
impl CompressionOptions {
pub fn new(wbits: c_int, lev: c_int, strategy: c_int, max_dict_bytes: u32) -> CompressionOptions {
CompressionOptions {
window_bits: wbits,
level: lev,
strategy: strategy,
max_dict_bytes: max_dict_bytes,
}
}
}
impl Default for CompressionOptions {
fn default() -> Self {
CompressionOptions::new(-14, -1, 0, 0)
}
}
/// Return status For inplace update callback
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum UpdateStatus {
/// Nothing to update
Failed = 0,
/// Value updated inplace
Inplace = 1,
/// No inplace update. Merged value set
Updated = 2,
}
// FIXME: impled in ColumnFamilyOptions
// pub struct AdvancedColumnFamilyOptions {}