Skip to content

Commit

Permalink
kv: In memory keyvalue db implementation
Browse files Browse the repository at this point in the history
Signed-off-by: Ramesh Chander <Ramesh.Chander@sandisk.com>
  • Loading branch information
chhabaramesh committed Jul 13, 2016
1 parent fb3a34b commit 24a8a08
Show file tree
Hide file tree
Showing 9 changed files with 796 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/common/config_opts.h
Expand Up @@ -155,6 +155,7 @@ SUBSYS(bdev, 1, 3)
SUBSYS(kstore, 1, 5)
SUBSYS(rocksdb, 4, 5)
SUBSYS(leveldb, 4, 5)
SUBSYS(memdb, 4, 5)
SUBSYS(kinetic, 1, 5)
SUBSYS(fuse, 1, 5)

Expand Down
28 changes: 28 additions & 0 deletions src/include/encoding.h
Expand Up @@ -1018,4 +1018,32 @@ inline void decode(std::deque<T>& ls, bufferlist::iterator& p)
bl.advance(struct_end - bl.get_off()); \
}

/*
* Encoders/decoders to read from current offset in a file handle and
* encode/decode the data according to argument types.
*/
inline ssize_t decode_file(int fd, std::string &str)
{
bufferlist bl;
__u32 len = 0;
bl.read_fd(fd, sizeof(len));
decode(len, bl);
bl.read_fd(fd, len);
decode(str, bl);
return bl.length();
}

inline ssize_t decode_file(int fd, bufferptr &bp)
{
bufferlist bl;
__u32 len = 0;
bl.read_fd(fd, sizeof(len));
decode(len, bl);
bl.read_fd(fd, len);
bufferlist::iterator bli = bl.begin();

decode(bp, bli);
return bl.length();
}

#endif
1 change: 1 addition & 0 deletions src/kv/CMakeLists.txt
@@ -1,6 +1,7 @@
set(kv_srcs
KeyValueDB.cc
LevelDBStore.cc
MemDB.cc
RocksDBStore.cc)
add_library(kv_objs OBJECT ${kv_srcs})
add_library(kv STATIC $<TARGET_OBJECTS:kv_objs>)
Expand Down
10 changes: 10 additions & 0 deletions src/kv/KeyValueDB.cc
Expand Up @@ -3,6 +3,7 @@

#include "KeyValueDB.h"
#include "LevelDBStore.h"
#include "MemDB.h"
#ifdef HAVE_LIBROCKSDB
#include "RocksDBStore.h"
#endif
Expand All @@ -29,6 +30,11 @@ KeyValueDB *KeyValueDB::create(CephContext *cct, const string& type,
return new RocksDBStore(cct, dir, p);
}
#endif

if ((type == "memdb") &&
cct->check_experimental_feature_enabled("memdb")) {
return new MemDB(cct, dir, p);
}
return NULL;
}

Expand All @@ -47,5 +53,9 @@ int KeyValueDB::test_init(const string& type, const string& dir)
return RocksDBStore::_test_init(dir);
}
#endif

if (type == "memdb") {
return MemDB::_test_init(dir);
}
return -EINVAL;
}
1 change: 1 addition & 0 deletions src/kv/KeyValueDB.h
Expand Up @@ -124,6 +124,7 @@ class KeyValueDB {
virtual int init(string option_str="") = 0;
virtual int open(std::ostream &out) = 0;
virtual int create_and_open(std::ostream &out) = 0;
virtual void close() { }

virtual Transaction get_transaction() = 0;
virtual int submit_transaction(Transaction) = 0;
Expand Down
4 changes: 4 additions & 0 deletions src/kv/Makefile.am
Expand Up @@ -51,4 +51,8 @@ libkv_a_LIBADD += -lkinetic_client -lprotobuf -lglog -lgflags libcrypto.a
noinst_HEADERS += kv/KineticStore.h
endif

libkv_a_SOURCES += kv/MemDB.cc
noinst_HEADERS += kv/MemDB.h


endif # ENABLE_SERVER

0 comments on commit 24a8a08

Please sign in to comment.