]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mon/MonitorDBStore: move backend instantiation out of ctor
authorSage Weil <sage@redhat.com>
Mon, 2 May 2016 19:48:53 +0000 (15:48 -0400)
committerSage Weil <sage@redhat.com>
Tue, 3 May 2016 12:51:12 +0000 (08:51 -0400)
Signed-off-by: Sage Weil <sage@redhat.com>
src/mon/MonitorDBStore.h

index a935d1f9aede4577b6f976b39b946f4026edd78e..73e91c6336b88ac84763de4546eec0b74a1dd378 100644 (file)
@@ -31,6 +31,7 @@
 
 class MonitorDBStore
 {
+  string path;
   boost::scoped_ptr<KeyValueDB> db;
   bool do_dump;
   int dump_fd_binary;
@@ -577,11 +578,53 @@ class MonitorDBStore
     assert(r >= 0);
   }
 
-  int open(ostream &out) {
+  void _open() {
+    string::const_reverse_iterator rit;
+    int pos = 0;
+    for (rit = path.rbegin(); rit != path.rend(); ++rit, ++pos) {
+      if (*rit != '/')
+       break;
+    }
+    ostringstream os;
+    os << path.substr(0, path.size() - pos) << "/store.db";
+    string full_path = os.str();
+
+    KeyValueDB *db_ptr = KeyValueDB::create(g_ceph_context,
+                                           g_conf->mon_keyvaluedb,
+                                           full_path);
+    if (!db_ptr) {
+      derr << __func__ << " error initializing "
+          << g_conf->mon_keyvaluedb << " db back storage in "
+          << full_path << dendl;
+      assert(0 != "MonitorDBStore: error initializing keyvaluedb back storage");
+    }
+    db.reset(db_ptr);
+
+    if (g_conf->mon_debug_dump_transactions) {
+      if (!g_conf->mon_debug_dump_json) {
+        dump_fd_binary = ::open(
+          g_conf->mon_debug_dump_location.c_str(),
+          O_CREAT|O_APPEND|O_WRONLY, 0644);
+        if (dump_fd_binary < 0) {
+          dump_fd_binary = -errno;
+          derr << "Could not open log file, got "
+               << cpp_strerror(dump_fd_binary) << dendl;
+        }
+      } else {
+        dump_fmt.reset();
+        dump_fmt.open_array_section("dump");
+        dump_fd_json.open(g_conf->mon_debug_dump_location.c_str());
+      }
+      do_dump = true;
+    }
     if (g_conf->mon_keyvaluedb == "rocksdb")
       db->init(g_conf->mon_rocksdb_options);
     else
       db->init();
+  }
+
+  int open(ostream &out) {
+    _open();
     int r = db->open(out);
     if (r < 0)
       return r;
@@ -591,10 +634,7 @@ class MonitorDBStore
   }
 
   int create_and_open(ostream &out) {
-    if (g_conf->mon_keyvaluedb == "rocksdb")
-      db->init(g_conf->mon_rocksdb_options);
-    else
-      db->init();
+    _open();
     int r = db->create_and_open(out);
     if (r < 0)
       return r;
@@ -622,50 +662,13 @@ class MonitorDBStore
   }
 
   explicit MonitorDBStore(const string& path)
-    : db(0),
+    : path(path),
+      db(0),
       do_dump(false),
       dump_fd_binary(-1),
       dump_fmt(true),
       io_work(g_ceph_context, "monstore", "fn_monstore"),
       is_open(false) {
-    string::const_reverse_iterator rit;
-    int pos = 0;
-    for (rit = path.rbegin(); rit != path.rend(); ++rit, ++pos) {
-      if (*rit != '/')
-       break;
-    }
-    ostringstream os;
-    os << path.substr(0, path.size() - pos) << "/store.db";
-    string full_path = os.str();
-
-    KeyValueDB *db_ptr = KeyValueDB::create(g_ceph_context,
-                                           g_conf->mon_keyvaluedb,
-                                           full_path);
-    if (!db_ptr) {
-      derr << __func__ << " error initializing "
-          << g_conf->mon_keyvaluedb << " db back storage in "
-          << full_path << dendl;
-      assert(0 != "MonitorDBStore: error initializing keyvaluedb back storage");
-    }
-    db.reset(db_ptr);
-
-    if (g_conf->mon_debug_dump_transactions) {
-      if (!g_conf->mon_debug_dump_json) {
-        dump_fd_binary = ::open(
-          g_conf->mon_debug_dump_location.c_str(),
-          O_CREAT|O_APPEND|O_WRONLY, 0644);
-        if (dump_fd_binary < 0) {
-          dump_fd_binary = -errno;
-          derr << "Could not open log file, got "
-               << cpp_strerror(dump_fd_binary) << dendl;
-        }
-      } else {
-        dump_fmt.reset();
-        dump_fmt.open_array_section("dump");
-        dump_fd_json.open(g_conf->mon_debug_dump_location.c_str());
-      }
-      do_dump = true;
-    }
   }
   ~MonitorDBStore() {
     assert(!is_open);