From c1c067f1f47f6adcb23e1c437470e9f7a023cd7a Mon Sep 17 00:00:00 2001 From: Ceri Storey Date: Wed, 24 Feb 2016 11:06:39 +0000 Subject: [PATCH] Start adding WriteOptions. --- src/ffi.rs | 2 ++ src/rocksdb_options.rs | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/ffi.rs b/src/ffi.rs index 6318dde..8b0f86d 100644 --- a/src/ffi.rs +++ b/src/ffi.rs @@ -190,6 +190,8 @@ extern { -> DBInstance; pub fn rocksdb_writeoptions_create() -> DBWriteOptions; pub fn rocksdb_writeoptions_destroy(writeopts: DBWriteOptions); + pub fn rocksdb_writeoptions_set_sync(writeopts: DBWriteOptions, v: bool); + pub fn rocksdb_writeoptions_disable_WAL(writeopts: DBWriteOptions, v: c_int); pub fn rocksdb_put(db: DBInstance, writeopts: DBWriteOptions, k: *const u8, diff --git a/src/rocksdb_options.rs b/src/rocksdb_options.rs index e53bd27..7210061 100644 --- a/src/rocksdb_options.rs +++ b/src/rocksdb_options.rs @@ -31,6 +31,10 @@ pub struct Options { pub inner: rocksdb_ffi::DBOptions, } +pub struct WriteOptions { + pub inner: rocksdb_ffi::DBWriteOptions, +} + impl Drop for Options { fn drop(&mut self) { unsafe { @@ -47,6 +51,14 @@ impl Drop for BlockBasedOptions { } } +impl Drop for WriteOptions { + fn drop(&mut self) { + unsafe { + rocksdb_ffi::rocksdb_writeoptions_destroy(self.inner); + } + } +} + impl BlockBasedOptions { pub fn new() -> BlockBasedOptions { let block_opts = unsafe { @@ -311,3 +323,19 @@ impl Options { } } } + +impl WriteOptions { + pub fn new() -> WriteOptions { + let write_opts = unsafe { rocksdb_ffi::rocksdb_writeoptions_create() }; + let rocksdb_ffi::DBWriteOptions(opt_ptr) = write_opts; + if opt_ptr.is_null() { + panic!("Could not create rocksdb write options".to_string()); + } + WriteOptions { inner: write_opts } + } + pub fn set_sync(&mut self, sync: bool) { + unsafe { + rocksdb_ffi::rocksdb_writeoptions_set_sync(self.inner, sync); + } + } +}