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 Jun 28, 2016
1 parent 5a8070f commit d7cecf8
Show file tree
Hide file tree
Showing 7 changed files with 806 additions and 2 deletions.
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
10 changes: 10 additions & 0 deletions src/kv/KeyValueDB.cc
Expand Up @@ -3,6 +3,7 @@

#include "KeyValueDB.h"
#include "LevelDBStore.h"
#include "MemDBStore.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 MSStore(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 MSStore::_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/MemDBStore.cc
noinst_HEADERS += kv/MemDBStore.h


endif # ENABLE_SERVER

0 comments on commit d7cecf8

Please sign in to comment.