Commit 229732cb authored by Jay's avatar Jay Committed by GitHub

use cf descriptor to create cf (#146)

parent 9aa42565
...@@ -615,12 +615,12 @@ impl DB { ...@@ -615,12 +615,12 @@ impl DB {
self.get_cf_opt(cf, key, &ReadOptions::new()) self.get_cf_opt(cf, key, &ReadOptions::new())
} }
pub fn create_cf( pub fn create_cf<'a, T>(&mut self, cfd: T) -> Result<&CFHandle, String>
&mut self, where
name: &str, T: Into<ColumnFamilyDescriptor<'a>>,
cf_opts: ColumnFamilyOptions, {
) -> Result<&CFHandle, String> { let cfd = cfd.into();
let cname = match CString::new(name.as_bytes()) { let cname = match CString::new(cfd.name.as_bytes()) {
Ok(c) => c, Ok(c) => c,
Err(_) => { Err(_) => {
return Err( return Err(
...@@ -632,12 +632,12 @@ impl DB { ...@@ -632,12 +632,12 @@ impl DB {
unsafe { unsafe {
let cf_handler = ffi_try!(crocksdb_create_column_family( let cf_handler = ffi_try!(crocksdb_create_column_family(
self.inner, self.inner,
cf_opts.inner, cfd.options.inner,
cname_ptr cname_ptr
)); ));
let handle = CFHandle { inner: cf_handler }; let handle = CFHandle { inner: cf_handler };
self._cf_opts.push(cf_opts); self._cf_opts.push(cfd.options);
Ok(match self.cfs.entry(name.to_owned()) { Ok(match self.cfs.entry(cfd.name.to_owned()) {
Entry::Occupied(mut e) => { Entry::Occupied(mut e) => {
e.insert(handle); e.insert(handle);
e.into_mut() e.into_mut()
...@@ -1972,7 +1972,7 @@ mod test { ...@@ -1972,7 +1972,7 @@ mod test {
if *cf == "default" { if *cf == "default" {
continue; continue;
} }
db.create_cf(cf, cf_opts).unwrap(); db.create_cf((*cf, cf_opts)).unwrap();
} }
} }
let opts_list_cfs = DBOptions::new(); let opts_list_cfs = DBOptions::new();
...@@ -2156,8 +2156,7 @@ mod test { ...@@ -2156,8 +2156,7 @@ mod test {
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
let mut db = DB::open(opts, path.path().to_str().unwrap()).unwrap(); let mut db = DB::open(opts, path.path().to_str().unwrap()).unwrap();
let cf_opts = ColumnFamilyOptions::new(); db.create_cf("cf").unwrap();
db.create_cf("cf", cf_opts).unwrap();
let cf_handle = db.cf_handle("cf").unwrap(); let cf_handle = db.cf_handle("cf").unwrap();
for i in 0..200 { for i in 0..200 {
......
...@@ -28,8 +28,7 @@ pub fn test_column_family() { ...@@ -28,8 +28,7 @@ pub fn test_column_family() {
let mut cf_opts = ColumnFamilyOptions::new(); let mut cf_opts = ColumnFamilyOptions::new();
cf_opts.add_merge_operator("test operator", test_provided_merge); cf_opts.add_merge_operator("test operator", test_provided_merge);
let mut db = DB::open_cf(opts, path_str, vec![("default", cf_opts)]).unwrap(); let mut db = DB::open_cf(opts, path_str, vec![("default", cf_opts)]).unwrap();
let cf_opts = ColumnFamilyOptions::new(); match db.create_cf("cf1") {
match db.create_cf("cf1", cf_opts) {
Ok(_) => println!("cf1 created successfully"), Ok(_) => println!("cf1 created successfully"),
Err(e) => { Err(e) => {
panic!("could not create column family: {}", e); panic!("could not create column family: {}", e);
......
...@@ -1460,8 +1460,7 @@ fn test_delete_range_ingest_file() { ...@@ -1460,8 +1460,7 @@ fn test_delete_range_ingest_file() {
], ],
); );
let cf_opts = ColumnFamilyOptions::new(); db.create_cf("cf1").unwrap();
db.create_cf("cf1", cf_opts).unwrap();
let handle = db.cf_handle("cf1").unwrap(); let handle = db.cf_handle("cf1").unwrap();
gen_sst(ColumnFamilyOptions::new(), None, test_sstfile_str); gen_sst(ColumnFamilyOptions::new(), None, test_sstfile_str);
......
...@@ -97,8 +97,7 @@ fn concat_merge(_: &[u8], existing_val: Option<&[u8]>, operands: &mut MergeOpera ...@@ -97,8 +97,7 @@ fn concat_merge(_: &[u8], existing_val: Option<&[u8]>, operands: &mut MergeOpera
fn test_ingest_external_file() { fn test_ingest_external_file() {
let path = TempDir::new("_rust_rocksdb_ingest_sst").expect(""); let path = TempDir::new("_rust_rocksdb_ingest_sst").expect("");
let mut db = create_default_database(&path); let mut db = create_default_database(&path);
let cf_opts = ColumnFamilyOptions::new(); db.create_cf("cf1").unwrap();
db.create_cf("cf1", cf_opts).unwrap();
let handle = db.cf_handle("cf1").unwrap(); let handle = db.cf_handle("cf1").unwrap();
let gen_path = TempDir::new("_rust_rocksdb_ingest_sst_gen").expect(""); let gen_path = TempDir::new("_rust_rocksdb_ingest_sst_gen").expect("");
let test_sstfile = gen_path.path().join("test_sst_file"); let test_sstfile = gen_path.path().join("test_sst_file");
...@@ -217,7 +216,7 @@ fn test_ingest_external_file_new_cf() { ...@@ -217,7 +216,7 @@ fn test_ingest_external_file_new_cf() {
let test_sstfile_str = test_sstfile.to_str().unwrap(); let test_sstfile_str = test_sstfile.to_str().unwrap();
let mut cf_opts = ColumnFamilyOptions::new(); let mut cf_opts = ColumnFamilyOptions::new();
cf_opts.add_merge_operator("merge operator", concat_merge); cf_opts.add_merge_operator("merge operator", concat_merge);
db.create_cf("cf1", cf_opts).unwrap(); db.create_cf(("cf1", cf_opts)).unwrap();
let handle = db.cf_handle("cf1").unwrap(); let handle = db.cf_handle("cf1").unwrap();
let mut ingest_opt = IngestExternalFileOptions::new(); let mut ingest_opt = IngestExternalFileOptions::new();
...@@ -295,8 +294,7 @@ fn create_default_database(path: &TempDir) -> DB { ...@@ -295,8 +294,7 @@ fn create_default_database(path: &TempDir) -> DB {
fn create_cfs(db: &mut DB, cfs: &[&str]) { fn create_cfs(db: &mut DB, cfs: &[&str]) {
for cf in cfs { for cf in cfs {
if *cf != "default" { if *cf != "default" {
let cf_opts = ColumnFamilyOptions::new(); db.create_cf(*cf).unwrap();
db.create_cf(cf, cf_opts).unwrap();
} }
} }
} }
...@@ -323,8 +321,7 @@ fn test_ingest_simulate_real_world() { ...@@ -323,8 +321,7 @@ fn test_ingest_simulate_real_world() {
let mut db2 = create_default_database(&path2); let mut db2 = create_default_database(&path2);
for cf in &ALL_CFS { for cf in &ALL_CFS {
if *cf != "default" { if *cf != "default" {
let cf_opts = ColumnFamilyOptions::new(); db2.create_cf(*cf).unwrap();
db2.create_cf(cf, cf_opts).unwrap();
} }
} }
for cf in &ALL_CFS { for cf in &ALL_CFS {
......
use rocksdb::{ColumnFamilyOptions, DBOptions, Writable, DB}; use rocksdb::{DBOptions, Writable, DB};
use tempdir::TempDir; use tempdir::TempDir;
macro_rules! check_kv { macro_rules! check_kv {
...@@ -53,9 +53,8 @@ fn test_open_cf_for_read_only() { ...@@ -53,9 +53,8 @@ fn test_open_cf_for_read_only() {
{ {
let mut rw = DB::open_default(path).unwrap(); let mut rw = DB::open_default(path).unwrap();
let cf_opts = ColumnFamilyOptions::new(); let _ = rw.create_cf("cf1").unwrap();
let _ = rw.create_cf("cf1", cf_opts.clone()).unwrap(); let _ = rw.create_cf("cf2").unwrap();
let _ = rw.create_cf("cf2", cf_opts.clone()).unwrap();
} }
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment