class MonitorDBStore
{
+ string path;
boost::scoped_ptr<KeyValueDB> db;
bool do_dump;
int dump_fd_binary;
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;
}
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;
}
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);