Commit 867f543d authored by Matthieu Dorier's avatar Matthieu Dorier

refactoring complete

parent b057e75e
......@@ -17,7 +17,11 @@ test_bench_client_LDADD = ${LIBS} -lkvclient
lib_LTLIBRARIES = lib/libkvclient.la \
lib/libkvserver.la \
lib/libkvgroupclient.la \
lib/libkvgroupserver.la
lib/libkvgroupserver.la \
lib/libsdskv-client.la \
lib/libsdskv-server.la
lib_libsdskv_client_la_SOURCES = src/sdskv-client.c
lib_libkvclient_la_SOURCES = src/kv-client.c
......@@ -26,17 +30,27 @@ lib_libkvgroupclient_la_SOURCES = src/kvgroup-client.cc
lib_libkvserver_la_SOURCES = src/kv-server.cc \
src/datastore/datastore.cc
lib_libsdskv_server_la_SOURCES = src/sdskv-server.cc \
src/datastore/datastore.cc
if BUILD_BWTREE
lib_libkvserver_la_SOURCES += src/BwTree/src/bwtree.cpp \
src/datastore/bwtree_datastore.cc
lib_libsdskv_server_la_SOURCES += src/BwTree/src/bwtree.cpp \
src/datastore/bwtree_datastore.cc
endif
if BUILD_BDB
lib_libkvserver_la_SOURCES += src/datastore/berkeleydb_datastore.cc
lib_libsdskv_server_la_SOURCES += src/datastore/berkeleydb_datastore.cc
endif
if BUILD_LEVELDB
lib_libkvserver_la_SOURCES += src/datastore/leveldb_datastore.cc
lib_libsdskv_server_la_SOURCES += src/datastore/leveldb_datastore.cc
endif
......
......@@ -5,7 +5,6 @@
#include "kv-config.h"
#include "bulk.h"
#include "sds-keyval.h"
#include <boost/functional/hash.hpp>
#include <vector>
......
#ifndef datastore_factory_h
#define datastore_factory_h
#include "datastore.h"
#ifdef SDSKV
#include "sdskv-common.h"
#else
#include "sds-keyval.h"
#endif
#include "datastore.h"
#ifdef USE_BWTREE
#include "bwtree_datastore.h"
......@@ -44,7 +48,11 @@ class datastore_factory {
public:
#ifdef SDSKV
static AbstractDataStore* create_datastore(sdskv_db_type_t type)
#else
static AbstractDataStore* create_datastore(kv_db_type_t type)
#endif
{
switch(type) {
case KVDB_BWTREE:
......
......@@ -536,7 +536,7 @@ static hg_return_t bench_handler(hg_handle_t handle)
}
DEFINE_MARGO_RPC_HANDLER(bench_handler)
kv_context_t *kv_server_register(const margo_instance_id mid)
extern "C" kv_context_t *kv_server_register(const margo_instance_id mid)
{
hg_return_t ret;
hg_addr_t addr_self;
......@@ -601,13 +601,13 @@ kv_context_t *kv_server_register(const margo_instance_id mid)
return context;
}
hg_return_t kv_server_wait_for_shutdown(kv_context_t *context) {
extern "C" hg_return_t kv_server_wait_for_shutdown(kv_context_t *context) {
margo_wait_for_finalize(context->mid);
return HG_SUCCESS;
}
/* this is the same as client. should be moved to common utility library */
hg_return_t kv_server_deregister(kv_context_t *context) {
extern "C" hg_return_t kv_server_deregister(kv_context_t *context) {
free(context);
delete datastore;
std::cout << "SERVER: cleanup complete, deregistered" << std::endl;
......
......@@ -11,7 +11,7 @@
unsigned long server_indexes[CH_MAX_REPLICATION];
kv_group_t *kvgroup_client_register(margo_instance_id mid, ssg_group_id_t gid)
extern "C" kv_group_t *kvgroup_client_register(margo_instance_id mid, ssg_group_id_t gid)
{
kv_group_t *group = (kv_group_t*)calloc(1, sizeof(group));
......@@ -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, kv_db_type_t db_type)
extern "C" 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];
......@@ -74,7 +74,7 @@ hg_return_t kvgroup_open(kv_group_t *group, const char *db_name, kv_db_type_t db
// oid is unique associated with key
// in ParSplice key is already a uint64_t hashed value
hg_return_t kvgroup_put(kv_group_t * group, uint64_t oid,
extern "C" hg_return_t kvgroup_put(kv_group_t * group, uint64_t oid,
void *key, hg_size_t ksize,
void *value, hg_size_t vsize)
{
......@@ -89,7 +89,7 @@ hg_return_t kvgroup_put(kv_group_t * group, uint64_t oid,
// oid is unique associated with key
// in ParSplice key is already a uint64_t hashed value
// vsize is in/out
hg_return_t kvgroup_get(kv_group_t *group, uint64_t oid,
extern "C" hg_return_t kvgroup_get(kv_group_t *group, uint64_t oid,
void *key, hg_size_t ksize,
void *value, hg_size_t *vsize)
{
......@@ -100,7 +100,7 @@ hg_return_t kvgroup_get(kv_group_t *group, uint64_t oid,
return kv_get(group->db[server_indexes[0]], key, ksize, value, vsize);
}
hg_return_t kvgroup_close(kv_group_t * group)
extern "C" hg_return_t kvgroup_close(kv_group_t * group)
{
hg_return_t ret;
for (hg_size_t i=0; i<group->gsize; i++) {
......@@ -110,7 +110,7 @@ hg_return_t kvgroup_close(kv_group_t * group)
return HG_SUCCESS;
}
hg_return_t kvgroup_client_deregister(kv_group_t * group)
extern "C" hg_return_t kvgroup_client_deregister(kv_group_t * group)
{
hg_return_t ret;
ret = kv_client_deregister(group->kv_context);
......@@ -127,7 +127,7 @@ hg_return_t kvgroup_client_deregister(kv_group_t * group)
}
// only one client calls shutdown
hg_return_t kvgroup_client_signal_shutdown(kv_group_t *group)
extern "C" hg_return_t kvgroup_client_signal_shutdown(kv_group_t *group)
{
hg_return_t ret;
for (hg_size_t i=0; i<group->gsize; i++) {
......@@ -140,7 +140,7 @@ hg_return_t kvgroup_client_signal_shutdown(kv_group_t *group)
// collective along with kvgroup_server_send_gid
// single server rank calls send, all client ranks call recv
// gid is an output argument
void kvgroup_client_recv_gid(ssg_group_id_t *gid, MPI_Comm comm)
extern "C" void kvgroup_client_recv_gid(ssg_group_id_t *gid, MPI_Comm comm)
{
char *serialized_gid = NULL;
size_t gid_size = 0;
......
......@@ -19,7 +19,7 @@ static void group_update_cb(ssg_membership_update_t update, void *cb_dat)
}
/* this is a collective operation */
kv_group_t *kvgroup_server_register(margo_instance_id mid,
extern "C" kv_group_t *kvgroup_server_register(margo_instance_id mid,
const char *ssg_name, MPI_Comm ssg_comm)
{
kv_group_t * group = (kv_group_t *)calloc(1, sizeof(kv_group_t));
......@@ -45,7 +45,7 @@ kv_group_t *kvgroup_server_register(margo_instance_id mid,
return group;
}
hg_return_t kvgroup_server_deregister(kv_group_t *group)
extern "C" hg_return_t kvgroup_server_deregister(kv_group_t *group)
{
hg_return_t ret = kv_server_deregister(group->kv_context);
ssg_group_destroy(group->gid);
......@@ -55,7 +55,7 @@ hg_return_t kvgroup_server_deregister(kv_group_t *group)
return ret;
}
hg_return_t kvgroup_server_wait_for_shutdown(kv_group_t *group)
extern "C" hg_return_t kvgroup_server_wait_for_shutdown(kv_group_t *group)
{
hg_return_t ret = kv_server_wait_for_shutdown(group->kv_context);
return ret;
......@@ -64,7 +64,7 @@ hg_return_t kvgroup_server_wait_for_shutdown(kv_group_t *group)
// collective along with kvgroup_client_recv_gid
// single server rank calls send, all client ranks call recv
// gid is an input argument
void kvgroup_server_send_gid(ssg_group_id_t gid, MPI_Comm comm)
extern "C" void kvgroup_server_send_gid(ssg_group_id_t gid, MPI_Comm comm)
{
char *serialized_gid = NULL;
size_t gid_size = 0;
......
......@@ -54,7 +54,7 @@ hg_return_t kvgroup_server_deregister(kv_group_t *group);
hg_return_t kvgroup_server_wait_for_shutdown(kv_group_t *group);
kv_group_t *kvgroup_client_register(margo_instance_id mid, ssg_group_id_t gid);
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_return_t kvgroup_put(kv_group_t *group, uint64_t oid,
void *key, hg_size_t ksize,
void *value, hg_size_t vsize);
......
This diff is collapsed.
#ifndef sds_keyval_client_h
#define sds_keyval_client_h
#include <margo.h>
#include <stdint.h>
#include <sdskv-common.h>
#if defined(__cplusplus)
extern "C" {
#endif
typedef struct sdskv_client* sdskv_client_t;
#define SDSKV_CLIENT_NULL ((sdskv_client_t)NULL)
typedef struct sdskv_provider_handle *sdskv_provider_handle_t;
#define SDSKV_PROVIDER_HANDLE_NULL ((sdskv_provider_handle_t)NULL)
int sdskv_client_init(margo_instance_id mid, sdskv_client_t* client);
int sdskv_client_finalize(sdskv_client_t client);
int sdskv_provider_handle_create(
sdskv_client_t client,
hg_addr_t addr,
uint8_t mplex_id,
sdskv_provider_handle_t* handle);
int sdskv_provider_handle_ref_incr(
sdskv_provider_handle_t handle);
int sdskv_provider_release(sdskv_provider_handle_t handle);
int sdskv_open(
sdskv_provider_handle_t provider,
const char* db_name,
sdskv_database_id_t* db_id);
int sdskv_put(sdskv_provider_handle_t provider,
sdskv_database_id_t db_id,
const void *key, hg_size_t ksize,
const void *value, hg_size_t vsize);
int sdskv_get(sdskv_provider_handle_t provider,
sdskv_database_id_t db_id,
const void *key, hg_size_t ksize,
void *value, hg_size_t* vsize);
int sdskv_length(sdskv_provider_handle_t db,
sdskv_database_id_t db_id, const void *key,
hg_size_t ksize, hg_size_t* vsize);
int sdskv_list_keys(sdskv_provider_handle_t provider,
sdskv_database_id_t db_id, // db instance
const void *start_key, // we want keys strictly after this start_key
hg_size_t start_ksize, // size of the start_key
void **keys, // pointer to an array of void* pointers,
// this array has size *max_keys
hg_size_t* ksizes, // pointer to an array of hg_size_t sizes
// representing sizes allocated in
// keys for each key
hg_size_t* max_keys); // maximum number of keys requested
int sdskv_list_keys_with_prefix(sdskv_provider_handle_t provider,
sdskv_database_id_t db_id, // db instance
const void *start_key, // we want keys strictly after this start_key
hg_size_t start_ksize, // size of the start_key
const void *prefix, // return only keys that begin with 'prefix'
hg_size_t prefix_size,
void **keys, // pointer to an array of void* pointers,
// this array has size *max_keys
hg_size_t* ksizes, // pointer to an array of hg_size_t sizes
// representing sizes allocated in
// keys for each key
hg_size_t* max_keys); // maximum number of keys requested
#if defined(__cplusplus)
}
#endif
#endif
#ifndef SDSKV_COMMON_H
#define SDSKV_COMMON_H
#if defined(__cplusplus)
extern "C" {
#endif
typedef enum sdskv_db_type_t
{
KVDB_BWTREE,
KVDB_LEVELDB,
KVDB_BERKELEYDB
} sdskv_db_type_t;
typedef uint64_t sdskv_database_id_t;
#define SDSKV_DATABASE_ID_INVALID 0
#define SDSKV_SUCCESS 0
#define SDSKV_ERROR -1
#if defined(__cplusplus)
}
#endif
#endif
#ifndef SDSKV_RPC_TYPE_H
#define SDSKV_RPC_TYPE_H
#include <stdint.h>
#include <assert.h>
#include <mercury.h>
#include <mercury_macros.h>
#include <mercury_proc_string.h>
#include <margo.h>
#include "sdskv-common.h"
// setup to support opaque type handling
typedef char* kv_data_t;
typedef struct {
uint64_t db_id;
kv_data_t key;
hg_size_t ksize;
kv_data_t value;
hg_size_t vsize;
} put_in_t;
typedef struct {
uint64_t db_id;
kv_data_t key;
hg_size_t ksize;
hg_size_t vsize;
} get_in_t;
typedef struct {
kv_data_t value;
hg_size_t vsize;
int32_t ret;
} get_out_t;
typedef struct {
uint64_t db_id;
kv_data_t key;
hg_size_t ksize;
} length_in_t;
static inline hg_return_t hg_proc_put_in_t(hg_proc_t proc, void *data)
{
hg_return_t ret;
put_in_t *in = (put_in_t*)data;
ret = hg_proc_uint64_t(proc, &in->db_id);
if(ret != HG_SUCCESS) return ret;
ret = hg_proc_hg_size_t(proc, &in->ksize);
if(ret != HG_SUCCESS) return ret;
if (in->ksize) {
switch (hg_proc_get_op(proc)) {
case HG_ENCODE:
ret = hg_proc_raw(proc, in->key, in->ksize);
if(ret != HG_SUCCESS) return ret;
break;
case HG_DECODE:
in->key = (kv_data_t)malloc(in->ksize);
ret = hg_proc_raw(proc, in->key, in->ksize);
if(ret != HG_SUCCESS) return ret;
break;
case HG_FREE:
free(in->key);
break;
default:
break;
}
}
ret = hg_proc_hg_size_t(proc, &in->vsize);
if(ret != HG_SUCCESS) return ret;
if (in->vsize) {
switch (hg_proc_get_op(proc)) {
case HG_ENCODE:
ret = hg_proc_raw(proc, in->value, in->vsize);
if(ret != HG_SUCCESS) return ret;
break;
case HG_DECODE:
in->value = (kv_data_t)malloc(in->vsize);
ret = hg_proc_raw(proc, in->value, in->vsize);
if(ret != HG_SUCCESS) return ret;
break;
case HG_FREE:
free(in->value);
break;
default:
break;
}
}
return HG_SUCCESS;
}
static inline hg_return_t hg_proc_length_in_t(hg_proc_t proc, void *data)
{
hg_return_t ret;
length_in_t *in = (length_in_t*)data;
ret = hg_proc_uint64_t(proc, &in->db_id);
if(ret != HG_SUCCESS) return ret;
ret = hg_proc_hg_size_t(proc, &in->ksize);
if(ret != HG_SUCCESS) return ret;
if (in->ksize) {
switch (hg_proc_get_op(proc)) {
case HG_ENCODE:
ret = hg_proc_raw(proc, in->key, in->ksize);
if(ret != HG_SUCCESS) return ret;
break;
case HG_DECODE:
in->key = (kv_data_t)malloc(in->ksize);
ret = hg_proc_raw(proc, in->key, in->ksize);
if(ret != HG_SUCCESS) return ret;
break;
case HG_FREE:
free(in->key);
break;
default:
break;
}
}
return HG_SUCCESS;
}
static inline hg_return_t hg_proc_get_in_t(hg_proc_t proc, void *data)
{
hg_return_t ret;
get_in_t *in = (get_in_t*)data;
ret = hg_proc_uint64_t(proc, &in->db_id);
if(ret != HG_SUCCESS) return ret;
ret = hg_proc_hg_size_t(proc, &in->ksize);
if(ret != HG_SUCCESS) return ret;
if (in->ksize) {
switch (hg_proc_get_op(proc)) {
case HG_ENCODE:
ret = hg_proc_raw(proc, in->key, in->ksize);
if(ret != HG_SUCCESS) return ret;
break;
case HG_DECODE:
in->key = (kv_data_t)malloc(in->ksize);
ret = hg_proc_raw(proc, in->key, in->ksize);
if(ret != HG_SUCCESS) return ret;
break;
case HG_FREE:
free(in->key);
break;
default:
break;
}
}
ret = hg_proc_hg_size_t(proc, &in->vsize);
if(ret != HG_SUCCESS) return ret;
return HG_SUCCESS;
}
static inline hg_return_t hg_proc_get_out_t(hg_proc_t proc, void *data)
{
hg_return_t ret;
get_out_t *out = (get_out_t*)data;
ret = hg_proc_hg_size_t(proc, &out->vsize);
if(ret != HG_SUCCESS) return ret;
if (out->vsize) {
switch (hg_proc_get_op(proc)) {
case HG_ENCODE:
ret = hg_proc_raw(proc, out->value, out->vsize);
if(ret != HG_SUCCESS) return ret;
break;
case HG_DECODE:
out->value = (kv_data_t)malloc(out->vsize);
ret = hg_proc_raw(proc, out->value, out->vsize);
if(ret != HG_SUCCESS) return ret;
break;
case HG_FREE:
free(out->value);
break;
default:
break;
}
}
ret = hg_proc_int32_t(proc, &out->ret);
if(ret != HG_SUCCESS) return ret;
return HG_SUCCESS;
}
typedef struct {
uint64_t db_id;
kv_data_t start_key;
hg_size_t start_ksize;
hg_size_t max_keys;
} list_in_t;
typedef struct {
hg_size_t nkeys;
kv_data_t *keys;
hg_size_t *ksizes;
int32_t ret;
} list_out_t;
static inline hg_return_t hg_proc_list_in_t(hg_proc_t proc, void *data)
{
hg_return_t ret;
list_in_t *in = (list_in_t*)data;
ret = hg_proc_uint64_t(proc, &in->db_id);
if(ret != HG_SUCCESS) return ret;
ret = hg_proc_hg_size_t(proc, &in->start_ksize);
if(ret != HG_SUCCESS) return ret;
if (in->start_ksize) {
switch(hg_proc_get_op(proc)) {
case HG_ENCODE:
ret = hg_proc_raw(proc, in->start_key, in->start_ksize);
if(ret != HG_SUCCESS) return ret;
break;
case HG_DECODE:
in->start_key = (kv_data_t)malloc(in->start_ksize);
ret = hg_proc_raw(proc, in->start_key, in->start_ksize);
if(ret != HG_SUCCESS) return ret;
break;
case HG_FREE:
free(in->start_key);
default:
break;
}
}
ret = hg_proc_hg_size_t(proc, &in->max_keys);
return ret;
}
static inline hg_return_t hg_proc_list_out_t(hg_proc_t proc, void *data)
{
hg_return_t ret;
unsigned int i;
list_out_t *out = (list_out_t*)data;
ret = hg_proc_hg_size_t(proc, &out->nkeys);
if(ret != HG_SUCCESS) return ret;
if (out->nkeys) {
switch(hg_proc_get_op(proc)) {
case HG_ENCODE:
for (i=0; i<out->nkeys; i++) {
ret = hg_proc_raw(proc, &(out->ksizes[i]),
sizeof(*(out->ksizes)) );
}
for (i=0; i<out->nkeys; i++) {
ret = hg_proc_raw(proc, out->keys[i], out->ksizes[i]);
if(ret != HG_SUCCESS) return ret;
}
break;
case HG_DECODE:
out->ksizes =
(hg_size_t*)malloc(out->nkeys*sizeof(*out->ksizes));
for (i=0; i<out->nkeys; i++) {
ret = hg_proc_raw(proc, &(out->ksizes[i]),
sizeof(*out->ksizes));
}
out->keys = (kv_data_t *)malloc(out->nkeys*sizeof(kv_data_t));
for (i=0; i<out->nkeys; i++) {
out->keys[i] = (kv_data_t)malloc(out->ksizes[i]);
ret = hg_proc_raw(proc, out->keys[i], out->ksizes[i]);
if(ret != HG_SUCCESS) return ret;
}
break;
case HG_FREE:
for (i=0; i<out->nkeys; i++) {
free(out->keys[i]);
}
free(out->keys);
free(out->ksizes);
break;
default:
break;
}
}
ret = hg_proc_int32_t(proc, &out->ret);
return ret;
}
MERCURY_GEN_PROC(put_out_t, ((int32_t)(ret)))
MERCURY_GEN_PROC(length_out_t, ((hg_size_t)(size)) ((int32_t)(ret)))
MERCURY_GEN_PROC(open_in_t,
((hg_string_t)(name)))
MERCURY_GEN_PROC(open_out_t, ((uint64_t)(db_id)) ((int32_t)(ret)))
// for handling bulk puts/gets (e.g. for ParSplice use case)
typedef struct {
uint64_t db_id;
kv_data_t key;
hg_size_t ksize;
hg_size_t vsize;
hg_bulk_t handle;
} kv_bulk_t;
static inline hg_return_t hg_proc_kv_bulk_t(hg_proc_t proc, void *data)
{
hg_return_t ret;
kv_bulk_t *bulk = (kv_bulk_t*)data;
ret = hg_proc_uint64_t(proc, &bulk->db_id);
if(ret != HG_SUCCESS) return ret;
ret = hg_proc_hg_size_t(proc, &bulk->ksize);
if(ret != HG_SUCCESS) return ret;
if (bulk->ksize) {
switch (hg_proc_get_op(proc)) {
case HG_ENCODE:
ret = hg_proc_raw(proc, bulk->key, bulk->ksize);
if(ret != HG_SUCCESS) return ret;
break;
case HG_DECODE:
bulk->key = (kv_data_t)malloc(bulk->ksize);
ret = hg_proc_raw(proc, bulk->key, bulk->ksize);
if(ret != HG_SUCCESS) return ret;
break;
case HG_FREE:
free(bulk->key);
break;
default:
break;
}
}
ret = hg_proc_hg_size_t(proc, &bulk->vsize);
if(ret != HG_SUCCESS) return ret;
ret = hg_proc_hg_bulk_t(proc, &bulk->handle);
if(ret != HG_SUCCESS) return ret;
return HG_SUCCESS;
}
MERCURY_GEN_PROC(bulk_put_in_t, ((kv_bulk_t)(bulk)))
MERCURY_GEN_PROC(bulk_put_out_t, ((int32_t)(ret)))
MERCURY_GEN_PROC(bulk_get_in_t, ((kv_bulk_t)(bulk)))
MERCURY_GEN_PROC(bulk_get_out_t, ((hg_size_t)(size)) ((int32_t)(ret)))
static inline hg_return_t hg_proc_double(hg_proc_t proc, void *data)
{
hg_return_t ret;
hg_size_t size = sizeof(double);
ret = hg_proc_raw(proc, data, size);
assert(ret == HG_SUCCESS);
return HG_SUCCESS;
}
#endif
This diff is collapsed.
/*
* (C) 2018 The University of Chicago
*
* See COPYRIGHT in top-level directory.
*/
#ifndef __SDSKV_SERVER_H
#define __SDSKV_SERVER_H
#include <margo.h>
#include "sdskv-common.h"
#ifdef __cplusplus
extern "C" {
#endif
#define SDSKV_ABT_POOL_DEFAULT ABT_POOL_NULL
#define SDSKV_MPLEX_ID_DEFAULT 0
#define SDSKV_PROVIDER_IGNORE NULL
typedef struct sdskv_server_context_t* sdskv_provider_t;
int sdskv_provider_register(
margo_instance_id mid,
uint8_t mplex_id,
ABT_pool pool,
sdskv_provider_t* provider);
/**
* Makes the provider start managing a database.
*
* @param provider provider
* @param db_name name of the database
* @param db_type type of database
* @param db_id resulting id identifying the database
*
* @return 0 on success, -1 on failure
*/
int sdskv_provider_add_storage_target(
sdskv_provider_t provider,
const char* db_name,
sdskv_db_type_t db_type,
sdskv_database_id_t* sb_id);