From 2a7ab0f805883a08a54aa229ac15cd446d5fe10a Mon Sep 17 00:00:00 2001 From: Richard Dodd Date: Tue, 25 Jul 2017 12:36:31 +0100 Subject: [PATCH] Include change from 5.4.5 Change "use_direct_writes" to "use_direct_io_for_flush_and_compaction" --- librocksdb-sys/src/lib.rs | 3 +- src/db_options.rs | 64 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 65 insertions(+), 2 deletions(-) diff --git a/librocksdb-sys/src/lib.rs b/librocksdb-sys/src/lib.rs index 7cd922a..f2320ac 100644 --- a/librocksdb-sys/src/lib.rs +++ b/librocksdb-sys/src/lib.rs @@ -636,7 +636,8 @@ extern "C" { 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_use_direct_io_for_flush_and_compaction(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 515af19..11a0b1a 100644 --- a/src/db_options.rs +++ b/src/db_options.rs @@ -388,17 +388,79 @@ impl Options { /// # Example /// /// ``` + /// #[allow(deprecated)] /// use rocksdb::Options; /// /// let mut opts = Options::default(); /// opts.set_use_direct_writes(true); /// ``` + #[deprecated(note = "replaced by `Options::set_use_direct_io_for_flush_and_compaction`")] pub fn set_use_direct_writes(&mut self, enabled: bool) { unsafe { - ffi::rocksdb_options_set_use_direct_writes(self.inner, enabled as c_uchar); + ffi::rocksdb_options_set_use_direct_io_for_flush_and_compaction(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_io_for_flush_and_compaction(true); + /// ``` + pub fn set_use_direct_io_for_flush_and_compaction(&mut self, enabled: bool) { + unsafe { + ffi::rocksdb_options_set_use_direct_io_for_flush_and_compaction(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. + /// + /// The exact behavior of this parameter is platform dependent. + /// + /// On POSIX systems, after RocksDB reads data from disk it will + /// mark the pages as "unneeded". The operating system may - or may not + /// - evict these pages from memory, reducing pressure on the system + /// cache. If the disk block is requested again this can result in + /// additional disk I/O. + /// + /// On WINDOWS systems, files will be opened in "unbuffered I/O" mode + /// which means that data read from the disk will not be cached or + /// bufferized. The hardware buffer of the devices may however still + /// be used. Memory mapped files are not impacted by this parameter. + /// + /// Default: true + /// + /// # Example + /// + /// ``` + /// #[allow(deprecated)] + /// use rocksdb::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_io_for_flush_and_compaction methods")] + pub fn set_allow_os_buffer(&mut self, is_allow: bool) { + self.set_use_direct_reads(!is_allow); + self.set_use_direct_io_for_flush_and_compaction(!is_allow); + } + /// Sets the number of shards used for table cache. /// /// Default: `6`