Unverified Commit f7249f34 authored by yiwu-arbug's avatar yiwu-arbug Committed by GitHub

Cherry-pick Titan related fixes (#313)

Cherry-picking changes:
c503e736 2019-07-02 yiwu@pingcap.com     Fix Titan portable build (#312)
c17648a5 2019-07-01 yiwu@pingcap.com     Fix create_cf not passinig titan specific options to titan (#311)
parent 4d2381ec
...@@ -16,8 +16,8 @@ tempdir = "0.3" ...@@ -16,8 +16,8 @@ tempdir = "0.3"
default = [] default = []
# portable doesn't require static link, though it's meaningless # portable doesn't require static link, though it's meaningless
# when not using with static-link right now in this crate. # when not using with static-link right now in this crate.
portable = [] portable = ["libtitan_sys/portable"]
sse = [] sse = ["libtitan_sys/portable"]
[build-dependencies] [build-dependencies]
cc = "1.0.3" cc = "1.0.3"
......
...@@ -4958,6 +4958,9 @@ struct ctitandb_options_t { ...@@ -4958,6 +4958,9 @@ struct ctitandb_options_t {
TitanOptions rep; TitanOptions rep;
}; };
// TODO: Simplify the API by merging db_options into tdb_options, and
// column_family_options into titan_column_family_options, since the later
// of the pairs already contain the former.
crocksdb_t* ctitandb_open_column_families( crocksdb_t* ctitandb_open_column_families(
const char* name, const crocksdb_options_t* db_options, const char* name, const crocksdb_options_t* db_options,
const ctitandb_options_t* tdb_options, int num_column_families, const ctitandb_options_t* tdb_options, int num_column_families,
...@@ -4993,6 +4996,26 @@ crocksdb_t* ctitandb_open_column_families( ...@@ -4993,6 +4996,26 @@ crocksdb_t* ctitandb_open_column_families(
return result; return result;
} }
// Caller should make sure `db` is created from ctitandb_open_column_families.
//
// TODO: ctitandb_open_column_family should return a ctitandb_t. Caller can
// use ctitandb_t for titan specific functions.
crocksdb_column_family_handle_t* ctitandb_create_column_family(
crocksdb_t* db,
const ctitandb_options_t* titan_column_family_options,
const char* column_family_name,
char** errptr) {
// Blindly cast db into TitanDB.
TitanDB* titan_db = reinterpret_cast<TitanDB*>(db->rep);
crocksdb_column_family_handle_t* handle = new crocksdb_column_family_handle_t;
SaveError(errptr,
titan_db->CreateColumnFamily(
TitanCFDescriptor(std::string(column_family_name),
titan_column_family_options->rep),
&(handle->rep)));
return handle;
}
/* TitanDBOptions */ /* TitanDBOptions */
ctitandb_options_t* ctitandb_options_create() { return new ctitandb_options_t; } ctitandb_options_t* ctitandb_options_create() { return new ctitandb_options_t; }
......
...@@ -1976,6 +1976,13 @@ extern C_ROCKSDB_LIBRARY_API crocksdb_t* ctitandb_open_column_families( ...@@ -1976,6 +1976,13 @@ extern C_ROCKSDB_LIBRARY_API crocksdb_t* ctitandb_open_column_families(
const ctitandb_options_t** titan_column_family_options, const ctitandb_options_t** titan_column_family_options,
crocksdb_column_family_handle_t** column_family_handles, char** errptr); crocksdb_column_family_handle_t** column_family_handles, char** errptr);
extern C_ROCKSDB_LIBRARY_API
crocksdb_column_family_handle_t* ctitandb_create_column_family(
crocksdb_t* db,
const ctitandb_options_t* titan_column_family_options,
const char* column_family_name,
char** errptr);
/* TitanDBOptions */ /* TitanDBOptions */
extern C_ROCKSDB_LIBRARY_API ctitandb_options_t* ctitandb_options_create(); extern C_ROCKSDB_LIBRARY_API ctitandb_options_t* ctitandb_options_create();
......
...@@ -7,6 +7,13 @@ links = "titan" ...@@ -7,6 +7,13 @@ links = "titan"
[dependencies] [dependencies]
libc = "0.2.11" libc = "0.2.11"
[features]
default = []
# portable doesn't require static link, though it's meaningless
# when not using with static-link right now in this crate.
portable = []
sse = []
[build-dependencies] [build-dependencies]
cc = "1.0.3" cc = "1.0.3"
cmake = "0.1" cmake = "0.1"
......
...@@ -3,7 +3,14 @@ extern crate cmake; ...@@ -3,7 +3,14 @@ extern crate cmake;
fn main() { fn main() {
let cur_dir = std::env::current_dir().unwrap(); let cur_dir = std::env::current_dir().unwrap();
let dst = cmake::Config::new("titan") let mut cfg = cmake::Config::new("titan");
if cfg!(feature = "portable") {
cfg.define("PORTABLE", "ON");
}
if cfg!(feature = "sse") {
cfg.define("FORCE_SSE42", "ON");
}
let dst = cfg
.define("ROCKSDB_DIR", cur_dir.join("..").join("rocksdb")) .define("ROCKSDB_DIR", cur_dir.join("..").join("rocksdb"))
.define("WITH_TITAN_TESTS", "OFF") .define("WITH_TITAN_TESTS", "OFF")
.define("WITH_TITAN_TOOLS", "OFF") .define("WITH_TITAN_TOOLS", "OFF")
......
...@@ -1826,6 +1826,13 @@ extern "C" { ...@@ -1826,6 +1826,13 @@ extern "C" {
err: *mut *mut c_char, err: *mut *mut c_char,
) -> *mut DBInstance; ) -> *mut DBInstance;
pub fn ctitandb_create_column_family(
db: *mut DBInstance,
titan_column_family_options: *const DBTitanDBOptions,
column_family_name: *const c_char,
err: *mut *mut c_char,
) -> *mut DBCFHandle;
pub fn ctitandb_options_create() -> *mut DBTitanDBOptions; pub fn ctitandb_options_create() -> *mut DBTitanDBOptions;
pub fn ctitandb_options_destroy(opts: *mut DBTitanDBOptions); pub fn ctitandb_options_destroy(opts: *mut DBTitanDBOptions);
pub fn ctitandb_options_copy(opts: *mut DBTitanDBOptions) -> *mut DBTitanDBOptions; pub fn ctitandb_options_copy(opts: *mut DBTitanDBOptions) -> *mut DBTitanDBOptions;
......
...@@ -772,11 +772,19 @@ impl DB { ...@@ -772,11 +772,19 @@ impl DB {
}; };
let cname_ptr = cname.as_ptr(); let cname_ptr = cname.as_ptr();
unsafe { unsafe {
let cf_handler = ffi_try!(crocksdb_create_column_family( let cf_handler = if !self.is_titan() {
ffi_try!(crocksdb_create_column_family(
self.inner, self.inner,
cfd.options.inner, cfd.options.inner,
cname_ptr cname_ptr
)); ))
} else {
ffi_try!(ctitandb_create_column_family(
self.inner,
cfd.options.titan_inner,
cname_ptr
))
};
let handle = CFHandle { inner: cf_handler }; let handle = CFHandle { inner: cf_handler };
self._cf_opts.push(cfd.options); self._cf_opts.push(cfd.options);
Ok(match self.cfs.entry(cfd.name.to_owned()) { Ok(match self.cfs.entry(cfd.name.to_owned()) {
......
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