1414#include < rocksdb/status.h>
1515#include < rocksdb/cache.h>
1616#include < rocksdb/write_batch.h>
17+ #include < rocksdb/utilities/options_util.h>
1718
1819namespace {
1920 const std::string PROP_NAME = " rocksdb.dbname" ;
@@ -33,6 +34,9 @@ namespace {
3334
3435 const std::string PROP_OPTIMIZE_LEVELCOMP = " rocksdb.optimize_level_style_compaction" ;
3536 const std::string PROP_OPTIMIZE_LEVELCOMP_DEFAULT = " false" ;
37+
38+ const std::string PROP_OPTIONS_FILE = " rocksdb.optionsfile" ;
39+ const std::string PROP_OPTIONS_FILE_DEFAULT = " " ;
3640} // anonymous
3741
3842namespace ycsbc {
@@ -45,7 +49,7 @@ void RocksdbDB::Init() {
4549 const std::lock_guard<std::mutex> lock (mu_);
4650
4751 const utils::Properties &props = *props_;
48- const std::string & format = props.GetProperty (PROP_FORMAT, PROP_FORMAT_DEFAULT);
52+ const std::string format = props.GetProperty (PROP_FORMAT, PROP_FORMAT_DEFAULT);
4953 if (format == " single" ) {
5054 format_ = kSingleEntry ;
5155 method_read_ = &RocksdbDB::ReadSingleEntry;
@@ -71,17 +75,22 @@ void RocksdbDB::Init() {
7175
7276 rocksdb::Options opt;
7377 opt.create_if_missing = true ;
74- GetOptions (props, &opt);
78+ std::vector<rocksdb::ColumnFamilyDescriptor> cf_descs;
79+ std::vector<rocksdb::ColumnFamilyHandle *> cf_handles;
80+ GetOptions (props, &opt, &cf_descs);
7581
7682 rocksdb::Status s;
77-
7883 if (props.GetProperty (PROP_DESTROY, PROP_DESTROY_DEFAULT) == " true" ) {
7984 s = rocksdb::DestroyDB (db_path, opt);
8085 if (!s.ok ()) {
8186 throw utils::Exception (std::string (" RocksDB DestroyDB: " ) + s.ToString ());
8287 }
8388 }
84- s = rocksdb::DB::Open (opt, db_path, &db_);
89+ if (cf_descs.empty ()) {
90+ s = rocksdb::DB::Open (opt, db_path, &db_);
91+ } else {
92+ s = rocksdb::DB::Open (opt, db_path, cf_descs, &cf_handles, &db_);
93+ }
8594 if (!s.ok ()) {
8695 throw utils::Exception (std::string (" RocksDB Open: " ) + s.ToString ());
8796 }
@@ -95,11 +104,22 @@ void RocksdbDB::Cleanup() {
95104 delete db_;
96105}
97106
98- void RocksdbDB::GetOptions (const utils::Properties &props, rocksdb::Options *opt) {
107+ void RocksdbDB::GetOptions (const utils::Properties &props, rocksdb::Options *opt,
108+ std::vector<rocksdb::ColumnFamilyDescriptor> *cf_descs) {
109+ const std::string options_file = props.GetProperty (PROP_OPTIONS_FILE, PROP_OPTIONS_FILE_DEFAULT);
110+ if (options_file != " " ) {
111+ rocksdb::Status s = rocksdb::LoadOptionsFromFile (options_file, rocksdb::Env::Default (), opt,
112+ cf_descs);
113+ if (!s.ok ()) {
114+ throw utils::Exception (std::string (" RocksDB LoadOptionsFromFile: " ) + s.ToString ());
115+ }
116+ return ;
117+ }
118+
99119 const std::string compression_type = props.GetProperty (PROP_COMPRESSION,
100120 PROP_COMPRESSION_DEFAULT);
101121 if (compression_type == " no" ) {
102- opt->compression = rocksdb::kSnappyCompression ;
122+ opt->compression = rocksdb::kNoCompression ;
103123 } else if (compression_type == " snappy" ) {
104124 opt->compression = rocksdb::kSnappyCompression ;
105125 } else if (compression_type == " zlib" ) {
0 commit comments