|
|
|
@ -31,6 +31,7 @@ use std::path::PathBuf; |
|
|
|
|
use std::ptr; |
|
|
|
|
use std::slice; |
|
|
|
|
use std::str; |
|
|
|
|
use std::time::Duration; |
|
|
|
|
|
|
|
|
|
/// A RocksDB database.
|
|
|
|
|
///
|
|
|
|
@ -55,6 +56,7 @@ enum AccessType<'a> { |
|
|
|
|
ReadWrite, |
|
|
|
|
ReadOnly { error_if_log_file_exist: bool }, |
|
|
|
|
Secondary { secondary_path: &'a Path }, |
|
|
|
|
WithTTL { ttl: Duration }, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl DB { |
|
|
|
@ -88,6 +90,25 @@ impl DB { |
|
|
|
|
DB::open_cf_as_secondary(opts, primary_path, secondary_path, None::<&str>) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Opens the database with a Time to Live compaction filter.
|
|
|
|
|
pub fn open_with_ttl<P: AsRef<Path>>( |
|
|
|
|
opts: &Options, |
|
|
|
|
path: P, |
|
|
|
|
ttl: Duration, |
|
|
|
|
) -> Result<DB, Error> { |
|
|
|
|
let c_path = to_cpath(&path)?; |
|
|
|
|
let db = DB::open_raw(opts, &c_path, &AccessType::WithTTL { ttl })?; |
|
|
|
|
if db.is_null() { |
|
|
|
|
return Err(Error::new("Could not initialize database.".to_owned())); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Ok(DB { |
|
|
|
|
inner: db, |
|
|
|
|
cfs: BTreeMap::new(), |
|
|
|
|
path: path.as_ref().to_path_buf(), |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Opens a database with the given database options and column family names.
|
|
|
|
|
///
|
|
|
|
|
/// Column families opened using this function will be created with default `Options`.
|
|
|
|
@ -275,6 +296,11 @@ impl DB { |
|
|
|
|
to_cpath(secondary_path)?.as_ptr() as *const _, |
|
|
|
|
)) |
|
|
|
|
} |
|
|
|
|
AccessType::WithTTL { ttl } => ffi_try!(ffi::rocksdb_open_with_ttl( |
|
|
|
|
opts.inner, |
|
|
|
|
cpath.as_ptr() as *const _, |
|
|
|
|
ttl.as_secs() as c_int, |
|
|
|
|
)), |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
Ok(db) |
|
|
|
@ -321,6 +347,7 @@ impl DB { |
|
|
|
|
cfhandles.as_mut_ptr(), |
|
|
|
|
)) |
|
|
|
|
} |
|
|
|
|
_ => return Err(Error::new("Unsupported access type".to_owned())), |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
Ok(db) |
|
|
|
|