From 9f55661ebac54bc9156e3a72ad4d0a05d5ba95ff Mon Sep 17 00:00:00 2001 From: Tyler Neely Date: Sun, 26 Jul 2015 20:03:21 -0700 Subject: [PATCH] checkpointing cf work --- src/rocksdb.rs | 71 ++++++++++++++++++++++++++++++++++++-- test/test_column_family.rs | 8 +++++ 2 files changed, 76 insertions(+), 3 deletions(-) diff --git a/src/rocksdb.rs b/src/rocksdb.rs index 6d12fe2..6e7e8f2 100644 --- a/src/rocksdb.rs +++ b/src/rocksdb.rs @@ -250,9 +250,7 @@ impl RocksDB { db = rocksdb_ffi::rocksdb_open_column_families(opts.inner, cpath_ptr, nfam as libc::c_int, names.as_ptr(), - copts, - handles, - err_ptr); + copts, handles, err_ptr); } for handle in cfhandles.iter() { @@ -377,6 +375,24 @@ impl RocksDB { Ok(()) } + pub fn drop_cf(&mut self, name: &str) -> Result<(), String> { + let cf = self.cfs.get(name); + if cf.is_none() { + return Err(format!("Invalid column family: {}", name).to_string()); + } + + let mut err: *const i8 = 0 as *const i8; + let err_ptr: *mut *const i8 = &mut err; + unsafe { + rocksdb_ffi::rocksdb_drop_column_family(self.inner, cf.unwrap(), err_ptr); + } + if !err.is_null() { + return Err(error_message(err)); + } + + Ok(()) + } + pub fn iterator(&self) -> DBIterator { let opts = ReadOptions::new(); DBIterator::new(&self, &opts) @@ -698,3 +714,52 @@ fn iterator_test() { let opts = Options::new(); assert!(RocksDB::destroy(&opts, path).is_ok()); } + +#[test] +pub fn test_column_family() { + let path = "_rust_rocksdb_cftest"; + + // should be able to create column families + { + let mut db = RocksDB::open_default(path).unwrap(); + let opts = Options::new(); + match db.create_cf("cf1", &opts) { + Ok(_) => println!("cf1 created successfully"), + Err(e) => { + panic!("could not create column family: {}", e); + }, + } + } + + // should fail to open db without specifying same column families + { + match RocksDB::open_default(path) { + Ok(_) => panic!("should not have opened DB successfully without specifying column + families"), + Err(e) => assert!(e.starts_with("Invalid argument: You have to open all column families.")), + } + } + + // should properly open db when specyfing all column families + { + match RocksDB::open_cf(&Options::new(), path, &["cf1"]) { + Ok(_) => println!("successfully opened db with column family"), + Err(e) => panic!("failed to open db with column family: {}", e), + } + + } + // should be able to write, read, merge, batch, and iterate over a cf + { + + } + // should b able to drop a cf + { + let mut db = RocksDB::open_cf(&Options::new(), path, &["cf1"]).unwrap(); + match db.drop_cf("cf1") { + Ok(_) => println!("cf1 successfully dropped."), + Err(e) => panic!("failed to drop column family: {}", e), + } + } + + assert!(RocksDB::destroy(&Options::new(), path).is_ok()); +} diff --git a/test/test_column_family.rs b/test/test_column_family.rs index 034d1a1..b79309d 100644 --- a/test/test_column_family.rs +++ b/test/test_column_family.rs @@ -52,6 +52,14 @@ pub fn test_column_family() { { } + // should b able to drop a cf + { + let mut db = RocksDB::open_cf(&Options::new(), path, &["cf1"]).unwrap(); + match db.drop_cf("cf1") { + Ok(_) => println!("cf1 successfully dropped."), + Err(e) => panic!("failed to drop column family: {}", e), + } + } assert!(RocksDB::destroy(&Options::new(), path).is_ok()); }