Add DB::open_cf_with_opts method (#689)

master
walter 2 years ago committed by GitHub
parent 6cd1c020b0
commit 4ac69cd978
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      src/db.rs
  2. 25
      tests/test_column_family.rs

@ -436,6 +436,22 @@ impl<T: ThreadMode> DBWithThreadMode<T> {
Self::open_cf_descriptors_internal(opts, path, cfs, &AccessType::ReadWrite)
}
/// Opens a database with the given database options and column family names.
///
/// Column families opened using given `Options`.
pub fn open_cf_with_opts<P, I, N>(opts: &Options, path: P, cfs: I) -> Result<Self, Error>
where
P: AsRef<Path>,
I: IntoIterator<Item = (N, Options)>,
N: AsRef<str>,
{
let cfs = cfs
.into_iter()
.map(|(name, opts)| ColumnFamilyDescriptor::new(name.as_ref(), opts));
Self::open_cf_descriptors(opts, path, cfs)
}
/// Opens a database for read only with the given database options and column family names.
pub fn open_cf_for_read_only<P, I, N>(
opts: &Options,

@ -156,6 +156,31 @@ fn test_create_missing_column_family() {
}
}
#[test]
fn test_open_column_family_with_opts() {
let n = DBPath::new("_rust_rocksdb_open_cf_with_opts");
{
let mut opts = Options::default();
opts.create_if_missing(true);
opts.create_missing_column_families(true);
// We can use different parameters for different column family.
let mut cf1_opts = Options::default();
cf1_opts.set_min_write_buffer_number(2);
cf1_opts.set_min_write_buffer_number_to_merge(4);
let mut cf2_opts = Options::default();
cf2_opts.set_min_write_buffer_number(5);
cf2_opts.set_min_write_buffer_number_to_merge(10);
let cfs = vec![("cf1", cf1_opts), ("cf2", cf2_opts)];
match DB::open_cf_with_opts(&opts, &n, cfs) {
Ok(_db) => println!("successfully opened column family with the specified options"),
Err(e) => panic!("failed to open cf with options: {}", e),
}
}
}
#[test]
#[ignore]
fn test_merge_operator() {

Loading…
Cancel
Save