From cd7fe07a130fa9a181e2c5aa55864db23a37be51 Mon Sep 17 00:00:00 2001 From: Duarte Nunes Date: Thu, 29 Jul 2021 06:45:37 -0300 Subject: [PATCH] Add rocksdb WAL flush api (#541) --- src/db.rs | 9 +++++++++ src/db_options.rs | 20 ++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/db.rs b/src/db.rs index 789129f..f923a16 100644 --- a/src/db.rs +++ b/src/db.rs @@ -589,6 +589,15 @@ impl DBWithThreadMode { &self.path.as_path() } + /// Flushes the WAL buffer. If `sync` is set to `true`, also syncs + /// the data to disk. + pub fn flush_wal(&self, sync: bool) -> Result<(), Error> { + unsafe { + ffi_try!(ffi::rocksdb_flush_wal(self.inner, sync as u8)); + } + Ok(()) + } + /// Flushes database memtables to SST files on the disk. pub fn flush_opt(&self, flushopts: &FlushOptions) -> Result<(), Error> { unsafe { diff --git a/src/db_options.rs b/src/db_options.rs index 899817f..c51d40e 100644 --- a/src/db_options.rs +++ b/src/db_options.rs @@ -2650,6 +2650,26 @@ impl Options { } } + /// If enabled, WAL is not flushed automatically after each write. Instead it + /// relies on manual invocation of `DB::flush_wal()` to write the WAL buffer + /// to its file. + /// + /// Default: false + /// + /// # Examples + /// + /// ``` + /// use rocksdb::Options; + /// + /// let mut options = Options::default(); + /// options.set_manual_wal_flush(true); + /// ``` + pub fn set_manual_wal_flush(&mut self, is_enabled: bool) { + unsafe { + ffi::rocksdb_options_set_manual_wal_flush(self.inner, is_enabled as c_uchar); + } + } + /// Guarantee that all column families are flushed together atomically. /// This option applies to both manual flushes (`db.flush()`) and automatic /// background flushes caused when memtables are filled.