kv/KeyValueDB: pass kv_options map to ctor

This will let us avoid passing options via global config options.

Signed-off-by: Sage Weil <sage@redhat.com>
This commit is contained in:
Sage Weil 2017-11-20 14:52:18 -06:00
parent e6612ade1d
commit 33a333ebaa
4 changed files with 10 additions and 4 deletions

View File

@ -15,6 +15,7 @@
KeyValueDB *KeyValueDB::create(CephContext *cct, const string& type,
const string& dir,
map<string,string> options,
void *p)
{
#ifdef WITH_LEVELDB
@ -30,7 +31,7 @@ KeyValueDB *KeyValueDB::create(CephContext *cct, const string& type,
#endif
#ifdef HAVE_LIBROCKSDB
if (type == "rocksdb") {
return new RocksDBStore(cct, dir, p);
return new RocksDBStore(cct, dir, options, p);
}
#endif

View File

@ -151,6 +151,7 @@ public:
/// create a new instance
static KeyValueDB *create(CephContext *cct, const std::string& type,
const std::string& dir,
map<std::string,std::string> options = {},
void *p = NULL);
/// test whether we can successfully initialize; may have side effects (e.g., create)

View File

@ -71,6 +71,7 @@ class RocksDBStore : public KeyValueDB {
CephContext *cct;
PerfCounters *logger;
string path;
map<string,string> kv_options;
void *priv;
rocksdb::DB *db;
rocksdb::Env *env;
@ -138,10 +139,11 @@ public:
compact_range_async(combine_strings(prefix, start), combine_strings(prefix, end));
}
RocksDBStore(CephContext *c, const string &path, void *p) :
RocksDBStore(CephContext *c, const string &path, map<string,string> opt, void *p) :
cct(c),
logger(NULL),
path(path),
kv_options(opt),
priv(p),
db(NULL),
env(static_cast<rocksdb::Env*>(p)),

View File

@ -13,7 +13,8 @@ const string dir("rocksdb.test_temp_dir");
TEST(RocksDBOption, simple) {
rocksdb::Options options;
rocksdb::Status status;
RocksDBStore *db = new RocksDBStore(g_ceph_context, dir, NULL);
map<string,string> kvoptions;
RocksDBStore *db = new RocksDBStore(g_ceph_context, dir, kvoptions, NULL);
string options_string = ""
"write_buffer_size=536870912;"
"create_if_missing=true;"
@ -42,7 +43,8 @@ TEST(RocksDBOption, simple) {
TEST(RocksDBOption, interpret) {
rocksdb::Options options;
rocksdb::Status status;
RocksDBStore *db = new RocksDBStore(g_ceph_context, dir, NULL);
map<string,string> kvoptions;
RocksDBStore *db = new RocksDBStore(g_ceph_context, dir, kvoptions, NULL);
string options_string = "compact_on_mount = true; compaction_threads=10;flusher_threads=5;";
int r = db->ParseOptionsFromString(options_string, options);