Commit afce7284 authored by Matthieu Dorier's avatar Matthieu Dorier
Browse files

made it possible to select among all 3 db types at run type

parent 80e21fc6
#ifndef datastore_factory_h
#define datastore_factory_h
#include "datastore.h"
#include "sds-keyval.h"
#ifdef USE_BWTREE
#include "bwtree_datastore.h"
#endif
#ifdef USE_BDB
#include "berkeleydb_datastore.h"
#endif
#ifdef USE_LEVELDB
#include "leveldb_datastore.h"
#endif
class datastore_factory {
static AbstractDataStore* create_bwtree_datastore() {
#ifdef USE_BWTREE
return new BwTreeDataStore();
#else
return nullptr;
#endif
}
static AbstractDataStore* create_berkeleydb_datastore() {
#ifdef USE_BDB
return new BerkeleyDBDataStore();
#else
return nullptr;
#endif
}
static AbstractDataStore* create_leveldb_datastore() {
#ifdef USE_LEVELDB
return new LevelDBDataStore();
#else
return nullptr;
#endif
}
public:
static AbstractDataStore* create_datastore(kv_db_type_t type)
{
switch(type) {
case KVDB_BWTREE:
return create_bwtree_datastore();
case KVDB_LEVELDB:
return create_berkeleydb_datastore();
case KVDB_BERKELEYDB:
return create_leveldb_datastore();
}
return nullptr;
};
};
#endif
......@@ -307,7 +307,9 @@ MERCURY_GEN_PROC(get_in_t, ((kv_get_in_t)(gi)))
MERCURY_GEN_PROC(get_out_t, ((kv_get_out_t)(go)))
DECLARE_MARGO_RPC_HANDLER(get_handler)
MERCURY_GEN_PROC(open_in_t, ((hg_string_t)(name)))
MERCURY_GEN_PROC(open_in_t,
((hg_string_t)(name))\
((int32_t)(db_type)))
MERCURY_GEN_PROC(open_out_t, ((hg_return_t)(ret)))
DECLARE_MARGO_RPC_HANDLER(open_handler)
......
......@@ -45,7 +45,7 @@ kv_context_t *kv_client_register(const margo_instance_id mid) {
}
kv_database_t * kv_open(kv_context_t *context,
const char *server_addr, const char *db_name)
const char *server_addr, const char *db_name, kv_db_type_t db_type)
{
hg_return_t ret = HG_SUCCESS;
hg_handle_t handle;
......@@ -64,6 +64,7 @@ kv_database_t * kv_open(kv_context_t *context,
assert(ret == HG_SUCCESS);
open_in.name = (hg_string_t)db_name;
open_in.db_type = (int32_t)db_type;
ret = margo_forward(handle, &open_in);
assert(ret == HG_SUCCESS);
......
......@@ -4,17 +4,7 @@
#include "datastore.h"
#include "kv-config.h"
#ifdef USE_BWTREE
#include "bwtree_datastore.h"
#endif
#ifdef USE_BDB
#include "berkeleydb_datastore.h"
#endif
#ifdef USE_LEVELDB
#include "leveldb_datastore.h"
#endif
#include "datastore_factory.h"
#include <mercury.h>
#include <margo.h>
......@@ -47,17 +37,18 @@ static hg_return_t open_handler(hg_handle_t handle)
ABT_mutex_lock(mutex);
if (!datastore) {
#if USE_BWTREE
datastore = new BwTreeDataStore(); // testing BwTree
#elif USE_BDB
datastore = new BerkeleyDBDataStore(); // testing BerkeleyDB
// in-memory implementation not working, needs debugging
//datastore->set_in_memory(true); // testing in-memory BerkeleyDB
#elif USE_LEVELDB
datastore = new LevelDBDataStore(); // testing LevelDB
#else
#error "No datastore backend selected at configure-time"
#endif
if(in.db_type < 0 || in.db_type > 2) {
std::cerr << "SERVER OPEN: Invalid db type" << std::endl;
out.ret = HG_OTHER_ERROR;
goto finish;
}
kv_db_type_t db_type = (kv_db_type_t)(in.db_type);
datastore = datastore_factory::create_datastore(db_type);
if(!datastore) {
std::cerr << "SERVER OPEN: Could not create database (invalid database type requested)" << std::endl;
out.ret = HG_OTHER_ERROR;
goto finish;
}
db_name = in_name;
datastore->createDatabase(db_name);
#ifdef KV_DEBUG
......@@ -82,6 +73,7 @@ static hg_return_t open_handler(hg_handle_t handle)
}
ABT_mutex_unlock(mutex);
finish:
ret = margo_respond(handle, &out);
assert(ret == HG_SUCCESS);
......
......@@ -28,7 +28,7 @@ kv_group_t *kvgroup_client_register(margo_instance_id mid, ssg_group_id_t gid)
return group;
}
hg_return_t kvgroup_open(kv_group_t *group, const char *db_name)
hg_return_t kvgroup_open(kv_group_t *group, const char *db_name, kv_db_type_t db_type)
{
hg_size_t addr_str_sz = 128;
char addr_str[addr_str_sz];
......@@ -62,7 +62,7 @@ hg_return_t kvgroup_open(kv_group_t *group, const char *db_name)
+ separator + name; // each session uses unique db name
// open client connection with this server
std::cout << "request open of " << server_dbname << " from server " << addr_str << std::endl;
group->db[i] = kv_open(group->kv_context, addr_str, server_dbname.c_str());
group->db[i] = kv_open(group->kv_context, addr_str, server_dbname.c_str(), db_type);
assert(ret == HG_SUCCESS);
}
......
#ifndef sds_keyval_h
#define sds_keyval_h
#if defined(__cplusplus)
extern "C" {
#endif
#include <margo.h>
#include <stdint.h>
typedef enum kv_db_type_t
{
KVDB_BWTREE,
KVDB_LEVELDB,
KVDB_BERKELEYDB
} kv_db_type_t;
// some setup to support simple benchmarking
typedef struct {
int64_t nkeys;
......@@ -52,7 +61,7 @@ hg_return_t kv_server_wait_for_shutdown(kv_context_t *context);
hg_return_t kv_client_signal_shutdown(kv_database_t *db);
kv_database_t * kv_open(kv_context_t *context,
const char *server, const char *db_name);
const char *server, const char *db_name, kv_db_type_t db_type);
hg_return_t kv_put(kv_database_t *db, void *key, hg_size_t ksize,
void *value, hg_size_t vsize);
hg_return_t kv_get(kv_database_t *db, void *key, hg_size_t ksize,
......
......@@ -76,8 +76,9 @@ int main(int argc, char **argv)
margo_instance_id mid = margo_init(proto, MARGO_CLIENT_MODE, 0, -1);
free(proto);
context = kv_client_register(mid);
db = kv_open(context, server_addr_str, "db/testdb");
kv_db_type_t db_type = KVDB_BWTREE; // XXX make that an argument from argv
db = kv_open(context, server_addr_str, "db/testdb", db_type);
assert(db != NULL);
RandomInsertSpeedTest(db, items, &rpc);
......
......@@ -16,7 +16,8 @@ int main(int argc, char **argv) {
kv_context_t *context = kv_client_register(mid);
/* open */
kv_database_t *db = kv_open(context, server_addr_str, "db/booger");
kv_db_type_t db_type = KVDB_BWTREE; // XXX take that from argv
kv_database_t *db = kv_open(context, server_addr_str, "db/booger", db_type);
assert(db != NULL);
/* put */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment