]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
os/KeyValueDB: generic create(), test_init()
authorxinxinsh <xinxin.shu@intel.com>
Tue, 1 Apr 2014 00:55:16 +0000 (17:55 -0700)
committerSage Weil <sage@redhat.com>
Wed, 30 Jul 2014 04:28:30 +0000 (21:28 -0700)
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 <sage@inktank.com>
src/os/KeyValueDB.cc [new file with mode: 0644]
src/os/KeyValueDB.h
src/os/LevelDBStore.cc
src/os/LevelDBStore.h
src/os/Makefile.am

diff --git a/src/os/KeyValueDB.cc b/src/os/KeyValueDB.cc
new file mode 100644 (file)
index 0000000..8e590e2
--- /dev/null
@@ -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;
+}
index 84253418483abbc4b8d4bc08a8d1d1cba85ba5c2..a1255083cd0f136b057c3a53a35b111682d5fdf8 100644 (file)
@@ -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;
index 326862f896a15ad4ef3dc2da9bfd2d0d33510da5..818396a9558ca77efdcc937b336f4a43debd9215 100644 (file)
@@ -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();
index 26e7bbe7c12ea89d36db8ae1b4238b7afbd24efe..1c072daa43b2f7cf697ec1aecc36c32203cec199 100644 (file)
@@ -154,6 +154,7 @@ public:
 
   ~LevelDBStore();
 
+  static int _test_init(const string& dir);
   int init();
 
   /// Opens underlying db
index cfe06c5c706311ff7f0f5f982f5a95cdcc44ece3..07b0e6f0ecf2b6736afdaa469deca6377de46cbf 100644 (file)
@@ -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 \