rocksdb/properties.rs
1//! Properties
2//!
3//! Full list of valid properties and descriptions pulled from
4//! [here](https:///github.com/facebook/rocksdb/blob/08809f5e6cd9cc4bc3958dd4d59457ae78c76660/include/rocksdb/db.h#L428-L634).
5
6use std::ffi::{CStr, CString};
7
8macro_rules! property {
9 ($suffix: literal) => {
10 // SAFETY: We’re appending terminating NUL byte and this macro is always
11 // called with values without interior NUL bytes.
12 unsafe {
13 CStr::from_bytes_with_nul_unchecked(concat!("rocksdb.", $suffix, "\0").as_bytes())
14 }
15 };
16}
17
18/// "rocksdb.num-files-at-level<N>" - returns string containing the number
19/// of files at level <N>, where <N> is an ASCII representation of a
20/// level number (e.g., "0").
21pub fn num_files_at_level(level: usize) -> CString {
22 unsafe { level_property("num-files-at-level", level) }
23}
24
25/// "rocksdb.compression-ratio-at-level<N>" - returns string containing the
26/// compression ratio of data at level <N>, where <N> is an ASCII
27/// representation of a level number (e.g., "0"). Here, compression
28/// ratio is defined as uncompressed data size / compressed file size.
29/// Returns "-1.0" if no open files at level <N>.
30pub fn compression_ratio_at_level(level: usize) -> CString {
31 unsafe { level_property("compression-ratio-at-level", level) }
32}
33
34/// "rocksdb.stats" - returns a multi-line string containing the data
35/// described by kCFStats followed by the data described by kDBStats.
36pub const STATS: &CStr = property!("stats");
37
38/// "rocksdb.sstables" - returns a multi-line string summarizing current
39/// SST files.
40pub const SSTABLES: &CStr = property!("sstables");
41
42/// "rocksdb.cfstats" - Both of "rocksdb.cfstats-no-file-histogram" and
43/// "rocksdb.cf-file-histogram" together. See below for description
44/// of the two.
45pub const CFSTATS: &CStr = property!("CFSTATS");
46
47/// "rocksdb.cfstats-no-file-histogram" - returns a multi-line string with
48/// general columm family stats per-level over db's lifetime ("L<n>"),
49/// aggregated over db's lifetime ("Sum"), and aggregated over the
50/// interval since the last retrieval ("Int").
51/// It could also be used to return the stats in the format of the map.
52/// In this case there will a pair of string to array of double for
53/// each level as well as for "Sum". "Int" stats will not be affected
54/// when this form of stats are retrieved.
55pub const CFSTATS_NO_FILE_HISTOGRAM: &CStr = property!("cfstats-no-file-histogram");
56
57/// "rocksdb.cf-file-histogram" - print out how many file reads to every
58/// level, as well as the histogram of latency of single requests.
59pub const CF_FILE_HISTOGRAM: &CStr = property!("cf-file-histogram");
60
61/// "rocksdb.dbstats" - returns a multi-line string with general database
62/// stats, both cumulative (over the db's lifetime) and interval (since
63/// the last retrieval of kDBStats).
64pub const DBSTATS: &CStr = property!("dbstats");
65
66/// "rocksdb.levelstats" - returns multi-line string containing the number
67/// of files per level and total size of each level (MB).
68pub const LEVELSTATS: &CStr = property!("levelstats");
69
70/// "rocksdb.num-immutable-mem-table" - returns number of immutable
71/// memtables that have not yet been flushed.
72pub const NUM_IMMUTABLE_MEM_TABLE: &CStr = property!("num-immutable-mem-table");
73
74/// "rocksdb.num-immutable-mem-table-flushed" - returns number of immutable
75/// memtables that have already been flushed.
76pub const NUM_IMMUTABLE_MEM_TABLE_FLUSHED: &CStr = property!("num-immutable-mem-table-flushed");
77
78/// "rocksdb.mem-table-flush-pending" - returns 1 if a memtable flush is
79/// pending; otherwise, returns 0.
80pub const MEM_TABLE_FLUSH_PENDING: &CStr = property!("mem-table-flush-pending");
81
82/// "rocksdb.num-running-flushes" - returns the number of currently running
83/// flushes.
84pub const NUM_RUNNING_FLUSHES: &CStr = property!("num-running-flushes");
85
86/// "rocksdb.compaction-pending" - returns 1 if at least one compaction is
87/// pending; otherwise, returns 0.
88pub const COMPACTION_PENDING: &CStr = property!("compaction-pending");
89
90/// "rocksdb.num-running-compactions" - returns the number of currently
91/// running compactions.
92pub const NUM_RUNNING_COMPACTIONS: &CStr = property!("num-running-compactions");
93
94/// "rocksdb.background-errors" - returns accumulated number of background
95/// errors.
96pub const BACKGROUND_ERRORS: &CStr = property!("background-errors");
97
98/// "rocksdb.cur-size-active-mem-table" - returns approximate size of active
99/// memtable (bytes).
100pub const CUR_SIZE_ACTIVE_MEM_TABLE: &CStr = property!("cur-size-active-mem-table");
101
102/// "rocksdb.cur-size-all-mem-tables" - returns approximate size of active
103/// and unflushed immutable memtables (bytes).
104pub const CUR_SIZE_ALL_MEM_TABLES: &CStr = property!("cur-size-all-mem-tables");
105
106/// "rocksdb.size-all-mem-tables" - returns approximate size of active,
107/// unflushed immutable, and pinned immutable memtables (bytes).
108pub const SIZE_ALL_MEM_TABLES: &CStr = property!("size-all-mem-tables");
109
110/// "rocksdb.num-entries-active-mem-table" - returns total number of entries
111/// in the active memtable.
112pub const NUM_ENTRIES_ACTIVE_MEM_TABLE: &CStr = property!("num-entries-active-mem-table");
113
114/// "rocksdb.num-entries-imm-mem-tables" - returns total number of entries
115/// in the unflushed immutable memtables.
116pub const NUM_ENTRIES_IMM_MEM_TABLES: &CStr = property!("num-entries-imm-mem-tables");
117
118/// "rocksdb.num-deletes-active-mem-table" - returns total number of delete
119/// entries in the active memtable.
120pub const NUM_DELETES_ACTIVE_MEM_TABLE: &CStr = property!("num-deletes-active-mem-table");
121
122/// "rocksdb.num-deletes-imm-mem-tables" - returns total number of delete
123/// entries in the unflushed immutable memtables.
124pub const NUM_DELETES_IMM_MEM_TABLES: &CStr = property!("num-deletes-imm-mem-tables");
125
126/// "rocksdb.estimate-num-keys" - returns estimated number of total keys in
127/// the active and unflushed immutable memtables and storage.
128pub const ESTIMATE_NUM_KEYS: &CStr = property!("estimate-num-keys");
129
130/// "rocksdb.estimate-table-readers-mem" - returns estimated memory used for
131/// reading SST tables, excluding memory used in block cache (e.g.,
132/// filter and index blocks).
133pub const ESTIMATE_TABLE_READERS_MEM: &CStr = property!("estimate-table-readers-mem");
134
135/// "rocksdb.is-file-deletions-enabled" - returns 0 if deletion of obsolete
136/// files is enabled; otherwise, returns a non-zero number.
137pub const IS_FILE_DELETIONS_ENABLED: &CStr = property!("is-file-deletions-enabled");
138
139/// "rocksdb.num-snapshots" - returns number of unreleased snapshots of the
140/// database.
141pub const NUM_SNAPSHOTS: &CStr = property!("num-snapshots");
142
143/// "rocksdb.oldest-snapshot-time" - returns number representing unix
144/// timestamp of oldest unreleased snapshot.
145pub const OLDEST_SNAPSHOT_TIME: &CStr = property!("oldest-snapshot-time");
146
147/// "rocksdb.num-live-versions" - returns number of live versions. `Version`
148/// is an internal data structure. See version_set.h for details. More
149/// live versions often mean more SST files are held from being deleted,
150/// by iterators or unfinished compactions.
151pub const NUM_LIVE_VERSIONS: &CStr = property!("num-live-versions");
152
153/// "rocksdb.current-super-version-number" - returns number of current LSM
154/// version. It is a uint64_t integer number, incremented after there is
155/// any change to the LSM tree. The number is not preserved after restarting
156/// the DB. After DB restart, it will start from 0 again.
157pub const CURRENT_SUPER_VERSION_NUMBER: &CStr = property!("current-super-version-number");
158
159/// "rocksdb.estimate-live-data-size" - returns an estimate of the amount of
160/// live data in bytes.
161pub const ESTIMATE_LIVE_DATA_SIZE: &CStr = property!("estimate-live-data-size");
162
163/// "rocksdb.min-log-number-to-keep" - return the minimum log number of the
164/// log files that should be kept.
165pub const MIN_LOG_NUMBER_TO_KEEP: &CStr = property!("min-log-number-to-keep");
166
167/// "rocksdb.min-obsolete-sst-number-to-keep" - return the minimum file
168/// number for an obsolete SST to be kept. The max value of `uint64_t`
169/// will be returned if all obsolete files can be deleted.
170pub const MIN_OBSOLETE_SST_NUMBER_TO_KEEP: &CStr = property!("min-obsolete-sst-number-to-keep");
171
172/// "rocksdb.total-sst-files-size" - returns total size (bytes) of all SST
173/// files.
174/// WARNING: may slow down online queries if there are too many files.
175pub const TOTAL_SST_FILES_SIZE: &CStr = property!("total-sst-files-size");
176
177/// "rocksdb.live-sst-files-size" - returns total size (bytes) of all SST
178/// files belong to the latest LSM tree.
179pub const LIVE_SST_FILES_SIZE: &CStr = property!("live-sst-files-size");
180
181/// "rocksdb.base-level" - returns number of level to which L0 data will be
182/// compacted.
183pub const BASE_LEVEL: &CStr = property!("base-level");
184
185/// "rocksdb.estimate-pending-compaction-bytes" - returns estimated total
186/// number of bytes compaction needs to rewrite to get all levels down
187/// to under target size. Not valid for other compactions than level-
188/// based.
189pub const ESTIMATE_PENDING_COMPACTION_BYTES: &CStr = property!("estimate-pending-compaction-bytes");
190
191/// "rocksdb.aggregated-table-properties" - returns a string representation
192/// of the aggregated table properties of the target column family.
193pub const AGGREGATED_TABLE_PROPERTIES: &CStr = property!("aggregated-table-properties");
194
195/// "rocksdb.aggregated-table-properties-at-level<N>", same as the previous
196/// one but only returns the aggregated table properties of the
197/// specified level "N" at the target column family.
198pub fn aggregated_table_properties_at_level(level: usize) -> CString {
199 unsafe { level_property("aggregated-table-properties-at-level", level) }
200}
201
202/// "rocksdb.actual-delayed-write-rate" - returns the current actual delayed
203/// write rate. 0 means no delay.
204pub const ACTUAL_DELAYED_WRITE_RATE: &CStr = property!("actual-delayed-write-rate");
205
206/// "rocksdb.is-write-stopped" - Return 1 if write has been stopped.
207pub const IS_WRITE_STOPPED: &CStr = property!("is-write-stopped");
208
209/// "rocksdb.estimate-oldest-key-time" - returns an estimation of
210/// oldest key timestamp in the DB. Currently only available for
211/// FIFO compaction with
212/// compaction_options_fifo.allow_compaction = false.
213pub const ESTIMATE_OLDEST_KEY_TIME: &CStr = property!("estimate-oldest-key-time");
214
215/// "rocksdb.block-cache-capacity" - returns block cache capacity.
216pub const BLOCK_CACHE_CAPACITY: &CStr = property!("block-cache-capacity");
217
218/// "rocksdb.block-cache-usage" - returns the memory size for the entries
219/// residing in block cache.
220pub const BLOCK_CACHE_USAGE: &CStr = property!("block-cache-usage");
221
222/// "rocksdb.block-cache-pinned-usage" - returns the memory size for the
223/// entries being pinned.
224pub const BLOCK_CACHE_PINNED_USAGE: &CStr = property!("block-cache-pinned-usage");
225
226/// "rocksdb.options-statistics" - returns multi-line string
227/// of options.statistics
228pub const OPTIONS_STATISTICS: &CStr = property!("options-statistics");
229
230/// Constructs a property name for an ‘at level’ property.
231///
232/// `name` is the infix of the property name (e.g. `"num-files-at-level"`) and
233/// `level` is level to get statistics of. The property name is constructed as
234/// `"rocksdb.<name><level>"`.
235///
236/// Expects `name` not to contain any interior NUL bytes.
237unsafe fn level_property(name: &str, level: usize) -> CString {
238 let bytes = format!("rocksdb.{name}{level}\0").into_bytes();
239 // SAFETY: We’re appending terminating NUL and all our call sites pass
240 // a string without interior NUL bytes.
241 CString::from_vec_with_nul_unchecked(bytes)
242}
243
244#[test]
245fn sanity_checks() {
246 let want = CString::new("rocksdb.cfstats-no-file-histogram".to_string()).unwrap();
247 assert_eq!(want.as_c_str(), CFSTATS_NO_FILE_HISTOGRAM);
248
249 let want = CString::new("rocksdb.num-files-at-level5".to_string()).unwrap();
250 assert_eq!(want, num_files_at_level(5));
251}