Unverified Commit 8d06b36b authored by Connor's avatar Connor Committed by GitHub

Fix titan open without cf (#404)

* fix titan open without cf
Signed-off-by: 's avatarConnor1996 <zbk602423539@gmail.com>
parent fe7be35b
......@@ -38,7 +38,9 @@ use std::rc::Rc;
use std::str::from_utf8;
use std::sync::Arc;
use std::{fs, ptr, slice};
use table_properties::{TableProperties, TablePropertiesCollection};
use titan::TitanDBOptions;
pub struct CFHandle {
inner: *mut DBCFHandle,
......@@ -58,10 +60,18 @@ impl Drop for CFHandle {
}
}
fn ensure_default_cf_exists<'a>(list: &mut Vec<ColumnFamilyDescriptor<'a>>, ttls: &mut Vec<i32>) {
fn ensure_default_cf_exists<'a>(
list: &mut Vec<ColumnFamilyDescriptor<'a>>,
ttls: &mut Vec<i32>,
is_titan: bool,
) {
let contains = list.iter().any(|ref cf| cf.is_default());
if !contains {
list.push(ColumnFamilyDescriptor::default());
let mut desc = ColumnFamilyDescriptor::default();
if is_titan {
desc.options.set_titandb_options(&TitanDBOptions::new());
}
list.push(desc);
if ttls.len() > 0 {
ttls.push(0);
}
......@@ -541,7 +551,7 @@ impl DB {
let mut descs = cfds.into_iter().map(|t| t.into()).collect();
let mut ttls_vec = ttls.to_vec();
ensure_default_cf_exists(&mut descs, &mut ttls_vec);
ensure_default_cf_exists(&mut descs, &mut ttls_vec, !opts.titan_inner.is_null());
let (names, options) = split_descriptors(descs);
let cstrings = build_cstring_list(&names);
......
......@@ -195,6 +195,29 @@ fn test_titandb() {
check_table_properties(&db, num_entries / 2, num_entries);
}
#[test]
fn test_titan_sequence_number() {
let path = tempdir_with_prefix("test_titan_sequence_number");
let tdb_path = path.path().join("titandb");
let mut tdb_opts = TitanDBOptions::new();
tdb_opts.set_dirname(tdb_path.to_str().unwrap());
let mut opts = DBOptions::new();
opts.create_if_missing(true);
opts.set_titandb_options(&tdb_opts);
let db = DB::open(opts, path.path().to_str().unwrap()).unwrap();
let snap = db.snapshot();
let snap_seq = snap.get_sequence_number();
let seq1 = db.get_latest_sequence_number();
assert_eq!(snap_seq, seq1);
db.put(b"key", b"value").unwrap();
let seq2 = db.get_latest_sequence_number();
assert!(seq2 > seq1);
}
#[test]
fn test_titan_blob_index() {
let mut index = TitanBlobIndex::default();
......
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