From 6b407a3486c654ab507f9ca3616a9f24a6bd0242 Mon Sep 17 00:00:00 2001 From: Karl Hobley Date: Tue, 25 Jul 2017 10:10:31 +0100 Subject: [PATCH] Implement support for DirectIO As per: https://github.com/facebook/rocksdb/commit/972f96b3fbae1a4675043bdf4279c9072ad69645 --- librocksdb-sys/src/lib.rs | 3 ++- src/db_options.rs | 54 ++++++++++++++++++++++++++++++++++++--- 2 files changed, 53 insertions(+), 4 deletions(-) diff --git a/librocksdb-sys/src/lib.rs b/librocksdb-sys/src/lib.rs index fb1ce6c..6e86a38 100644 --- a/librocksdb-sys/src/lib.rs +++ b/librocksdb-sys/src/lib.rs @@ -633,7 +633,8 @@ extern "C" { pub fn rocksdb_options_set_purge_redundant_kvs_while_flush(opt: *mut rocksdb_options_t, v: c_uchar); - pub fn rocksdb_options_set_allow_os_buffer(opt: *mut rocksdb_options_t, v: c_uchar); + pub fn rocksdb_options_set_use_direct_reads(opt: *mut rocksdb_options_t, v: c_uchar); + pub fn rocksdb_options_set_use_direct_writes(opt: *mut rocksdb_options_t, v: c_uchar); pub fn rocksdb_options_set_allow_mmap_reads(opt: *mut rocksdb_options_t, v: c_uchar); diff --git a/src/db_options.rs b/src/db_options.rs index 5c5ede9..8952d97 100644 --- a/src/db_options.rs +++ b/src/db_options.rs @@ -351,6 +351,54 @@ impl Options { unsafe { ffi::rocksdb_options_set_disable_data_sync(self.inner, disable as c_int) } } + /// Enable direct I/O mode for reading + /// they may or may not improve performance depending on the use case + /// + /// Files will be opened in "direct I/O" mode + /// which means that data read from the disk will not be cached or + /// buffered. The hardware buffer of the devices may however still + /// be used. Memory mapped files are not impacted by these parameters. + /// + /// Default: false + /// + /// # Example + /// + /// ``` + /// use rocksdb::Options; + /// + /// let mut opts = Options::default(); + /// opts.set_use_direct_reads(true); + /// ``` + pub fn set_use_direct_reads(&mut self, enabled: bool) { + unsafe { + ffi::rocksdb_options_set_use_direct_reads(self.inner, enabled as c_uchar); + } + } + + /// Enable direct I/O mode for writing + /// they may or may not improve performance depending on the use case + /// + /// Files will be opened in "direct I/O" mode + /// which means that data written to the disk will not be cached or + /// buffered. The hardware buffer of the devices may however still + /// be used. Memory mapped files are not impacted by these parameters. + /// + /// Default: false + /// + /// # Example + /// + /// ``` + /// use rocksdb::Options; + /// + /// let mut opts = Options::default(); + /// opts.set_use_direct_writes(true); + /// ``` + pub fn set_use_direct_writes(&mut self, enabled: bool) { + unsafe { + ffi::rocksdb_options_set_use_direct_writes(self.inner, enabled as c_uchar); + } + } + /// Hints to the OS that it should not buffer disk I/O. Enabling this /// parameter may improve performance but increases pressure on the /// system cache. @@ -378,10 +426,10 @@ impl Options { /// let mut opts = Options::default(); /// opts.set_allow_os_buffer(false); /// ``` + #[deprecated(since="0.7.0", note="replaced with set_use_direct_reads/set_use_direct_writes methods")] pub fn set_allow_os_buffer(&mut self, is_allow: bool) { - unsafe { - ffi::rocksdb_options_set_allow_os_buffer(self.inner, is_allow as c_uchar); - } + self.set_use_direct_reads(!is_allow); + self.set_use_direct_writes(!is_allow); } /// Sets the number of shards used for table cache.