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