From 65f720ae9d29fb19a8705b8e9094a9b3463944bb Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Thu, 10 Dec 2015 16:10:24 -0500 Subject: [PATCH] kv/RocksDBStore: take custom Env Signed-off-by: Sage Weil --- src/kv/KeyValueDB.cc | 5 ++-- src/kv/KeyValueDB.h | 3 ++- src/kv/Makefile.am | 4 +-- src/kv/RocksDBStore.cc | 26 +++++++++++++------ src/kv/RocksDBStore.h | 7 ++++- .../objectstore/TestRocksdbOptionParse.cc | 4 +-- 6 files changed, 33 insertions(+), 16 deletions(-) diff --git a/src/kv/KeyValueDB.cc b/src/kv/KeyValueDB.cc index 65ce487ed8065..9437958739ae8 100644 --- a/src/kv/KeyValueDB.cc +++ b/src/kv/KeyValueDB.cc @@ -11,7 +11,8 @@ #endif KeyValueDB *KeyValueDB::create(CephContext *cct, const string& type, - const string& dir) + const string& dir, + void *p) { if (type == "leveldb") { return new LevelDBStore(cct, dir); @@ -25,7 +26,7 @@ KeyValueDB *KeyValueDB::create(CephContext *cct, const string& type, #ifdef HAVE_LIBROCKSDB if (type == "rocksdb" && cct->check_experimental_feature_enabled("rocksdb")) { - return new RocksDBStore(cct, dir); + return new RocksDBStore(cct, dir, p); } #endif return NULL; diff --git a/src/kv/KeyValueDB.h b/src/kv/KeyValueDB.h index 347169aecb8e4..8b26d5d6bf401 100644 --- a/src/kv/KeyValueDB.h +++ b/src/kv/KeyValueDB.h @@ -99,7 +99,8 @@ public: /// create a new instance static KeyValueDB *create(CephContext *cct, const std::string& type, - const std::string& dir); + const std::string& dir, + void *p = NULL); /// test whether we can successfully initialize; may have side effects (e.g., create) static int test_init(const std::string& type, const std::string& dir); diff --git a/src/kv/Makefile.am b/src/kv/Makefile.am index e5e4878b682fe..060305e421497 100644 --- a/src/kv/Makefile.am +++ b/src/kv/Makefile.am @@ -3,7 +3,7 @@ if ENABLE_SERVER libkv_a_SOURCES = \ kv/KeyValueDB.cc \ kv/LevelDBStore.cc -libkv_a_CXXFLAGS = ${AM_CXXFLAGS} -I rocksdb/include +libkv_a_CXXFLAGS = ${AM_CXXFLAGS} libkv_a_LIBADD = noinst_LIBRARIES += libkv.a @@ -18,7 +18,7 @@ if WITH_SLIBROCKSDB # PORTABLE=1 fixes the aarch64 build (-march=native doesn't work there) rocksdb/librocksdb.a: cd rocksdb && EXTRA_CXXFLAGS=-fPIC PORTABLE=1 make -j$(shell nproc) static_lib -libkv_a_CXXFLAGS += -I rocksdb/include -fPIC +libkv_a_CXXFLAGS += -I rocksdb/include -fPIC libkv_a_SOURCES += kv/RocksDBStore.cc libkv_a_LIBADD += rocksdb/librocksdb.a noinst_HEADERS += kv/RocksDBStore.h diff --git a/src/kv/RocksDBStore.cc b/src/kv/RocksDBStore.cc index abcf114e8de68..f2fde937acf69 100644 --- a/src/kv/RocksDBStore.cc +++ b/src/kv/RocksDBStore.cc @@ -152,19 +152,24 @@ int RocksDBStore::init(string _options_str) int RocksDBStore::create_and_open(ostream &out) { - int r = ::mkdir(path.c_str(), 0755); - if (r < 0) - r = -errno; - if (r < 0 && r != -EEXIST) { - derr << __func__ << " failed to create " << path << ": " << cpp_strerror(r) - << dendl; - return r; + if (env) { + unique_ptr dir; + env->NewDirectory(path, &dir); + } else { + int r = ::mkdir(path.c_str(), 0755); + if (r < 0) + r = -errno; + if (r < 0 && r != -EEXIST) { + derr << __func__ << " failed to create " << path << ": " << cpp_strerror(r) + << dendl; + return r; + } } // create tertiary paths string wal_path = path + ".wal"; struct stat st; - r = ::stat(wal_path.c_str(), &st); + int r = ::stat(wal_path.c_str(), &st); if (r < 0) r = -errno; if (r == -ENOENT) { @@ -195,6 +200,11 @@ int RocksDBStore::do_open(ostream &out, bool create_if_missing) opt.info_log.reset(new CephRocksdbLogger(g_ceph_context)); } + if (priv) { + dout(10) << __func__ << " using custom Env " << priv << dendl; + opt.env = static_cast(priv); + } + status = rocksdb::DB::Open(opt, path, &db); if (!status.ok()) { derr << status.ToString() << dendl; diff --git a/src/kv/RocksDBStore.h b/src/kv/RocksDBStore.h index 45278e068230d..a519b1c8d8fe9 100644 --- a/src/kv/RocksDBStore.h +++ b/src/kv/RocksDBStore.h @@ -38,6 +38,7 @@ enum { namespace rocksdb{ class DB; + class Env; class Cache; class FilterPolicy; class Snapshot; @@ -57,7 +58,9 @@ class RocksDBStore : public KeyValueDB { CephContext *cct; PerfCounters *logger; string path; + void *priv; rocksdb::DB *db; + rocksdb::Env *env; string options_str; int do_open(ostream &out, bool create_if_missing); @@ -108,11 +111,13 @@ public: } int get_info_log_level(string info_log_level); - RocksDBStore(CephContext *c, const string &path) : + RocksDBStore(CephContext *c, const string &path, void *p) : cct(c), logger(NULL), path(path), + priv(p), db(NULL), + env(static_cast(p)), compact_queue_lock("RocksDBStore::compact_thread_lock"), compact_queue_stop(false), compact_thread(this), diff --git a/src/test/objectstore/TestRocksdbOptionParse.cc b/src/test/objectstore/TestRocksdbOptionParse.cc index eaccfa14c65e4..727bdba7d711b 100644 --- a/src/test/objectstore/TestRocksdbOptionParse.cc +++ b/src/test/objectstore/TestRocksdbOptionParse.cc @@ -14,7 +14,7 @@ const string dir("store_test_temp_dir"); TEST(RocksDBOption, simple) { rocksdb::Options options; rocksdb::Status status; - RocksDBStore *db = new RocksDBStore(g_ceph_context, dir); + RocksDBStore *db = new RocksDBStore(g_ceph_context, dir, NULL); string options_string = "" "write_buffer_size=536870912;" "create_if_missing=true;" @@ -45,7 +45,7 @@ TEST(RocksDBOption, simple) { TEST(RocksDBOption, interpret) { rocksdb::Options options; rocksdb::Status status; - RocksDBStore *db = new RocksDBStore(g_ceph_context, dir); + RocksDBStore *db = new RocksDBStore(g_ceph_context, dir, NULL); string options_string = "compact_on_mount = true; compaction_threads=10;flusher_threads=5;"; int r = db->ParseOptionsFromString(options_string, options); -- 2.39.5