@ -14,11 +14,12 @@
use std ::ffi ::{ CStr , CString } ;
use std ::mem ;
use std ::path ::Path ;
use libc ::{ self , c_int , c_uchar , c_uint , c_void , size_t , uint64_t } ;
use ffi ;
use { BlockBasedOptions , BlockBasedIndexType , DBCompactionStyle , DBCompressionType , DBRecoveryMode ,
use { BlockBasedOptions , BlockBasedIndexType , DBCompactionStyle , DBCompressionType , DBRecoveryMode , MemtableFactory ,
Options , WriteOptions } ;
use compaction_filter ::{ self , CompactionFilterCallback , CompactionFilterFn , filter_callback } ;
use comparator ::{ self , ComparatorCallback , CompareFn } ;
@ -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 ) {
unsafe {
let bloom = if block_based {
@ -239,6 +246,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 ,
full_merge_fn : MergeFn ,
partial_merge_fn : Option < MergeFn > ) {
@ -901,6 +922,47 @@ impl Options {
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 ) {
unsafe {
ffi ::rocksdb_options_set_block_based_table_factory ( self . inner , factory . inner ) ;
@ -998,6 +1060,26 @@ impl Options {
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 {
@ -1042,6 +1124,7 @@ impl Default for WriteOptions {
#[ cfg(test) ]
mod tests {
use MemtableFactory ;
use Options ;
#[ test ]
@ -1054,4 +1137,16 @@ mod tests {
let opts = Options ::default ( ) ;
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 ,
} ) ;
}
}