Commit 130c764e authored by follitude's avatar follitude Committed by zhangjinpeng1987

refactor options (#102)

parent 240e5b66
This diff is collapsed.
...@@ -39,8 +39,9 @@ pub use librocksdb_sys::{DBCompactionStyle, DBCompressionType, DBRecoveryMode, D ...@@ -39,8 +39,9 @@ pub use librocksdb_sys::{DBCompactionStyle, DBCompressionType, DBRecoveryMode, D
pub use merge_operator::MergeOperands; pub use merge_operator::MergeOperands;
pub use rocksdb::{DB, DBIterator, DBVector, Kv, SeekKey, Writable, WriteBatch, CFHandle, Range, pub use rocksdb::{DB, DBIterator, DBVector, Kv, SeekKey, Writable, WriteBatch, CFHandle, Range,
BackupEngine, SstFileWriter}; BackupEngine, SstFileWriter};
pub use rocksdb_options::{BlockBasedOptions, Options, ReadOptions, WriteOptions, RestoreOptions, pub use rocksdb_options::{BlockBasedOptions, DBOptions, ColumnFamilyOptions, ReadOptions,
IngestExternalFileOptions, EnvOptions, HistogramData, CompactOptions}; WriteOptions, RestoreOptions, IngestExternalFileOptions, EnvOptions,
HistogramData, CompactOptions};
pub use slice_transform::SliceTransform; pub use slice_transform::SliceTransform;
pub use table_properties::{TableProperties, TablePropertiesCollection, pub use table_properties::{TableProperties, TablePropertiesCollection,
TablePropertiesCollectionView, UserCollectedProperties}; TablePropertiesCollectionView, UserCollectedProperties};
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
// //
extern crate rocksdb; extern crate rocksdb;
use rocksdb::{DB, MergeOperands, Options, Writable}; use rocksdb::{DB, MergeOperands, DBOptions, Writable, ColumnFamilyOptions};
// fn snapshot_test() { // fn snapshot_test() {
// let path = "_rust_rocksdb_iteratortest"; // let path = "_rust_rocksdb_iteratortest";
...@@ -87,11 +87,12 @@ fn concat_merge(_: &[u8], existing_val: Option<&[u8]>, operands: &mut MergeOpera ...@@ -87,11 +87,12 @@ fn concat_merge(_: &[u8], existing_val: Option<&[u8]>, operands: &mut MergeOpera
fn custom_merge() { fn custom_merge() {
let path = "_rust_rocksdb_mergetest"; let path = "_rust_rocksdb_mergetest";
let mut opts = Options::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
opts.add_merge_operator("test operator", concat_merge); let mut cf_opts = ColumnFamilyOptions::new();
cf_opts.add_merge_operator("test operator", concat_merge);
{ {
let db = DB::open(opts, path).unwrap(); let db = DB::open_cf(opts, path, vec!["default"], vec![cf_opts]).unwrap();
db.put(b"k1", b"a").unwrap(); db.put(b"k1", b"a").unwrap();
db.merge(b"k1", b"b").unwrap(); db.merge(b"k1", b"b").unwrap();
db.merge(b"k1", b"c").unwrap(); db.merge(b"k1", b"c").unwrap();
...@@ -109,19 +110,19 @@ fn custom_merge() { ...@@ -109,19 +110,19 @@ fn custom_merge() {
Err(e) => println!("error retrieving value: {}", e), Err(e) => println!("error retrieving value: {}", e),
} }
} }
let opts = Options::new(); let opts = DBOptions::new();
DB::destroy(&opts, path).is_ok(); DB::destroy(&opts, path).is_ok();
} }
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use rocksdb::{BlockBasedOptions, DB, DBCompressionType, Options}; use rocksdb::{BlockBasedOptions, DB, DBCompressionType, ColumnFamilyOptions, DBOptions};
use rocksdb::DBCompactionStyle; use rocksdb::DBCompactionStyle;
use rocksdb::DBRecoveryMode; use rocksdb::DBRecoveryMode;
#[allow(dead_code)] #[allow(dead_code)]
fn tuned_for_somebody_elses_disk(path: &str, fn tuned_for_somebody_elses_disk(path: &str,
mut opts: Options, mut opts: DBOptions,
blockopts: &mut BlockBasedOptions) blockopts: &mut BlockBasedOptions)
-> DB { -> DB {
let per_level_compression: [DBCompressionType; 7] = [DBCompressionType::No, let per_level_compression: [DBCompressionType; 7] = [DBCompressionType::No,
...@@ -131,39 +132,39 @@ mod tests { ...@@ -131,39 +132,39 @@ mod tests {
DBCompressionType::Lz4, DBCompressionType::Lz4,
DBCompressionType::Lz4, DBCompressionType::Lz4,
DBCompressionType::Lz4]; DBCompressionType::Lz4];
let mut cf_opts = ColumnFamilyOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
opts.set_max_open_files(10000); opts.set_max_open_files(10000);
opts.set_use_fsync(false); opts.set_use_fsync(false);
opts.set_bytes_per_sync(8388608); opts.set_bytes_per_sync(8388608);
opts.set_block_cache_size_mb(1024); cf_opts.set_block_cache_size_mb(1024);
opts.set_table_cache_num_shard_bits(6); opts.set_table_cache_num_shard_bits(6);
opts.set_max_write_buffer_number(32); cf_opts.set_max_write_buffer_number(32);
opts.set_write_buffer_size(536870912); cf_opts.set_write_buffer_size(536870912);
opts.set_target_file_size_base(1073741824); cf_opts.set_target_file_size_base(1073741824);
opts.set_min_write_buffer_number_to_merge(4); cf_opts.set_min_write_buffer_number_to_merge(4);
opts.set_level_zero_file_num_compaction_trigger(4); cf_opts.set_level_zero_file_num_compaction_trigger(4);
opts.set_level_zero_stop_writes_trigger(2000); cf_opts.set_level_zero_stop_writes_trigger(2000);
opts.set_level_zero_slowdown_writes_trigger(0); cf_opts.set_level_zero_slowdown_writes_trigger(0);
opts.set_compaction_style(DBCompactionStyle::Universal); cf_opts.set_compaction_style(DBCompactionStyle::Universal);
opts.set_max_background_compactions(4); opts.set_max_background_compactions(4);
opts.set_max_background_flushes(4); opts.set_max_background_flushes(4);
opts.set_report_bg_io_stats(true); cf_opts.set_report_bg_io_stats(true);
opts.set_wal_recovery_mode(DBRecoveryMode::PointInTime); opts.set_wal_recovery_mode(DBRecoveryMode::PointInTime);
opts.enable_statistics(); opts.enable_statistics();
opts.set_stats_dump_period_sec(60); opts.set_stats_dump_period_sec(60);
opts.compression_per_level(&per_level_compression); cf_opts.compression_per_level(&per_level_compression);
blockopts.set_block_size(524288); blockopts.set_block_size(524288);
blockopts.set_cache_index_and_filter_blocks(true); blockopts.set_cache_index_and_filter_blocks(true);
blockopts.set_bloom_filter(10, false); blockopts.set_bloom_filter(10, false);
opts.set_block_based_table_factory(blockopts); cf_opts.set_block_based_table_factory(blockopts);
opts.set_disable_auto_compactions(true); cf_opts.set_disable_auto_compactions(true);
opts.set_max_compaction_bytes(1073741824 * 25); cf_opts.set_max_compaction_bytes(1073741824 * 25);
// let filter = new_bloom_filter(10); // let filter = new_bloom_filter(10);
// opts.set_filter(filter); // opts.set_filter(filter);
DB::open(opts, path).unwrap() DB::open_cf(opts, path, vec!["default"], vec![cf_opts]).unwrap()
} }
// TODO(tyler) unstable // TODO(tyler) unstable
......
...@@ -148,7 +148,7 @@ impl<'a> Iterator for &'a mut MergeOperands { ...@@ -148,7 +148,7 @@ impl<'a> Iterator for &'a mut MergeOperands {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use rocksdb::{DB, DBVector, Writable}; use rocksdb::{DB, DBVector, Writable};
use rocksdb_options::Options; use rocksdb_options::{DBOptions, ColumnFamilyOptions};
use super::*; use super::*;
use tempdir::TempDir; use tempdir::TempDir;
...@@ -177,10 +177,15 @@ mod test { ...@@ -177,10 +177,15 @@ mod test {
#[test] #[test]
fn mergetest() { fn mergetest() {
let path = TempDir::new("_rust_rocksdb_mergetest").expect(""); let path = TempDir::new("_rust_rocksdb_mergetest").expect("");
let mut opts = Options::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
opts.add_merge_operator("test operator", test_provided_merge); let mut cf_opts = ColumnFamilyOptions::new();
let db = DB::open(opts, path.path().to_str().unwrap()).unwrap(); cf_opts.add_merge_operator("test operator", test_provided_merge);
let db = DB::open_cf(opts,
path.path().to_str().unwrap(),
vec!["default"],
vec![cf_opts])
.unwrap();
let p = db.put(b"k1", b"a"); let p = db.put(b"k1", b"a");
assert!(p.is_ok()); assert!(p.is_ok());
let _ = db.merge(b"k1", b"b"); let _ = db.merge(b"k1", b"b");
......
This diff is collapsed.
This diff is collapsed.
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
// limitations under the License. // limitations under the License.
// //
use rocksdb::{DB, MergeOperands, Options, Writable}; use rocksdb::{DB, MergeOperands, DBOptions, ColumnFamilyOptions, Writable};
use tempdir::TempDir; use tempdir::TempDir;
#[test] #[test]
...@@ -23,12 +23,13 @@ pub fn test_column_family() { ...@@ -23,12 +23,13 @@ pub fn test_column_family() {
// should be able to create column families // should be able to create column families
{ {
let mut opts = Options::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
opts.add_merge_operator("test operator", test_provided_merge); let mut cf_opts = ColumnFamilyOptions::new();
let mut db = DB::open(opts, path_str).unwrap(); cf_opts.add_merge_operator("test operator", test_provided_merge);
let opts = Options::new(); let mut db = DB::open_cf(opts, path_str, vec!["default"], vec![cf_opts]).unwrap();
match db.create_cf("cf1", &opts) { let cf_opts = ColumnFamilyOptions::new();
match db.create_cf("cf1", cf_opts) {
Ok(_) => println!("cf1 created successfully"), Ok(_) => println!("cf1 created successfully"),
Err(e) => { Err(e) => {
panic!("could not create column family: {}", e); panic!("could not create column family: {}", e);
...@@ -39,9 +40,9 @@ pub fn test_column_family() { ...@@ -39,9 +40,9 @@ pub fn test_column_family() {
// should fail to open db without specifying same column families // should fail to open db without specifying same column families
{ {
let mut opts = Options::new(); let mut cf_opts = ColumnFamilyOptions::new();
opts.add_merge_operator("test operator", test_provided_merge); cf_opts.add_merge_operator("test operator", test_provided_merge);
match DB::open(opts, path_str) { match DB::open_cf(DBOptions::new(), path_str, vec!["default"], vec![cf_opts]) {
Ok(_) => { Ok(_) => {
panic!("should not have opened DB successfully without \ panic!("should not have opened DB successfully without \
specifying column specifying column
...@@ -56,18 +57,18 @@ pub fn test_column_family() { ...@@ -56,18 +57,18 @@ pub fn test_column_family() {
// should properly open db when specifying all column families // should properly open db when specifying all column families
{ {
let mut opts = Options::new(); let mut cf_opts = ColumnFamilyOptions::new();
opts.add_merge_operator("test operator", test_provided_merge); cf_opts.add_merge_operator("test operator", test_provided_merge);
match DB::open_cf(Options::new(), path_str, &["cf1"], &[&opts]) { match DB::open_cf(DBOptions::new(), path_str, vec!["cf1"], vec![cf_opts]) {
Ok(_) => println!("successfully opened db with column family"), Ok(_) => println!("successfully opened db with column family"),
Err(e) => panic!("failed to open db with column family: {}", e), Err(e) => panic!("failed to open db with column family: {}", e),
} }
} }
// TODO should be able to write, read, merge, batch, and iterate over a cf // TODO should be able to write, read, merge, batch, and iterate over a cf
{ {
let mut opts = Options::new(); let mut cf_opts = ColumnFamilyOptions::new();
opts.add_merge_operator("test operator", test_provided_merge); cf_opts.add_merge_operator("test operator", test_provided_merge);
let db = match DB::open_cf(Options::new(), path_str, &["cf1"], &[&opts]) { let db = match DB::open_cf(DBOptions::new(), path_str, vec!["cf1"], vec![cf_opts]) {
Ok(db) => { Ok(db) => {
println!("successfully opened db with column family"); println!("successfully opened db with column family");
db db
...@@ -114,9 +115,13 @@ pub fn test_column_family() { ...@@ -114,9 +115,13 @@ pub fn test_column_family() {
{} {}
// TODO should be able to iterate over a cf // TODO should be able to iterate over a cf
{} {}
// should b able to drop a cf // should be able to drop a cf
{ {
let mut db = DB::open_cf(Options::new(), path_str, &["cf1"], &[&Options::new()]).unwrap(); let mut db = DB::open_cf(DBOptions::new(),
path_str,
vec!["cf1"],
vec![ColumnFamilyOptions::new()])
.unwrap();
match db.drop_cf("cf1") { match db.drop_cf("cf1") {
Ok(_) => println!("cf1 successfully dropped."), Ok(_) => println!("cf1 successfully dropped."),
Err(e) => panic!("failed to drop column family: {}", e), Err(e) => panic!("failed to drop column family: {}", e),
......
...@@ -11,14 +11,14 @@ ...@@ -11,14 +11,14 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use rocksdb::{DB, Options, Range, Writable}; use rocksdb::{DB, DBOptions, Range, Writable};
use tempdir::TempDir; use tempdir::TempDir;
#[test] #[test]
fn test_compact_range() { fn test_compact_range() {
let path = TempDir::new("_rust_rocksdb_test_compact_range").expect(""); let path = TempDir::new("_rust_rocksdb_test_compact_range").expect("");
let mut opts = Options::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
let db = DB::open(opts, path.path().to_str().unwrap()).unwrap(); let db = DB::open(opts, path.path().to_str().unwrap()).unwrap();
let samples = vec![(b"k1".to_vec(), b"value--------1".to_vec()), let samples = vec![(b"k1".to_vec(), b"value--------1".to_vec()),
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use rocksdb::{Writable, DB, CompactionFilter, Options}; use rocksdb::{Writable, DB, CompactionFilter, DBOptions, ColumnFamilyOptions};
use std::sync::{Arc, RwLock}; use std::sync::{Arc, RwLock};
use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::atomic::{AtomicBool, Ordering};
use tempdir::TempDir; use tempdir::TempDir;
...@@ -40,19 +40,24 @@ impl Drop for Filter { ...@@ -40,19 +40,24 @@ impl Drop for Filter {
#[test] #[test]
fn test_compaction_filter() { fn test_compaction_filter() {
let path = TempDir::new("_rust_rocksdb_writebacktest").expect(""); let path = TempDir::new("_rust_rocksdb_writebacktest").expect("");
let mut opts = Options::new(); let mut cf_opts = ColumnFamilyOptions::new();
let drop_called = Arc::new(AtomicBool::new(false)); let drop_called = Arc::new(AtomicBool::new(false));
let filtered_kvs = Arc::new(RwLock::new(vec![])); let filtered_kvs = Arc::new(RwLock::new(vec![]));
// set ignore_snapshots to false // set ignore_snapshots to false
opts.set_compaction_filter("test", cf_opts.set_compaction_filter("test",
false, false,
Box::new(Filter { Box::new(Filter {
drop_called: drop_called.clone(), drop_called: drop_called.clone(),
filtered_kvs: filtered_kvs.clone(), filtered_kvs: filtered_kvs.clone(),
})) }))
.unwrap(); .unwrap();
let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
let db = DB::open(opts, path.path().to_str().unwrap()).unwrap(); let db = DB::open_cf(opts,
path.path().to_str().unwrap(),
vec!["default"],
vec![cf_opts])
.unwrap();
let samples = vec![(b"key1".to_vec(), b"value1".to_vec()), let samples = vec![(b"key1".to_vec(), b"value1".to_vec()),
(b"key2".to_vec(), b"value2".to_vec())]; (b"key2".to_vec(), b"value2".to_vec())];
for &(ref k, ref v) in &samples { for &(ref k, ref v) in &samples {
...@@ -71,10 +76,10 @@ fn test_compaction_filter() { ...@@ -71,10 +76,10 @@ fn test_compaction_filter() {
} }
drop(db); drop(db);
// reregister with ignore_snapshots set to true // reregister with ignore_snapshots set to true
let mut opts = Options::new(); let mut cf_opts = ColumnFamilyOptions::new();
opts.set_compaction_filter("test", let opts = DBOptions::new();
cf_opts.set_compaction_filter("test",
true, true,
Box::new(Filter { Box::new(Filter {
drop_called: drop_called.clone(), drop_called: drop_called.clone(),
...@@ -84,7 +89,11 @@ fn test_compaction_filter() { ...@@ -84,7 +89,11 @@ fn test_compaction_filter() {
assert!(drop_called.load(Ordering::Relaxed)); assert!(drop_called.load(Ordering::Relaxed));
drop_called.store(false, Ordering::Relaxed); drop_called.store(false, Ordering::Relaxed);
{ {
let db = DB::open(opts, path.path().to_str().unwrap()).unwrap(); let db = DB::open_cf(opts,
path.path().to_str().unwrap(),
vec!["default"],
vec![cf_opts])
.unwrap();
let _snap = db.snapshot(); let _snap = db.snapshot();
// Because ignore_snapshots is true, so all the keys will be compacted. // Because ignore_snapshots is true, so all the keys will be compacted.
db.compact_range(Some(b"key1"), Some(b"key3")); db.compact_range(Some(b"key1"), Some(b"key3"));
...@@ -93,6 +102,5 @@ fn test_compaction_filter() { ...@@ -93,6 +102,5 @@ fn test_compaction_filter() {
} }
assert_eq!(*filtered_kvs.read().unwrap(), samples); assert_eq!(*filtered_kvs.read().unwrap(), samples);
} }
assert!(drop_called.load(Ordering::Relaxed)); assert!(drop_called.load(Ordering::Relaxed));
} }
...@@ -15,7 +15,7 @@ use rocksdb::*; ...@@ -15,7 +15,7 @@ use rocksdb::*;
use std::fs; use std::fs;
use tempdir::TempDir; use tempdir::TempDir;
fn gen_sst(opt: Options, cf: Option<&CFHandle>, path: &str) { fn gen_sst(opt: ColumnFamilyOptions, cf: Option<&CFHandle>, path: &str) {
let _ = fs::remove_file(path); let _ = fs::remove_file(path);
let env_opt = EnvOptions::new(); let env_opt = EnvOptions::new();
let mut writer = if cf.is_some() { let mut writer = if cf.is_some() {
...@@ -157,7 +157,7 @@ fn test_delete_range_sst_files() { ...@@ -157,7 +157,7 @@ fn test_delete_range_sst_files() {
fn test_delete_range_ingest_file() { fn test_delete_range_ingest_file() {
let path = TempDir::new("_rust_rocksdb_test_delete_range_ingest_file").expect(""); let path = TempDir::new("_rust_rocksdb_test_delete_range_ingest_file").expect("");
let path_str = path.path().to_str().unwrap(); let path_str = path.path().to_str().unwrap();
let mut opts = Options::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
let mut db = DB::open(opts, path_str).unwrap(); let mut db = DB::open(opts, path_str).unwrap();
let gen_path = TempDir::new("_rust_rocksdb_ingest_sst_gen").expect(""); let gen_path = TempDir::new("_rust_rocksdb_ingest_sst_gen").expect("");
...@@ -183,10 +183,10 @@ fn test_delete_range_ingest_file() { ...@@ -183,10 +183,10 @@ fn test_delete_range_ingest_file() {
db.cf_handle("default"), db.cf_handle("default"),
&[(b"key1", None), (b"key2", None), (b"key3", None), (b"key4", Some(b"value4"))]); &[(b"key1", None), (b"key2", None), (b"key3", None), (b"key4", Some(b"value4"))]);
let cf_opts = Options::new(); let cf_opts = ColumnFamilyOptions::new();
db.create_cf("cf1", &cf_opts).unwrap(); db.create_cf("cf1", cf_opts).unwrap();
let handle = db.cf_handle("cf1").unwrap(); let handle = db.cf_handle("cf1").unwrap();
gen_sst(cf_opts, None, test_sstfile_str); gen_sst(ColumnFamilyOptions::new(), None, test_sstfile_str);
db.ingest_external_file_cf(handle, &ingest_opt, &[test_sstfile_str]) db.ingest_external_file_cf(handle, &ingest_opt, &[test_sstfile_str])
.unwrap(); .unwrap();
......
...@@ -77,7 +77,7 @@ fn test_event_listener_basic() { ...@@ -77,7 +77,7 @@ fn test_event_listener_basic() {
let path = TempDir::new("_rust_rocksdb_event_listener_flush").expect(""); let path = TempDir::new("_rust_rocksdb_event_listener_flush").expect("");
let path_str = path.path().to_str().unwrap(); let path_str = path.path().to_str().unwrap();
let mut opts = Options::new(); let mut opts = DBOptions::new();
let counter = EventCounter::default(); let counter = EventCounter::default();
opts.add_event_listener(counter.clone()); opts.add_event_listener(counter.clone());
opts.create_if_missing(true); opts.create_if_missing(true);
...@@ -111,7 +111,7 @@ fn test_event_listener_ingestion() { ...@@ -111,7 +111,7 @@ fn test_event_listener_ingestion() {
let path = TempDir::new("_rust_rocksdb_event_listener_ingestion").expect(""); let path = TempDir::new("_rust_rocksdb_event_listener_ingestion").expect("");
let path_str = path.path().to_str().unwrap(); let path_str = path.path().to_str().unwrap();
let mut opts = Options::new(); let mut opts = DBOptions::new();
let counter = EventCounter::default(); let counter = EventCounter::default();
opts.add_event_listener(counter.clone()); opts.add_event_listener(counter.clone());
opts.create_if_missing(true); opts.create_if_missing(true);
......
...@@ -16,7 +16,10 @@ use rocksdb::*; ...@@ -16,7 +16,10 @@ use rocksdb::*;
use std::fs; use std::fs;
use tempdir::TempDir; use tempdir::TempDir;
pub fn gen_sst(opt: Options, cf: Option<&CFHandle>, path: &str, data: &[(&[u8], &[u8])]) { pub fn gen_sst(opt: ColumnFamilyOptions,
cf: Option<&CFHandle>,
path: &str,
data: &[(&[u8], &[u8])]) {
let _ = fs::remove_file(path); let _ = fs::remove_file(path);
let env_opt = EnvOptions::new(); let env_opt = EnvOptions::new();
let mut writer = if cf.is_some() { let mut writer = if cf.is_some() {
...@@ -36,11 +39,11 @@ fn test_ingest_external_file() { ...@@ -36,11 +39,11 @@ fn test_ingest_external_file() {
let path = TempDir::new("_rust_rocksdb_ingest_sst").expect(""); let path = TempDir::new("_rust_rocksdb_ingest_sst").expect("");
let path_str = path.path().to_str().unwrap(); let path_str = path.path().to_str().unwrap();
let mut opts = Options::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
let mut db = DB::open(opts, path_str).unwrap(); let mut db = DB::open(opts, path_str).unwrap();
let cf_opts = Options::new(); let cf_opts = ColumnFamilyOptions::new();
db.create_cf("cf1", &cf_opts).unwrap(); db.create_cf("cf1", cf_opts).unwrap();
let handle = db.cf_handle("cf1").unwrap(); let handle = db.cf_handle("cf1").unwrap();
let gen_path = TempDir::new("_rust_rocksdb_ingest_sst_gen").expect(""); let gen_path = TempDir::new("_rust_rocksdb_ingest_sst_gen").expect("");
...@@ -60,7 +63,7 @@ fn test_ingest_external_file() { ...@@ -60,7 +63,7 @@ fn test_ingest_external_file() {
assert_eq!(db.get(b"k1").unwrap().unwrap(), b"v1"); assert_eq!(db.get(b"k1").unwrap().unwrap(), b"v1");
assert_eq!(db.get(b"k2").unwrap().unwrap(), b"v2"); assert_eq!(db.get(b"k2").unwrap().unwrap(), b"v2");
gen_sst(cf_opts, gen_sst(ColumnFamilyOptions::new(),
None, None,
test_sstfile_str, test_sstfile_str,
&[(b"k1", b"v3"), (b"k2", b"v4")]); &[(b"k1", b"v3"), (b"k2", b"v4")]);
...@@ -71,8 +74,7 @@ fn test_ingest_external_file() { ...@@ -71,8 +74,7 @@ fn test_ingest_external_file() {
let snap = db.snapshot(); let snap = db.snapshot();
let opt = Options::new(); gen_sst(ColumnFamilyOptions::new(),
gen_sst(opt,
None, None,
test_sstfile_str, test_sstfile_str,
&[(b"k2", b"v5"), (b"k3", b"v6")]); &[(b"k2", b"v5"), (b"k3", b"v6")]);
...@@ -86,4 +88,4 @@ fn test_ingest_external_file() { ...@@ -86,4 +88,4 @@ fn test_ingest_external_file() {
assert_eq!(snap.get_cf(handle, b"k1").unwrap().unwrap(), b"v3"); assert_eq!(snap.get_cf(handle, b"k1").unwrap().unwrap(), b"v3");
assert_eq!(snap.get_cf(handle, b"k2").unwrap().unwrap(), b"v4"); assert_eq!(snap.get_cf(handle, b"k2").unwrap().unwrap(), b"v4");
assert!(snap.get_cf(handle, b"k3").unwrap().is_none()); assert!(snap.get_cf(handle, b"k3").unwrap().is_none());
} }
\ No newline at end of file
...@@ -165,7 +165,7 @@ pub fn test_iterator() { ...@@ -165,7 +165,7 @@ pub fn test_iterator() {
#[test] #[test]
fn test_seek_for_prev() { fn test_seek_for_prev() {
let path = TempDir::new("_rust_rocksdb_seek_for_prev").expect(""); let path = TempDir::new("_rust_rocksdb_seek_for_prev").expect("");
let mut opts = Options::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
{ {
let db = DB::open(opts, path.path().to_str().unwrap()).unwrap(); let db = DB::open(opts, path.path().to_str().unwrap()).unwrap();
...@@ -213,7 +213,7 @@ fn test_seek_for_prev() { ...@@ -213,7 +213,7 @@ fn test_seek_for_prev() {
#[test] #[test]
fn read_with_upper_bound() { fn read_with_upper_bound() {
let path = TempDir::new("_rust_rocksdb_read_with_upper_bound_test").expect(""); let path = TempDir::new("_rust_rocksdb_read_with_upper_bound_test").expect("");
let mut opts = Options::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
{ {
let db = DB::open(opts, path.path().to_str().unwrap()).unwrap(); let db = DB::open(opts, path.path().to_str().unwrap()).unwrap();
...@@ -237,18 +237,23 @@ fn test_total_order_seek() { ...@@ -237,18 +237,23 @@ fn test_total_order_seek() {
let mut bbto = BlockBasedOptions::new(); let mut bbto = BlockBasedOptions::new();
bbto.set_bloom_filter(10, false); bbto.set_bloom_filter(10, false);
bbto.set_whole_key_filtering(false); bbto.set_whole_key_filtering(false);
let mut opts = Options::new(); let mut cf_opts = ColumnFamilyOptions::new();
let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
opts.set_block_based_table_factory(&bbto); cf_opts.set_block_based_table_factory(&bbto);
opts.set_prefix_extractor("FixedPrefixTransform", cf_opts.set_prefix_extractor("FixedPrefixTransform",
Box::new(FixedPrefixTransform { prefix_len: 2 })) Box::new(FixedPrefixTransform { prefix_len: 2 }))
.unwrap(); .unwrap();
// also create prefix bloom for memtable // also create prefix bloom for memtable
opts.set_memtable_prefix_bloom_size_ratio(0.1 as f64); cf_opts.set_memtable_prefix_bloom_size_ratio(0.1 as f64);
let keys = vec![b"k1-1", b"k1-2", b"k1-3", b"k2-1", b"k2-2", b"k2-3", b"k3-1", b"k3-2", let keys = vec![b"k1-1", b"k1-2", b"k1-3", b"k2-1", b"k2-2", b"k2-3", b"k3-1", b"k3-2",
b"k3-3"]; b"k3-3"];
let db = DB::open(opts, path.path().to_str().unwrap()).unwrap(); let db = DB::open_cf(opts,
path.path().to_str().unwrap(),
vec!["default"],
vec![cf_opts])
.unwrap();
let wopts = WriteOptions::new(); let wopts = WriteOptions::new();
// sst1 // sst1
...@@ -315,14 +320,19 @@ fn test_fixed_suffix_seek() { ...@@ -315,14 +320,19 @@ fn test_fixed_suffix_seek() {
let mut bbto = BlockBasedOptions::new(); let mut bbto = BlockBasedOptions::new();
bbto.set_bloom_filter(10, false); bbto.set_bloom_filter(10, false);
bbto.set_whole_key_filtering(false); bbto.set_whole_key_filtering(false);
let mut opts = Options::new(); let mut opts = DBOptions::new();
let mut cf_opts = ColumnFamilyOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
opts.set_block_based_table_factory(&bbto); cf_opts.set_block_based_table_factory(&bbto);
opts.set_prefix_extractor("FixedSuffixTransform", cf_opts.set_prefix_extractor("FixedSuffixTransform",
Box::new(FixedSuffixTransform { suffix_len: 2 })) Box::new(FixedSuffixTransform { suffix_len: 2 }))
.unwrap(); .unwrap();
let db = DB::open(opts, path.path().to_str().unwrap()).unwrap(); let db = DB::open_cf(opts,
path.path().to_str().unwrap(),
vec!["default"],
vec![cf_opts])
.unwrap();
db.put(b"k-eghe-5", b"a").unwrap(); db.put(b"k-eghe-5", b"a").unwrap();
db.put(b"k-24yfae-6", b"a").unwrap(); db.put(b"k-24yfae-6", b"a").unwrap();
db.put(b"k-h1fwd-7", b"a").unwrap(); db.put(b"k-h1fwd-7", b"a").unwrap();
......
...@@ -36,7 +36,7 @@ fn test_prefix_extractor_compatibility() { ...@@ -36,7 +36,7 @@ fn test_prefix_extractor_compatibility() {
// create db with no prefix extractor, and insert data // create db with no prefix extractor, and insert data
{ {
let mut opts = Options::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
let db = DB::open(opts, path.path().to_str().unwrap()).unwrap(); let db = DB::open(opts, path.path().to_str().unwrap()).unwrap();
let wopts = WriteOptions::new(); let wopts = WriteOptions::new();
...@@ -53,15 +53,20 @@ fn test_prefix_extractor_compatibility() { ...@@ -53,15 +53,20 @@ fn test_prefix_extractor_compatibility() {
let mut bbto = BlockBasedOptions::new(); let mut bbto = BlockBasedOptions::new();
bbto.set_bloom_filter(10, false); bbto.set_bloom_filter(10, false);
bbto.set_whole_key_filtering(false); bbto.set_whole_key_filtering(false);
let mut opts = Options::new(); let mut opts = DBOptions::new();
let mut cf_opts = ColumnFamilyOptions::new();
opts.create_if_missing(false); opts.create_if_missing(false);
opts.set_block_based_table_factory(&bbto); cf_opts.set_block_based_table_factory(&bbto);
opts.set_prefix_extractor("FixedPrefixTransform", cf_opts.set_prefix_extractor("FixedPrefixTransform",
Box::new(FixedPrefixTransform { prefix_len: 2 })) Box::new(FixedPrefixTransform { prefix_len: 2 }))
.unwrap(); .unwrap();
// also create prefix bloom for memtable // also create prefix bloom for memtable
opts.set_memtable_prefix_bloom_size_ratio(0.1 as f64); cf_opts.set_memtable_prefix_bloom_size_ratio(0.1 as f64);
let db = DB::open(opts, path.path().to_str().unwrap()).unwrap(); let db = DB::open_cf(opts,
path.path().to_str().unwrap(),
vec!["default"],
vec![cf_opts])
.unwrap();
let wopts = WriteOptions::new(); let wopts = WriteOptions::new();
// sst2 with prefix bloom. // sst2 with prefix bloom.
......
This diff is collapsed.
...@@ -11,7 +11,8 @@ ...@@ -11,7 +11,8 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use rocksdb::{Writable, DB, SliceTransform, Options, SeekKey, BlockBasedOptions}; use rocksdb::{Writable, DB, SliceTransform, ColumnFamilyOptions, DBOptions, SeekKey,
BlockBasedOptions};
use tempdir::TempDir; use tempdir::TempDir;
struct FixedPostfixTransform { struct FixedPostfixTransform {
...@@ -32,20 +33,25 @@ impl SliceTransform for FixedPostfixTransform { ...@@ -32,20 +33,25 @@ impl SliceTransform for FixedPostfixTransform {
#[test] #[test]
fn test_slice_transform() { fn test_slice_transform() {
let path = TempDir::new("_rust_rocksdb_slice_transform_test").expect(""); let path = TempDir::new("_rust_rocksdb_slice_transform_test").expect("");
let mut opts = Options::new(); let mut opts = DBOptions::new();
let mut cf_opts = ColumnFamilyOptions::new();
let mut block_opts = BlockBasedOptions::new(); let mut block_opts = BlockBasedOptions::new();
block_opts.set_bloom_filter(10, false); block_opts.set_bloom_filter(10, false);
block_opts.set_whole_key_filtering(false); block_opts.set_whole_key_filtering(false);
opts.set_block_based_table_factory(&block_opts); cf_opts.set_block_based_table_factory(&block_opts);
opts.set_memtable_prefix_bloom_size_ratio(0.25); cf_opts.set_memtable_prefix_bloom_size_ratio(0.25);
opts.set_prefix_extractor("test", Box::new(FixedPostfixTransform { postfix_len: 2 })) cf_opts.set_prefix_extractor("test", Box::new(FixedPostfixTransform { postfix_len: 2 }))
.unwrap(); .unwrap();
opts.create_if_missing(true); opts.create_if_missing(true);
let db = DB::open(opts, path.path().to_str().unwrap()).unwrap(); let db = DB::open_cf(opts,
path.path().to_str().unwrap(),
vec!["default"],
vec![cf_opts])
.unwrap();
let samples = vec![(b"key_01".to_vec(), b"1".to_vec()), let samples = vec![(b"key_01".to_vec(), b"1".to_vec()),
(b"key_02".to_vec(), b"2".to_vec()), (b"key_02".to_vec(), b"2".to_vec()),
(b"key_0303".to_vec(), b"3".to_vec()), (b"key_0303".to_vec(), b"3".to_vec()),
......
...@@ -18,7 +18,7 @@ use tempdir::TempDir; ...@@ -18,7 +18,7 @@ use tempdir::TempDir;
#[test] #[test]
fn test_db_statistics() { fn test_db_statistics() {
let path = TempDir::new("_rust_rocksdb_statistics").expect(""); let path = TempDir::new("_rust_rocksdb_statistics").expect("");
let mut opts = Options::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
opts.enable_statistics(); opts.enable_statistics();
let db = DB::open(opts, path.path().to_str().unwrap()).unwrap(); let db = DB::open(opts, path.path().to_str().unwrap()).unwrap();
......
...@@ -12,8 +12,9 @@ ...@@ -12,8 +12,9 @@
// limitations under the License. // limitations under the License.
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
use rocksdb::{DB, Range, Options, Writable, DBEntryType, TablePropertiesCollection, use rocksdb::{DB, Range, ColumnFamilyOptions, DBOptions, Writable, DBEntryType,
TablePropertiesCollector, TablePropertiesCollectorFactory, UserCollectedProperties}; TablePropertiesCollection, TablePropertiesCollector,
TablePropertiesCollectorFactory, UserCollectedProperties};
use std::collections::HashMap; use std::collections::HashMap;
use std::fmt; use std::fmt;
use tempdir::TempDir; use tempdir::TempDir;
...@@ -159,12 +160,17 @@ fn check_collection(collection: &TablePropertiesCollection, ...@@ -159,12 +160,17 @@ fn check_collection(collection: &TablePropertiesCollection,
#[test] #[test]
fn test_table_properties_collector_factory() { fn test_table_properties_collector_factory() {
let f = ExampleFactory::new(); let f = ExampleFactory::new();
let mut opts = Options::new(); let mut opts = DBOptions::new();
let mut cf_opts = ColumnFamilyOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
opts.add_table_properties_collector_factory("example-collector", Box::new(f)); cf_opts.add_table_properties_collector_factory("example-collector", Box::new(f));
let path = TempDir::new("_rust_rocksdb_collectortest").expect(""); let path = TempDir::new("_rust_rocksdb_collectortest").expect("");
let db = DB::open(opts, path.path().to_str().unwrap()).unwrap(); let db = DB::open_cf(opts,
path.path().to_str().unwrap(),
vec!["default"],
vec![cf_opts])
.unwrap();
let samples = vec![(b"key1".to_vec(), b"value1".to_vec()), let samples = vec![(b"key1".to_vec(), b"value1".to_vec()),
(b"key2".to_vec(), b"value2".to_vec()), (b"key2".to_vec(), b"value2".to_vec()),
......
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