From: xinxinsh Date: Tue, 1 Apr 2014 00:55:16 +0000 (-0700) Subject: os/KeyValueDB: generic create(), test_init() X-Git-Tag: v0.85~125^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=4bf929ef21b6710f60f01cb8f7095ad0a440709f;p=ceph.git os/KeyValueDB: generic create(), test_init() Let us create an implemenetation by name. Include a test_init() method that will instantiate an instance and verify it could start up. Signed-off-by: Sage Weil --- diff --git a/src/os/KeyValueDB.cc b/src/os/KeyValueDB.cc new file mode 100644 index 0000000000000..8e590e2a31e8b --- /dev/null +++ b/src/os/KeyValueDB.cc @@ -0,0 +1,32 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab + +#include "KeyValueDB.h" +#include "LevelDBStore.h" + +KeyValueDB *KeyValueDB::create(CephContext *cct, const string& type, + const string& dir) +{ + if (type == "leveldb") { + return new LevelDBStore(cct, dir); + } +#ifdef HAVE_KINETIC + if (kv_type == KV_TYPE_KINETIC) { + store = new KineticStore(g_ceph_context); + } +#endif + return NULL; +} + +int KeyValueDB::test_init(const string& type, const string& dir) +{ + if (type == "leveldb"){ + return LevelDBStore::_test_init(dir); + } +#ifdef HAVE_KINETIC + if (kv_type == KV_TYPE_KINETIC) { + return 0; + } +#endif + return -EINVAL; +} diff --git a/src/os/KeyValueDB.h b/src/os/KeyValueDB.h index 84253418483ab..a1255083cd0f1 100644 --- a/src/os/KeyValueDB.h +++ b/src/os/KeyValueDB.h @@ -64,6 +64,12 @@ public: }; typedef ceph::shared_ptr< TransactionImpl > Transaction; + /// create a new instance + static KeyValueDB *create(CephContext *cct, const string& type, + const string& dir); + + /// test whether we can successfully initialize; may have side effects (e.g., create) + static int test_init(const string& type, const string& dir); virtual int init() = 0; virtual int open(ostream &out) = 0; virtual int create_and_open(ostream &out) = 0; diff --git a/src/os/LevelDBStore.cc b/src/os/LevelDBStore.cc index 326862f896a15..818396a9558ca 100644 --- a/src/os/LevelDBStore.cc +++ b/src/os/LevelDBStore.cc @@ -92,6 +92,16 @@ int LevelDBStore::do_open(ostream &out, bool create_if_missing) return 0; } +int LevelDBStore::_test_init(const string& dir) +{ + leveldb::Options options; + options.create_if_missing = true; + leveldb::DB *db; + leveldb::Status status = leveldb::DB::Open(options, dir, &db); + delete db; + return status.ok() ? 0 : -EIO; +} + LevelDBStore::~LevelDBStore() { close(); diff --git a/src/os/LevelDBStore.h b/src/os/LevelDBStore.h index 26e7bbe7c12ea..1c072daa43b2f 100644 --- a/src/os/LevelDBStore.h +++ b/src/os/LevelDBStore.h @@ -154,6 +154,7 @@ public: ~LevelDBStore(); + static int _test_init(const string& dir); int init(); /// Opens underlying db diff --git a/src/os/Makefile.am b/src/os/Makefile.am index cfe06c5c70631..07b0e6f0ecf2b 100644 --- a/src/os/Makefile.am +++ b/src/os/Makefile.am @@ -17,6 +17,7 @@ libos_la_SOURCES = \ os/LevelDBStore.cc \ os/LFNIndex.cc \ os/MemStore.cc \ + os/KeyValueDB.cc \ os/KeyValueStore.cc \ os/ObjectStore.cc \ os/WBThrottle.cc \