From aaf227060903f61bf669ec9b6bcf05ec554c10ad Mon Sep 17 00:00:00 2001 From: Martin Ek Date: Fri, 6 Apr 2018 19:43:09 +0200 Subject: [PATCH] Add index_type customization to BlockBasedOptions --- src/db_options.rs | 22 ++++++++++++++++++++-- src/lib.rs | 14 ++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/db_options.rs b/src/db_options.rs index 716b6f7..c7433ce 100644 --- a/src/db_options.rs +++ b/src/db_options.rs @@ -18,8 +18,8 @@ use std::mem; use libc::{self, c_int, c_uchar, c_uint, c_void, size_t, uint64_t}; use ffi; -use {BlockBasedOptions, DBCompactionStyle, DBCompressionType, DBRecoveryMode, - Options, WriteOptions}; +use {BlockBasedOptions, BlockBasedIndexType, DBCompactionStyle, DBCompressionType, DBRecoveryMode, + Options, WriteOptions}; use compaction_filter::{self, CompactionFilterCallback, CompactionFilterFn, filter_callback}; use comparator::{self, ComparatorCallback, CompareFn}; use merge_operator::{self, MergeFn, MergeOperatorCallback, full_merge_callback, @@ -89,6 +89,24 @@ impl BlockBasedOptions { ffi::rocksdb_block_based_options_set_cache_index_and_filter_blocks(self.inner, v as u8); } } + + /// Defines the index type to be used for SS-table lookups. + /// + /// # Example + /// + /// ``` + /// use rocksdb::{BlockBasedOptions, BlockBasedIndexType, Options}; + /// + /// let mut opts = Options::default(); + /// let mut block_opts = BlockBasedOptions::default(); + /// block_opts.set_index_type(BlockBasedIndexType::HashSearch); + /// ``` + pub fn set_index_type(&mut self, index_type: BlockBasedIndexType) { + let index = index_type as i32; + unsafe { + ffi::rocksdb_block_based_options_set_index_type(self.inner, index); + } + } } impl Default for BlockBasedOptions { diff --git a/src/lib.rs b/src/lib.rs index f982702..35a9ccc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -136,6 +136,20 @@ pub struct BlockBasedOptions { inner: *mut ffi::rocksdb_block_based_table_options_t, } +/// Used by BlockBasedOptions::set_index_type. +pub enum BlockBasedIndexType { + /// A space efficient index block that is optimized for + /// binary-search-based index. + BinarySearch, + + /// The hash index, if enabled, will perform a hash lookup if + /// a prefix extractor has been provided through Options::set_prefix_extractor. + HashSearch, + + /// A two-level index implementation. Both levels are binary search indexes. + TwoLevelIndexSearch, +} + /// 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.