From: Sage Weil Date: Mon, 2 May 2016 19:48:53 +0000 (-0400) Subject: mon/MonitorDBStore: move backend instantiation out of ctor X-Git-Tag: v11.0.0~136^2~10^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=3f62c8463a1b45aa52fa4c015819901e0c13f2d4;p=ceph.git mon/MonitorDBStore: move backend instantiation out of ctor Signed-off-by: Sage Weil --- diff --git a/src/mon/MonitorDBStore.h b/src/mon/MonitorDBStore.h index a935d1f9aed..73e91c6336b 100644 --- a/src/mon/MonitorDBStore.h +++ b/src/mon/MonitorDBStore.h @@ -31,6 +31,7 @@ class MonitorDBStore { + string path; boost::scoped_ptr 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);