From 0db7837dd190003b4e8c467b01f3bb504215c180 Mon Sep 17 00:00:00 2001 From: Tyler Neely Date: Sun, 14 Dec 2014 21:31:04 -0500 Subject: [PATCH] add cache functions --- README.md | 6 +++--- src/ffi.rs | 6 ++++++ src/lib.rs | 1 + src/rocksdb.rs | 20 ++++++++++++++++++++ 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d0b871d..930b736 100644 --- a/README.md +++ b/README.md @@ -109,14 +109,14 @@ fn tuned_for_somebody_elses_disk() -> RocksDB { - [x] rocksdb compiled via cargo - [x] OSX support - [x] rustic merge operator + - [x] compaction filter, style + - [x] LRU cache + - [x] destroy/repair - [ ] batch - [ ] iterator - [ ] range - [ ] create/release snapshot - [ ] column family operations - - [ ] compaction filter, style - - [ ] LRU cache - - [ ] destroy/repair - [ ] comparator - [ ] slicetransform - [ ] windows support diff --git a/src/ffi.rs b/src/ffi.rs index 10e3d0e..5839bbf 100644 --- a/src/ffi.rs +++ b/src/ffi.rs @@ -24,6 +24,12 @@ pub fn new_bloom_filter(bits: c_int) -> RocksDBFilterPolicy { } } +pub fn new_cache(capacity: size_t) -> RocksDBCache { + unsafe { + rocksdb_cache_create_lru(capacity) + } +} + #[repr(C)] pub enum RocksDBCompressionType { RocksDBNoCompression = 0, diff --git a/src/lib.rs b/src/lib.rs index e20020d..36120e1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,6 +5,7 @@ pub use ffi as rocksdb_ffi; pub use ffi::{ new_bloom_filter, + new_cache, RocksDBUniversalCompactionStyle, RocksDBCompactionStyle, RocksDBCompressionType, diff --git a/src/rocksdb.rs b/src/rocksdb.rs index e9131d9..f3d87ee 100644 --- a/src/rocksdb.rs +++ b/src/rocksdb.rs @@ -101,6 +101,26 @@ impl RocksDBOptions { } } + pub fn set_cache(&self, cache: rocksdb_ffi::RocksDBCache) { + unsafe { + rocksdb_ffi::rocksdb_block_based_options_set_block_cache( + self.block_options, cache); + rocksdb_ffi::rocksdb_options_set_block_based_table_factory( + self.inner, + self.block_options); + } + } + + pub fn set_cache_compressed(&self, cache: rocksdb_ffi::RocksDBCache) { + unsafe { + rocksdb_ffi::rocksdb_block_based_options_set_block_cache_compressed( + self.block_options, cache); + rocksdb_ffi::rocksdb_options_set_block_based_table_factory( + self.inner, + self.block_options); + } + } + pub fn set_max_open_files(&self, nfiles: c_int) { unsafe { rocksdb_ffi::rocksdb_options_set_max_open_files(self.inner, nfiles);