Commit b8332a75 authored by Dylan Wen's avatar Dylan Wen Committed by GitHub

Add get options cf method for DB (#25)

parent 3b8597dc
...@@ -1053,6 +1053,20 @@ void crocksdb_enable_file_deletions( ...@@ -1053,6 +1053,20 @@ void crocksdb_enable_file_deletions(
SaveError(errptr, db->rep->EnableFileDeletions(force)); SaveError(errptr, db->rep->EnableFileDeletions(force));
} }
crocksdb_options_t* crocksdb_get_options(const crocksdb_t* db) {
crocksdb_options_t* options = new crocksdb_options_t;
options->rep = db->rep->GetOptions();
return options;
}
crocksdb_options_t* crocksdb_get_options_cf(
const crocksdb_t* db,
crocksdb_column_family_handle_t* column_family) {
crocksdb_options_t* options = new crocksdb_options_t;
options->rep = db->rep->GetOptions(column_family->rep);
return options;
}
void crocksdb_destroy_db( void crocksdb_destroy_db(
const crocksdb_options_t* options, const crocksdb_options_t* options,
const char* name, const char* name,
......
...@@ -362,6 +362,12 @@ extern C_ROCKSDB_LIBRARY_API void crocksdb_disable_file_deletions(crocksdb_t* db ...@@ -362,6 +362,12 @@ extern C_ROCKSDB_LIBRARY_API void crocksdb_disable_file_deletions(crocksdb_t* db
extern C_ROCKSDB_LIBRARY_API void crocksdb_enable_file_deletions( extern C_ROCKSDB_LIBRARY_API void crocksdb_enable_file_deletions(
crocksdb_t* db, unsigned char force, char** errptr); crocksdb_t* db, unsigned char force, char** errptr);
extern C_ROCKSDB_LIBRARY_API crocksdb_options_t* crocksdb_get_options(
const crocksdb_t* db);
extern C_ROCKSDB_LIBRARY_API crocksdb_options_t* crocksdb_get_options_cf(
const crocksdb_t* db, crocksdb_column_family_handle_t* column_family);
/* Management operations */ /* Management operations */
extern C_ROCKSDB_LIBRARY_API void crocksdb_destroy_db( extern C_ROCKSDB_LIBRARY_API void crocksdb_destroy_db(
......
...@@ -158,6 +158,8 @@ macro_rules! ffi_try { ...@@ -158,6 +158,8 @@ macro_rules! ffi_try {
// TODO audit the use of boolean arguments, b/c I think they need to be u8 // TODO audit the use of boolean arguments, b/c I think they need to be u8
// instead... // instead...
extern "C" { extern "C" {
pub fn crocksdb_get_options(db: *mut DBInstance) -> *mut DBOptions;
pub fn crocksdb_get_options_cf(db: *mut DBInstance, cf: *mut DBCFHandle) -> *mut DBOptions;
pub fn crocksdb_options_create() -> *mut DBOptions; pub fn crocksdb_options_create() -> *mut DBOptions;
pub fn crocksdb_options_destroy(opts: *mut DBOptions); pub fn crocksdb_options_destroy(opts: *mut DBOptions);
pub fn crocksdb_cache_create_lru(capacity: size_t) -> *mut DBCache; pub fn crocksdb_cache_create_lru(capacity: size_t) -> *mut DBCache;
......
...@@ -916,8 +916,18 @@ impl DB { ...@@ -916,8 +916,18 @@ impl DB {
self.opts.get_statistics_histogram(hist_type) self.opts.get_statistics_histogram(hist_type)
} }
pub fn get_options(&self) -> &Options { pub fn get_options(&self) -> Options {
&self.opts unsafe {
let inner = crocksdb_ffi::crocksdb_get_options(self.inner);
Options::new_with(inner)
}
}
pub fn get_options_cf(&self, cf: &CFHandle) -> Options {
unsafe {
let inner = crocksdb_ffi::crocksdb_get_options_cf(self.inner, cf.inner);
Options::new_with(inner)
}
} }
pub fn ingest_external_file(&self, pub fn ingest_external_file(&self,
......
...@@ -285,6 +285,15 @@ impl Options { ...@@ -285,6 +285,15 @@ impl Options {
Options::default() Options::default()
} }
pub fn new_with(inner: *mut DBOptions) -> Options {
assert!(!inner.is_null(),
"could not new rocksdb options with null inner");
Options {
inner: inner,
filter: None,
}
}
pub fn increase_parallelism(&mut self, parallelism: i32) { pub fn increase_parallelism(&mut self, parallelism: i32) {
unsafe { unsafe {
crocksdb_ffi::crocksdb_options_increase_parallelism(self.inner, parallelism); crocksdb_ffi::crocksdb_options_increase_parallelism(self.inner, parallelism);
......
...@@ -43,7 +43,8 @@ fn test_ingest_external_file() { ...@@ -43,7 +43,8 @@ fn test_ingest_external_file() {
let test_sstfile = gen_path.path().join("test_sst_file"); let test_sstfile = gen_path.path().join("test_sst_file");
let test_sstfile_str = test_sstfile.to_str().unwrap(); let test_sstfile_str = test_sstfile.to_str().unwrap();
gen_sst(db.get_options(), let default_options = db.get_options();
gen_sst(&default_options,
db.cf_handle("default").unwrap(), db.cf_handle("default").unwrap(),
test_sstfile_str, test_sstfile_str,
&[(b"k1", b"v1"), (b"k2", b"v2")]); &[(b"k1", b"v1"), (b"k2", b"v2")]);
...@@ -64,7 +65,7 @@ fn test_ingest_external_file() { ...@@ -64,7 +65,7 @@ fn test_ingest_external_file() {
let snap = db.snapshot(); let snap = db.snapshot();
gen_sst(db.get_options(), gen_sst(&default_options,
handle, handle,
test_sstfile_str, test_sstfile_str,
&[(b"k2", b"v5"), (b"k3", b"v6")]); &[(b"k2", b"v5"), (b"k3", b"v6")]);
......
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