// go
MonitorDBStore store(g_conf->mon_data);
+ assert(!store.create_and_open(cerr));
+
Monitor mon(g_ceph_context, g_conf->name.get_id(), &store, 0, &monmap);
int r = mon.mkfs(osdmapbl);
if (r < 0) {
}
MonitorDBStore store(g_conf->mon_data);
+ assert(!store.open(std::cerr));
bufferlist magicbl;
err = store.get(Monitor::MONITOR_NAME, "magic", magicbl);
db->submit_transaction_sync(dbt);
}
- MonitorDBStore(const string& path) : db(0) {
+ int open(ostream &out) {
+ return db->open(out);
+ }
+
+ int create_and_open(ostream &out) {
+ return db->create_and_open(out);
+ }
+ MonitorDBStore(const string& path) : db(0) {
string::const_reverse_iterator rit;
int pos = 0;
for (rit = path.rbegin(); rit != path.rend(); ++rit, ++pos) {
}
ostringstream os;
os << path.substr(0, path.size() - pos) << "/store.db";
-
string full_path = os.str();
LevelDBStore *db_ptr = new LevelDBStore(full_path);
if (!db_ptr) {
- cerr << __func__ << " error initializing level db back storage in "
- << full_path << std::endl;
+ std::cout << __func__ << " error initializing level db back storage in "
+ << full_path << std::endl;
assert(0 != "MonitorDBStore: error initializing level db back storage");
}
- cout << __func__ << " initializing back storage in "
- << full_path << std::endl;
- assert(!db_ptr->init(cerr));
db.reset(db_ptr);
}
MonitorDBStore(LevelDBStore *db_ptr) {
{
LevelDBStore *omap_store = new LevelDBStore(omap_dir);
stringstream err;
- if (omap_store->init(err)) {
+ if (omap_store->create_and_open(err)) {
delete omap_store;
derr << "Error initializing leveldb: " << err.str() << dendl;
ret = -1;
#include <errno.h>
using std::string;
-int LevelDBStore::init(ostream &out)
+int LevelDBStore::init(ostream &out, bool create_if_missing)
{
leveldb::Options options;
- options.create_if_missing = true;
+ options.create_if_missing = create_if_missing;
leveldb::DB *_db;
leveldb::Status status = leveldb::DB::Open(options, path, &_db);
db.reset(_db);
class LevelDBStore : public KeyValueDB {
string path;
boost::scoped_ptr<leveldb::DB> db;
+
+ int init(ostream &out, bool create_if_missing);
+
public:
LevelDBStore(const string &path) : path(path) {}
/// Opens underlying db
- int init(ostream &out);
+ int open(ostream &out) {
+ return init(out, false);
+ }
+ /// Creates underlying db if missing and opens it
+ int create_and_open(ostream &out) {
+ return init(out, true);
+ }
class LevelDBTransactionImpl : public KeyValueDB::TransactionImpl {
public:
string strpath(path);
std::cerr << "Using path: " << strpath << std::endl;
LevelDBStore *store = new LevelDBStore(strpath);
- assert(!store->init(std::cerr));
+ assert(!store->create_and_open(std::cerr));
db.reset(store);
verify(db.get());
assert(!store_path.empty());
LevelDBStore *db_ptr = new LevelDBStore(store_path);
- assert(!db_ptr->init(std::cerr));
+ assert(!db_ptr->create_and_open(std::cerr));
db.reset(db_ptr);
mock.reset(new KeyValueDBMemory());
}
cerr << "using path " << strpath << std::endl;;
LevelDBStore *store = new LevelDBStore(strpath);
- assert(!store->init(cerr));
+ assert(!store->create_and_open(cerr));
db.reset(new DBObjectMap(store));
tester.db = db.get();
if (string(args[0]) == string("new")) start_new = true;
LevelDBStore *_db = new LevelDBStore(db_path);
- assert(!_db->init(std::cerr));
+ assert(!_db->create_and_open(std::cerr));
boost::scoped_ptr<KeyValueDB> db(_db);
boost::scoped_ptr<ObjectStore> store(new FileStore(store_path, store_dev));