|
|
4b13ad |
From 041e760440682af7640d75ed6de3365307dcb062 Mon Sep 17 00:00:00 2001
|
|
|
4b13ad |
From: xinxinsh <xinxin.shu@intel.com>
|
|
|
4b13ad |
Date: Mon, 31 Mar 2014 17:55:16 -0700
|
|
|
4b13ad |
Subject: [PATCH] os/KeyValueDB: generic create(), test_init()
|
|
|
4b13ad |
|
|
|
4b13ad |
Let us create an implemenetation by name. Include a test_init() method
|
|
|
4b13ad |
that will instantiate an instance and verify it could start up.
|
|
|
4b13ad |
|
|
|
4b13ad |
Signed-off-by: Sage Weil <sage@inktank.com>
|
|
|
4b13ad |
(cherry picked from commit 4bf929ef21b6710f60f01cb8f7095ad0a440709f)
|
|
|
4b13ad |
---
|
|
|
4b13ad |
src/os/KeyValueDB.cc | 32 ++++++++++++++++++++++++++++++++
|
|
|
4b13ad |
src/os/KeyValueDB.h | 6 ++++++
|
|
|
4b13ad |
src/os/LevelDBStore.cc | 10 ++++++++++
|
|
|
4b13ad |
src/os/LevelDBStore.h | 1 +
|
|
|
4b13ad |
src/os/Makefile.am | 1 +
|
|
|
4b13ad |
5 files changed, 50 insertions(+)
|
|
|
4b13ad |
create mode 100644 src/os/KeyValueDB.cc
|
|
|
4b13ad |
|
|
|
4b13ad |
diff --git a/src/os/KeyValueDB.cc b/src/os/KeyValueDB.cc
|
|
|
4b13ad |
new file mode 100644
|
|
|
4b13ad |
index 0000000..8e590e2
|
|
|
4b13ad |
--- /dev/null
|
|
|
4b13ad |
+++ b/src/os/KeyValueDB.cc
|
|
|
4b13ad |
@@ -0,0 +1,32 @@
|
|
|
4b13ad |
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
|
|
|
4b13ad |
+// vim: ts=8 sw=2 smarttab
|
|
|
4b13ad |
+
|
|
|
4b13ad |
+#include "KeyValueDB.h"
|
|
|
4b13ad |
+#include "LevelDBStore.h"
|
|
|
4b13ad |
+
|
|
|
4b13ad |
+KeyValueDB *KeyValueDB::create(CephContext *cct, const string& type,
|
|
|
4b13ad |
+ const string& dir)
|
|
|
4b13ad |
+{
|
|
|
4b13ad |
+ if (type == "leveldb") {
|
|
|
4b13ad |
+ return new LevelDBStore(cct, dir);
|
|
|
4b13ad |
+ }
|
|
|
4b13ad |
+#ifdef HAVE_KINETIC
|
|
|
4b13ad |
+ if (kv_type == KV_TYPE_KINETIC) {
|
|
|
4b13ad |
+ store = new KineticStore(g_ceph_context);
|
|
|
4b13ad |
+ }
|
|
|
4b13ad |
+#endif
|
|
|
4b13ad |
+ return NULL;
|
|
|
4b13ad |
+}
|
|
|
4b13ad |
+
|
|
|
4b13ad |
+int KeyValueDB::test_init(const string& type, const string& dir)
|
|
|
4b13ad |
+{
|
|
|
4b13ad |
+ if (type == "leveldb"){
|
|
|
4b13ad |
+ return LevelDBStore::_test_init(dir);
|
|
|
4b13ad |
+ }
|
|
|
4b13ad |
+#ifdef HAVE_KINETIC
|
|
|
4b13ad |
+ if (kv_type == KV_TYPE_KINETIC) {
|
|
|
4b13ad |
+ return 0;
|
|
|
4b13ad |
+ }
|
|
|
4b13ad |
+#endif
|
|
|
4b13ad |
+ return -EINVAL;
|
|
|
4b13ad |
+}
|
|
|
4b13ad |
diff --git a/src/os/KeyValueDB.h b/src/os/KeyValueDB.h
|
|
|
4b13ad |
index c581aa5..f8e0b68 100644
|
|
|
4b13ad |
--- a/src/os/KeyValueDB.h
|
|
|
4b13ad |
+++ b/src/os/KeyValueDB.h
|
|
|
4b13ad |
@@ -64,6 +64,12 @@ public:
|
|
|
4b13ad |
};
|
|
|
4b13ad |
typedef ceph::shared_ptr< TransactionImpl > Transaction;
|
|
|
4b13ad |
|
|
|
4b13ad |
+ /// create a new instance
|
|
|
4b13ad |
+ static KeyValueDB *create(CephContext *cct, const string& type,
|
|
|
4b13ad |
+ const string& dir);
|
|
|
4b13ad |
+
|
|
|
4b13ad |
+ /// test whether we can successfully initialize; may have side effects (e.g., create)
|
|
|
4b13ad |
+ static int test_init(const string& type, const string& dir);
|
|
|
4b13ad |
virtual int init() = 0;
|
|
|
4b13ad |
virtual int open(ostream &out) = 0;
|
|
|
4b13ad |
virtual int create_and_open(ostream &out) = 0;
|
|
|
4b13ad |
diff --git a/src/os/LevelDBStore.cc b/src/os/LevelDBStore.cc
|
|
|
4b13ad |
index 326862f..818396a 100644
|
|
|
4b13ad |
--- a/src/os/LevelDBStore.cc
|
|
|
4b13ad |
+++ b/src/os/LevelDBStore.cc
|
|
|
4b13ad |
@@ -92,6 +92,16 @@ int LevelDBStore::do_open(ostream &out, bool create_if_missing)
|
|
|
4b13ad |
return 0;
|
|
|
4b13ad |
}
|
|
|
4b13ad |
|
|
|
4b13ad |
+int LevelDBStore::_test_init(const string& dir)
|
|
|
4b13ad |
+{
|
|
|
4b13ad |
+ leveldb::Options options;
|
|
|
4b13ad |
+ options.create_if_missing = true;
|
|
|
4b13ad |
+ leveldb::DB *db;
|
|
|
4b13ad |
+ leveldb::Status status = leveldb::DB::Open(options, dir, &db);
|
|
|
4b13ad |
+ delete db;
|
|
|
4b13ad |
+ return status.ok() ? 0 : -EIO;
|
|
|
4b13ad |
+}
|
|
|
4b13ad |
+
|
|
|
4b13ad |
LevelDBStore::~LevelDBStore()
|
|
|
4b13ad |
{
|
|
|
4b13ad |
close();
|
|
|
4b13ad |
diff --git a/src/os/LevelDBStore.h b/src/os/LevelDBStore.h
|
|
|
4b13ad |
index 26e7bbe..1c072da 100644
|
|
|
4b13ad |
--- a/src/os/LevelDBStore.h
|
|
|
4b13ad |
+++ b/src/os/LevelDBStore.h
|
|
|
4b13ad |
@@ -154,6 +154,7 @@ public:
|
|
|
4b13ad |
|
|
|
4b13ad |
~LevelDBStore();
|
|
|
4b13ad |
|
|
|
4b13ad |
+ static int _test_init(const string& dir);
|
|
|
4b13ad |
int init();
|
|
|
4b13ad |
|
|
|
4b13ad |
/// Opens underlying db
|
|
|
4b13ad |
diff --git a/src/os/Makefile.am b/src/os/Makefile.am
|
|
|
4b13ad |
index 39bbdb2..f2303fb 100644
|
|
|
4b13ad |
--- a/src/os/Makefile.am
|
|
|
4b13ad |
+++ b/src/os/Makefile.am
|
|
|
4b13ad |
@@ -18,6 +18,7 @@ libos_la_SOURCES = \
|
|
|
4b13ad |
os/LevelDBStore.cc \
|
|
|
4b13ad |
os/LFNIndex.cc \
|
|
|
4b13ad |
os/MemStore.cc \
|
|
|
4b13ad |
+ os/KeyValueDB.cc \
|
|
|
4b13ad |
os/KeyValueStore.cc \
|
|
|
4b13ad |
os/ObjectStore.cc \
|
|
|
4b13ad |
os/WBThrottle.cc \
|
|
|
4b13ad |
--
|
|
|
4b13ad |
1.9.3
|
|
|
4b13ad |
|