Commit 98ab8149 authored by follitude's avatar follitude Committed by siddontang

support db_paths (#105)

parent 06ad3fc1
...@@ -98,6 +98,7 @@ using rocksdb::TablePropertiesCollection; ...@@ -98,6 +98,7 @@ using rocksdb::TablePropertiesCollection;
using rocksdb::TablePropertiesCollector; using rocksdb::TablePropertiesCollector;
using rocksdb::TablePropertiesCollectorFactory; using rocksdb::TablePropertiesCollectorFactory;
using rocksdb::KeyVersion; using rocksdb::KeyVersion;
using rocksdb::DbPath;
using std::shared_ptr; using std::shared_ptr;
...@@ -1992,6 +1993,18 @@ void crocksdb_options_set_use_fsync( ...@@ -1992,6 +1993,18 @@ void crocksdb_options_set_use_fsync(
opt->rep.use_fsync = use_fsync; opt->rep.use_fsync = use_fsync;
} }
void crocksdb_options_set_db_paths(crocksdb_options_t *opt,
const char *const *dbpath_list,
const size_t *path_lens,
const uint64_t *target_size, int num_paths) {
std::vector<DbPath> db_paths;
for (int i = 0; i < num_paths; ++i) {
db_paths.emplace_back(
DbPath(std::string(dbpath_list[i], path_lens[i]), target_size[i]));
}
opt->rep.db_paths = db_paths;
}
void crocksdb_options_set_db_log_dir( void crocksdb_options_set_db_log_dir(
crocksdb_options_t* opt, const char* db_log_dir) { crocksdb_options_t* opt, const char* db_log_dir) {
opt->rep.db_log_dir = db_log_dir; opt->rep.db_log_dir = db_log_dir;
......
...@@ -822,6 +822,10 @@ extern C_ROCKSDB_LIBRARY_API void crocksdb_options_set_arena_block_size( ...@@ -822,6 +822,10 @@ extern C_ROCKSDB_LIBRARY_API void crocksdb_options_set_arena_block_size(
crocksdb_options_t*, size_t); crocksdb_options_t*, size_t);
extern C_ROCKSDB_LIBRARY_API void crocksdb_options_set_use_fsync( extern C_ROCKSDB_LIBRARY_API void crocksdb_options_set_use_fsync(
crocksdb_options_t*, int); crocksdb_options_t*, int);
extern C_ROCKSDB_LIBRARY_API void
crocksdb_options_set_db_paths(crocksdb_options_t *, const char *const *,
const size_t *, const uint64_t *, int);
extern C_ROCKSDB_LIBRARY_API void crocksdb_options_set_db_log_dir( extern C_ROCKSDB_LIBRARY_API void crocksdb_options_set_db_log_dir(
crocksdb_options_t*, const char*); crocksdb_options_t*, const char*);
extern C_ROCKSDB_LIBRARY_API void crocksdb_options_set_wal_dir(crocksdb_options_t*, extern C_ROCKSDB_LIBRARY_API void crocksdb_options_set_wal_dir(crocksdb_options_t*,
......
...@@ -385,6 +385,11 @@ extern "C" { ...@@ -385,6 +385,11 @@ extern "C" {
pub fn crocksdb_options_set_hard_pending_compaction_bytes_limit(options: *mut Options, pub fn crocksdb_options_set_hard_pending_compaction_bytes_limit(options: *mut Options,
v: u64); v: u64);
pub fn crocksdb_options_set_compaction_priority(options: *mut Options, v: CompactionPriority); pub fn crocksdb_options_set_compaction_priority(options: *mut Options, v: CompactionPriority);
pub fn crocksdb_options_set_db_paths(options: *mut Options,
db_paths: *const *const c_char,
path_lens: *const usize,
target_size: *const u64,
num_paths: c_int);
pub fn crocksdb_filterpolicy_create_bloom_full(bits_per_key: c_int) -> *mut DBFilterPolicy; pub fn crocksdb_filterpolicy_create_bloom_full(bits_per_key: c_int) -> *mut DBFilterPolicy;
pub fn crocksdb_filterpolicy_create_bloom(bits_per_key: c_int) -> *mut DBFilterPolicy; pub fn crocksdb_filterpolicy_create_bloom(bits_per_key: c_int) -> *mut DBFilterPolicy;
pub fn crocksdb_open(options: *mut Options, pub fn crocksdb_open(options: *mut Options,
......
...@@ -27,6 +27,7 @@ use merge_operator::MergeFn; ...@@ -27,6 +27,7 @@ use merge_operator::MergeFn;
use slice_transform::{SliceTransform, new_slice_transform}; use slice_transform::{SliceTransform, new_slice_transform};
use std::ffi::{CStr, CString}; use std::ffi::{CStr, CString};
use std::mem; use std::mem;
use std::path::Path;
use table_properties_collector_factory::{TablePropertiesCollectorFactory, use table_properties_collector_factory::{TablePropertiesCollectorFactory,
new_table_properties_collector_factory}; new_table_properties_collector_factory};
...@@ -614,6 +615,28 @@ impl DBOptions { ...@@ -614,6 +615,28 @@ impl DBOptions {
crocksdb_ffi::crocksdb_options_set_allow_concurrent_memtable_write(self.inner, v); crocksdb_ffi::crocksdb_options_set_allow_concurrent_memtable_write(self.inner, v);
} }
} }
/// the second parameter is a slice which contains tuples (path, target_size).
pub fn set_db_paths<T: AsRef<Path>>(&self, val: &[(T, u64)]) {
let num_paths = val.len();
let mut cpaths = Vec::with_capacity(num_paths);
let mut cpath_lens = Vec::with_capacity(num_paths);
let mut sizes = Vec::with_capacity(num_paths);
for dbpath in val {
let dbpath_str = dbpath.0.as_ref().to_str();
cpaths.push(dbpath_str.unwrap().as_ptr() as _);
cpath_lens.push(dbpath_str.unwrap().len());
sizes.push(dbpath.1);
}
unsafe {
crocksdb_ffi::crocksdb_options_set_db_paths(self.inner,
cpaths.as_ptr(),
cpath_lens.as_ptr(),
sizes.as_ptr(),
num_paths as c_int);
}
}
} }
pub struct ColumnFamilyOptions { pub struct ColumnFamilyOptions {
......
...@@ -452,3 +452,13 @@ fn test_clone_options() { ...@@ -452,3 +452,13 @@ fn test_clone_options() {
let cf_opts2 = cf_opts.clone(); let cf_opts2 = cf_opts.clone();
assert_eq!(cf_opts.get_compression(), cf_opts2.get_compression()); assert_eq!(cf_opts.get_compression(), cf_opts2.get_compression());
} }
#[test]
fn test_db_paths() {
let path = TempDir::new("_rust_rocksdb_db_paths").expect("");
let mut opts = DBOptions::new();
opts.create_if_missing(true);
let tmp_path = TempDir::new("_rust_rocksdb_test_db_path").expect("");
opts.set_db_paths(&[(tmp_path.path(), 1073741824 as u64)]);
DB::open(opts, path.path().to_str().unwrap()).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