|
|
|
@ -231,18 +231,43 @@ impl<T: ThreadMode> DBWithThreadMode<T> { |
|
|
|
|
path: P, |
|
|
|
|
ttl: Duration, |
|
|
|
|
) -> Result<Self, Error> { |
|
|
|
|
let c_path = to_cpath(&path)?; |
|
|
|
|
let db = Self::open_raw(opts, &c_path, &AccessType::WithTTL { ttl })?; |
|
|
|
|
if db.is_null() { |
|
|
|
|
return Err(Error::new("Could not initialize database.".to_owned())); |
|
|
|
|
Self::open_cf_descriptors_with_ttl(opts, path, std::iter::empty(), ttl) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Ok(Self { |
|
|
|
|
inner: db, |
|
|
|
|
cfs: T::new(BTreeMap::new()), |
|
|
|
|
path: path.as_ref().to_path_buf(), |
|
|
|
|
_outlive: vec![opts.outlive.clone()], |
|
|
|
|
}) |
|
|
|
|
/// Opens the database with a Time to Live compaction filter and column family names.
|
|
|
|
|
///
|
|
|
|
|
/// Column families opened using this function will be created with default `Options`.
|
|
|
|
|
pub fn open_cf_with_ttl<P, I, N>( |
|
|
|
|
opts: &Options, |
|
|
|
|
path: P, |
|
|
|
|
cfs: I, |
|
|
|
|
ttl: Duration, |
|
|
|
|
) -> Result<Self, Error> |
|
|
|
|
where |
|
|
|
|
P: AsRef<Path>, |
|
|
|
|
I: IntoIterator<Item = N>, |
|
|
|
|
N: AsRef<str>, |
|
|
|
|
{ |
|
|
|
|
let cfs = cfs |
|
|
|
|
.into_iter() |
|
|
|
|
.map(|name| ColumnFamilyDescriptor::new(name.as_ref(), Options::default())); |
|
|
|
|
|
|
|
|
|
Self::open_cf_descriptors_with_ttl(opts, path, cfs, ttl) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Opens a database with the given database with a Time to Live compaction filter and
|
|
|
|
|
/// column family descriptors.
|
|
|
|
|
pub fn open_cf_descriptors_with_ttl<P, I>( |
|
|
|
|
opts: &Options, |
|
|
|
|
path: P, |
|
|
|
|
cfs: I, |
|
|
|
|
ttl: Duration, |
|
|
|
|
) -> Result<Self, Error> |
|
|
|
|
where |
|
|
|
|
P: AsRef<Path>, |
|
|
|
|
I: IntoIterator<Item = ColumnFamilyDescriptor>, |
|
|
|
|
{ |
|
|
|
|
Self::open_cf_descriptors_internal(opts, path, cfs, &AccessType::WithTTL { ttl }) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Opens a database with the given database options and column family names.
|
|
|
|
@ -487,7 +512,17 @@ impl<T: ThreadMode> DBWithThreadMode<T> { |
|
|
|
|
cfhandles.as_mut_ptr(), |
|
|
|
|
)) |
|
|
|
|
} |
|
|
|
|
_ => return Err(Error::new("Unsupported access type".to_owned())), |
|
|
|
|
AccessType::WithTTL { ttl } => { |
|
|
|
|
ffi_try!(ffi::rocksdb_open_column_families_with_ttl( |
|
|
|
|
opts.inner, |
|
|
|
|
cpath.as_ptr(), |
|
|
|
|
cfs_v.len() as c_int, |
|
|
|
|
cfnames.as_ptr(), |
|
|
|
|
cfopts.as_ptr(), |
|
|
|
|
cfhandles.as_mut_ptr(), |
|
|
|
|
&(ttl.as_secs() as c_int) as *const _, |
|
|
|
|
)) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
Ok(db) |
|
|
|
|