@ -14,12 +14,13 @@
use std ::ffi ::{ CStr , CString } ;
use std ::ffi ::{ CStr , CString } ;
use std ::mem ;
use std ::mem ;
use std ::path ::Path ;
use libc ::{ self , c_int , c_uchar , c_uint , c_void , size_t , uint64_t } ;
use libc ::{ self , c_int , c_uchar , c_uint , c_void , size_t , uint64_t } ;
use ffi ;
use ffi ;
use { BlockBasedOptions , DBCompactionStyle , DBCompressionType , DBRecoveryMode ,
use { BlockBasedOptions , DBCompactionStyle , DBCompressionType , DBRecoveryMode , MemtableFactory ,
Options , WriteOptions } ;
Options , WriteOptions } ;
use compaction_filter ::{ self , CompactionFilterCallback , CompactionFilterFn , filter_callback } ;
use compaction_filter ::{ self , CompactionFilterCallback , CompactionFilterFn , filter_callback } ;
use comparator ::{ self , ComparatorCallback , CompareFn } ;
use comparator ::{ self , ComparatorCallback , CompareFn } ;
use merge_operator ::{ self , MergeFn , MergeOperatorCallback , full_merge_callback ,
use merge_operator ::{ self , MergeFn , MergeOperatorCallback , full_merge_callback ,
@ -72,6 +73,12 @@ impl BlockBasedOptions {
}
}
}
}
pub fn disable_cache ( & mut self ) {
unsafe {
ffi ::rocksdb_block_based_options_set_no_block_cache ( self . inner , true as c_uchar ) ;
}
}
pub fn set_bloom_filter ( & mut self , bits_per_key : c_int , block_based : bool ) {
pub fn set_bloom_filter ( & mut self , bits_per_key : c_int , block_based : bool ) {
unsafe {
unsafe {
let bloom = if block_based {
let bloom = if block_based {
@ -221,6 +228,20 @@ impl Options {
}
}
}
}
/// If non-zero, we perform bigger reads when doing compaction. If you're
/// running RocksDB on spinning disks, you should set this to at least 2MB.
/// That way RocksDB's compaction is doing sequential instead of random reads.
///
/// When non-zero, we also force new_table_reader_for_compaction_inputs to
/// true.
///
/// Default: `0`
pub fn set_compaction_readahead_size ( & mut self , compaction_readahead_size : usize ) {
unsafe {
ffi ::rocksdb_options_compaction_readahead_size ( self . inner , compaction_readahead_size as usize ) ;
}
}
pub fn set_merge_operator ( & mut self , name : & str ,
pub fn set_merge_operator ( & mut self , name : & str ,
full_merge_fn : MergeFn ,
full_merge_fn : MergeFn ,
partial_merge_fn : Option < MergeFn > ) {
partial_merge_fn : Option < MergeFn > ) {
@ -883,6 +904,47 @@ impl Options {
unsafe { ffi ::rocksdb_options_set_disable_auto_compactions ( self . inner , disable as c_int ) }
unsafe { ffi ::rocksdb_options_set_disable_auto_compactions ( self . inner , disable as c_int ) }
}
}
/// Defines the underlying memtable implementation.
/// See https://github.com/facebook/rocksdb/wiki/MemTable for more information.
/// Defaults to using a skiplist.
///
/// # Example
///
/// ```
/// use rocksdb::{Options, MemtableFactory};
/// let mut opts = Options::default();
/// let factory = MemtableFactory::HashSkipList {
/// bucket_count: 1_000_000,
/// height: 4,
/// branching_factor: 4,
/// };
///
/// opts.set_allow_concurrent_memtable_write(false);
/// opts.set_memtable_factory(factory);
/// ```
pub fn set_memtable_factory ( & mut self , factory : MemtableFactory ) {
match factory {
MemtableFactory ::Vector = > unsafe {
ffi ::rocksdb_options_set_memtable_vector_rep ( self . inner ) ;
} ,
MemtableFactory ::HashSkipList {
bucket_count ,
height ,
branching_factor ,
} = > unsafe {
ffi ::rocksdb_options_set_hash_skip_list_rep (
self . inner ,
bucket_count ,
height ,
branching_factor ,
) ;
} ,
MemtableFactory ::HashLinkList { bucket_count } = > unsafe {
ffi ::rocksdb_options_set_hash_link_list_rep ( self . inner , bucket_count ) ;
} ,
} ;
}
pub fn set_block_based_table_factory ( & mut self , factory : & BlockBasedOptions ) {
pub fn set_block_based_table_factory ( & mut self , factory : & BlockBasedOptions ) {
unsafe {
unsafe {
ffi ::rocksdb_options_set_block_based_table_factory ( self . inner , factory . inner ) ;
ffi ::rocksdb_options_set_block_based_table_factory ( self . inner , factory . inner ) ;
@ -980,6 +1042,26 @@ impl Options {
ffi ::rocksdb_options_set_num_levels ( self . inner , n ) ;
ffi ::rocksdb_options_set_num_levels ( self . inner , n ) ;
}
}
}
}
/// Specifies the absolute path of the directory the
/// write-ahead log (WAL) should be written to.
///
/// Default: same directory as the database
///
/// # Example
///
/// ```
/// use rocksdb::Options;
///
/// let mut opts = Options::default();
/// opts.set_wal_dir("/path/to/dir");
/// ```
pub fn set_wal_dir < P : AsRef < Path > > ( & mut self , path : P ) {
let p = CString ::new ( path . as_ref ( ) . to_string_lossy ( ) . as_bytes ( ) ) . unwrap ( ) ;
unsafe {
ffi ::rocksdb_options_set_wal_dir ( self . inner , p . as_ptr ( ) ) ;
}
}
}
}
impl Default for Options {
impl Default for Options {
@ -1024,6 +1106,7 @@ impl Default for WriteOptions {
#[ cfg(test) ]
#[ cfg(test) ]
mod tests {
mod tests {
use MemtableFactory ;
use Options ;
use Options ;
#[ test ]
#[ test ]
@ -1036,4 +1119,16 @@ mod tests {
let opts = Options ::default ( ) ;
let opts = Options ::default ( ) ;
assert! ( opts . get_statistics ( ) . is_none ( ) ) ;
assert! ( opts . get_statistics ( ) . is_none ( ) ) ;
}
}
#[ test ]
fn test_set_memtable_factory ( ) {
let mut opts = Options ::default ( ) ;
opts . set_memtable_factory ( MemtableFactory ::Vector ) ;
opts . set_memtable_factory ( MemtableFactory ::HashLinkList { bucket_count : 100 } ) ;
opts . set_memtable_factory ( MemtableFactory ::HashSkipList {
bucket_count : 100 ,
height : 4 ,
branching_factor : 4 ,
} ) ;
}
}
}