From f8e96a02df7ef1ab352f2b9add71391a32f9f6f3 Mon Sep 17 00:00:00 2001 From: Karl Hobley Date: Fri, 28 Oct 2016 11:59:35 +0100 Subject: [PATCH] Improve naming of some of the new Options methods None of these methods have been in a past released version so I don't think we should worry about backwards compatibility. Changes as follows: - Renamed ``compression`` to ``set_compression_type``. I think this is a much clearer name - Renamed ``add_merge_operator`` to ``set_merge_operator`` and ``add_comparator`` to ``set_comparator``. Both of these methods replace the entire value of their respective option so "add" is the wrong term to use here. - Renamed ``set_block_cache_size_mb`` to ``rocksdb_options_optimize_for_point_lookup``. To match RocksDB's API --- src/merge_operator.rs | 2 +- src/rocksdb_options.rs | 8 ++++---- test/test_column_family.rs | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/merge_operator.rs b/src/merge_operator.rs index 56a09b9..d243f60 100644 --- a/src/merge_operator.rs +++ b/src/merge_operator.rs @@ -185,7 +185,7 @@ fn mergetest() { let path = "_rust_rocksdb_mergetest"; let mut opts = Options::default(); opts.create_if_missing(true); - opts.add_merge_operator("test operator", test_provided_merge); + opts.set_merge_operator("test operator", test_provided_merge); { let db = DB::open(&opts, path).unwrap(); let p = db.put(b"k1", b"a"); diff --git a/src/rocksdb_options.rs b/src/rocksdb_options.rs index 1120a7b..1ad65a3 100644 --- a/src/rocksdb_options.rs +++ b/src/rocksdb_options.rs @@ -144,7 +144,7 @@ impl Options { /// levels after base level. /// /// Default: DBCompressionType::None - pub fn compression(&mut self, t: DBCompressionType) { + pub fn set_compression_type(&mut self, t: DBCompressionType) { unsafe { rocksdb_ffi::rocksdb_options_set_compression(self.inner, t); } @@ -165,7 +165,7 @@ impl Options { } } - pub fn add_merge_operator(&mut self, + pub fn set_merge_operator(&mut self, name: &str, merge_fn: MergeFn) { let cb = Box::new(MergeOperatorCallback { @@ -191,7 +191,7 @@ impl Options { /// The client must ensure that the comparator supplied here has the //// same name and orders keys *exactly* the same as the comparator /// provided to previous open calls on the same DB. - pub fn add_comparator(&mut self, + pub fn set_comparator(&mut self, name: &str, compare_fn: fn(&[u8], &[u8]) -> i32) { let cb = Box::new(ComparatorCallback { @@ -209,7 +209,7 @@ impl Options { } } - pub fn set_block_cache_size_mb(&mut self, cache_size: u64) { + pub fn optimize_for_point_lookup(&mut self, cache_size: u64) { unsafe { rocksdb_ffi::rocksdb_options_optimize_for_point_lookup(self.inner, cache_size); diff --git a/test/test_column_family.rs b/test/test_column_family.rs index c5f7aa1..1f06eea 100644 --- a/test/test_column_family.rs +++ b/test/test_column_family.rs @@ -22,7 +22,7 @@ pub fn test_column_family() { { let mut opts = Options::default(); opts.create_if_missing(true); - opts.add_merge_operator("test operator", test_provided_merge); + opts.set_merge_operator("test operator", test_provided_merge); let mut db = DB::open(&opts, path).unwrap(); let opts = Options::default(); match db.create_cf("cf1", &opts) { @@ -36,7 +36,7 @@ pub fn test_column_family() { // should fail to open db without specifying same column families { let mut opts = Options::default(); - opts.add_merge_operator("test operator", test_provided_merge); + opts.set_merge_operator("test operator", test_provided_merge); match DB::open(&opts, path) { Ok(_) => { panic!("should not have opened DB successfully without \ @@ -53,7 +53,7 @@ pub fn test_column_family() { // should properly open db when specyfing all column families { let mut opts = Options::default(); - opts.add_merge_operator("test operator", test_provided_merge); + opts.set_merge_operator("test operator", test_provided_merge); match DB::open_cf(&opts, path, &["cf1"]) { Ok(_) => println!("successfully opened db with column family"), Err(e) => panic!("failed to open db with column family: {}", e), @@ -84,7 +84,7 @@ fn test_merge_operator() { // TODO should be able to write, read, merge, batch, and iterate over a cf { let mut opts = Options::default(); - opts.add_merge_operator("test operator", test_provided_merge); + opts.set_merge_operator("test operator", test_provided_merge); let db = match DB::open_cf(&opts, path, &["cf1"]) { Ok(db) => { println!("successfully opened db with column family");