Use an options struct

master
Martin Ek 6 years ago
parent d82d5c6b77
commit b01acb71a9
  1. 35
      src/db_options.rs
  2. 15
      src/lib.rs

@ -27,7 +27,7 @@ use merge_operator::{
use slice_transform::SliceTransform; use slice_transform::SliceTransform;
use { use {
BlockBasedIndexType, BlockBasedOptions, DBCompactionStyle, DBCompressionType, DBRecoveryMode, BlockBasedIndexType, BlockBasedOptions, DBCompactionStyle, DBCompressionType, DBRecoveryMode,
MemtableFactory, Options, WriteOptions, MemtableFactory, Options, PlainTableFactoryOptions, WriteOptions,
}; };
pub fn new_cache(capacity: size_t) -> *mut ffi::rocksdb_cache_t { pub fn new_cache(capacity: size_t) -> *mut ffi::rocksdb_cache_t {
@ -982,22 +982,29 @@ impl Options {
} }
} }
// See https://github.com/facebook/rocksdb/wiki/PlainTable-Format. /// See https://github.com/facebook/rocksdb/wiki/PlainTable-Format.
// ///
// Defaults: /// ```
// user_key_len: 0 (variable length) /// use rocksdb::{Options, PlainTableFactoryOptions};
// bloom_bits_per_key: 10 ///
// has_table_ratio: 0.75 /// let mut opts = Options::default();
// index_sparseness: 16 /// let factory_opts = PlainTableFactoryOptions {
pub fn set_plain_table_factory(&mut self, user_key_len: u32, bloom_bits_per_key: i32, /// user_key_length: 0,
hash_table_ratio: f64, index_sparseness: usize) { /// bloom_bits_per_key: 20,
/// hash_table_ratio: 0.75,
/// index_sparseness: 16,
/// };
///
/// opts.set_plain_table_factory(factory_opts);
/// ```
pub fn set_plain_table_factory(&mut self, options: PlainTableFactoryOptions) {
unsafe { unsafe {
ffi::rocksdb_options_set_plain_table_factory( ffi::rocksdb_options_set_plain_table_factory(
self.inner, self.inner,
user_key_len, options.user_key_length,
bloom_bits_per_key, options.bloom_bits_per_key,
hash_table_ratio, options.hash_table_ratio,
index_sparseness, options.index_sparseness,
); );
} }
} }

@ -167,6 +167,21 @@ pub enum MemtableFactory {
}, },
} }
/// Used with DBOptions::set_plain_table_factory.
/// See https://github.com/facebook/rocksdb/wiki/PlainTable-Format.
///
/// Defaults:
/// user_key_length: 0 (variable length)
/// bloom_bits_per_key: 10
/// hash_table_ratio: 0.75
/// index_sparseness: 16
pub struct PlainTableFactoryOptions {
pub user_key_length: u32,
pub bloom_bits_per_key: i32,
pub hash_table_ratio: f64,
pub index_sparseness: usize,
}
/// Database-wide options around performance and behavior. /// Database-wide options around performance and behavior.
/// ///
/// Please read [the official tuning guide](https://github.com/facebook/rocksdb/wiki/RocksDB-Tuning-Guide), and most importantly, measure performance under realistic workloads with realistic hardware. /// Please read [the official tuning guide](https://github.com/facebook/rocksdb/wiki/RocksDB-Tuning-Guide), and most importantly, measure performance under realistic workloads with realistic hardware.

Loading…
Cancel
Save