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

greatly simplified the RPC types

parent a7c8ccb6
......@@ -212,10 +212,10 @@ int sdskv_put(sdskv_provider_handle_t provider,
put_out_t out;
in.db_id = db_id;
in.key = (kv_data_t)key;
in.ksize = ksize;
in.value = (kv_data_t)value;
in.vsize = vsize;
in.key.data = (kv_ptr_t)key;
in.key.size = ksize;
in.value.data = (kv_ptr_t)value;
in.value.size = vsize;
/* create handle */
hret = margo_create(
......@@ -259,13 +259,13 @@ int sdskv_put(sdskv_provider_handle_t provider,
bulk_put_in_t in;
bulk_put_out_t out;
in.bulk.db_id = db_id;
in.bulk.key = (kv_data_t)key;
in.bulk.ksize = ksize;
in.bulk.vsize = vsize;
in.db_id = db_id;
in.key.data = (kv_ptr_t)key;
in.key.size = ksize;
in.vsize = vsize;
hret = margo_bulk_create(provider->client->mid, 1, (void**)(&value), &in.bulk.vsize,
HG_BULK_READ_ONLY, &in.bulk.handle);
hret = margo_bulk_create(provider->client->mid, 1, (void**)(&value), &in.vsize,
HG_BULK_READ_ONLY, &in.handle);
if(hret != HG_SUCCESS) {
fprintf(stderr,"[SDSKV] margo_bulk_create() failed in sdskv_put()\n");
return -1;
......@@ -279,7 +279,7 @@ int sdskv_put(sdskv_provider_handle_t provider,
&handle);
if(hret != HG_SUCCESS) {
fprintf(stderr,"[SDSKV] margo_create() failed in sdskv_put()\n");
margo_bulk_free(in.bulk.handle);
margo_bulk_free(in.handle);
return -1;
}
......@@ -287,7 +287,7 @@ int sdskv_put(sdskv_provider_handle_t provider,
if(hret != HG_SUCCESS) {
fprintf(stderr,"[SDSKV] margo_set_target_id() failed in sdskv_put()\n");
margo_bulk_free(in.bulk.handle);
margo_bulk_free(in.handle);
margo_destroy(handle);
return -1;
}
......@@ -295,7 +295,7 @@ int sdskv_put(sdskv_provider_handle_t provider,
hret = margo_forward(handle, &in);
if(hret != HG_SUCCESS) {
fprintf(stderr,"[SDSKV] margo_forward() failed in sdskv_put()\n");
margo_bulk_free(in.bulk.handle);
margo_bulk_free(in.handle);
margo_destroy(handle);
return -1;
}
......@@ -303,14 +303,14 @@ int sdskv_put(sdskv_provider_handle_t provider,
hret = margo_get_output(handle, &out);
if(hret != HG_SUCCESS) {
fprintf(stderr,"[SDSKV] margo_get_output() failed in sdskv_put()\n");
margo_bulk_free(in.bulk.handle);
margo_bulk_free(in.handle);
margo_destroy(handle);
return -1;
}
ret = out.ret;
margo_free_output(handle, &out);
margo_bulk_free(in.bulk.handle);
margo_bulk_free(in.handle);
}
margo_destroy(handle);
......@@ -337,8 +337,8 @@ int sdskv_get(sdskv_provider_handle_t provider,
get_out_t out;
in.db_id = db_id;
in.key = (kv_data_t)key;
in.ksize = ksize;
in.key.data = (kv_ptr_t)key;
in.key.size = ksize;
in.vsize = size;
/* create handle */
......@@ -369,10 +369,10 @@ int sdskv_get(sdskv_provider_handle_t provider,
}
ret = out.ret;
*vsize = (hg_size_t)out.vsize;
*vsize = (hg_size_t)out.value.size;
if (out.vsize > 0) {
memcpy(value, out.value, out.vsize);
if (out.value.size > 0) {
memcpy(value, out.value.data, out.value.size);
}
margo_free_output(handle, &out);
......@@ -382,13 +382,13 @@ int sdskv_get(sdskv_provider_handle_t provider,
bulk_get_in_t in;
bulk_get_out_t out;
in.bulk.db_id = db_id;
in.bulk.key = (kv_data_t)key;
in.bulk.ksize = ksize;
in.bulk.vsize = size;
in.db_id = db_id;
in.key.data = (kv_ptr_t)key;
in.key.size = ksize;
in.vsize = size;
hret = margo_bulk_create(provider->client->mid, 1, &value, &in.bulk.vsize,
HG_BULK_WRITE_ONLY, &in.bulk.handle);
hret = margo_bulk_create(provider->client->mid, 1, &value, &in.vsize,
HG_BULK_WRITE_ONLY, &in.handle);
if(hret != HG_SUCCESS) return -1;
/* create handle */
......@@ -398,27 +398,27 @@ int sdskv_get(sdskv_provider_handle_t provider,
provider->client->sdskv_bulk_get_id,
&handle);
if(hret != HG_SUCCESS) {
margo_bulk_free(in.bulk.handle);
margo_bulk_free(in.handle);
return -1;
}
hret = margo_set_target_id(handle, provider->mplex_id);
if(hret != HG_SUCCESS) {
margo_bulk_free(in.bulk.handle);
margo_bulk_free(in.handle);
margo_destroy(handle);
return -1;
}
hret = margo_forward(handle, &in);
if(hret != HG_SUCCESS) {
margo_bulk_free(in.bulk.handle);
margo_bulk_free(in.handle);
margo_destroy(handle);
return -1;
}
hret = margo_get_output(handle, &out);
if(hret != HG_SUCCESS) {
margo_bulk_free(in.bulk.handle);
margo_bulk_free(in.handle);
margo_destroy(handle);
return -1;
}
......@@ -427,7 +427,7 @@ int sdskv_get(sdskv_provider_handle_t provider,
*vsize = (hg_size_t)out.size;
margo_free_output(handle, &out);
margo_bulk_free(in.bulk.handle);
margo_bulk_free(in.handle);
}
margo_destroy(handle);
......@@ -446,8 +446,8 @@ int sdskv_length(sdskv_provider_handle_t provider,
length_out_t out;
in.db_id = db_id;
in.key = (kv_data_t)key;
in.ksize = ksize;
in.key.data = (kv_ptr_t)key;
in.key.size = ksize;
/* create handle */
hret = margo_create(
......@@ -495,8 +495,8 @@ int sdskv_erase(sdskv_provider_handle_t provider,
erase_out_t out;
in.db_id = db_id;
in.key = (kv_data_t)key;
in.ksize = ksize;
in.key.data = (kv_ptr_t)key;
in.key.size = ksize;
/* create handle */
hret = margo_create(
......@@ -552,8 +552,8 @@ int sdskv_list_keys(sdskv_provider_handle_t provider,
int i;
in.db_id = db_id;
in.start_key = (kv_data_t) start_key;
in.start_ksize = start_ksize;
in.start_key.data = (kv_ptr_t) start_key;
in.start_key.size = start_ksize;
in.max_keys = *max_keys;
/* create bulk handle to expose the segments with key sizes */
......@@ -653,8 +653,8 @@ int sdskv_list_keyvals(sdskv_provider_handle_t provider,
int i;
in.db_id = db_id;
in.start_key = (kv_data_t) start_key;
in.start_ksize = start_ksize;
in.start_key.data = (kv_ptr_t) start_key;
in.start_key.size = start_ksize;
in.max_keys = *max_keys;
/* create bulk handle to expose the segments with key sizes */
......@@ -748,83 +748,7 @@ finish:
return ret;
}
#if 0
int sdskv_list_keyvals(
sdskv_provider_handle_t provider,
sdskv_database_id_t db_id,
const void *start_key,
hg_size_t start_ksize,
void **keys,
hg_size_t* ksizes,
void** values,
hg_size_t* vsizes,
hg_size_t* max_keys)
{
list_in_t in;
list_out_t out;
hg_return_t hret = HG_SUCCESS;
hg_handle_t handle;
int ret;
int i;
in.db_id = db_id;
in.start_key = (kv_data_t) start_key;
in.start_ksize = start_ksize;
in.max_keys = *max_keys;
/* create handle */
hret = margo_create(
provider->client->mid,
provider->addr,
provider->client->sdskv_list_keyvals_id,
&handle);
if(hret != HG_SUCCESS) return -1;
hret = margo_set_target_id(handle, provider->mplex_id);
if(hret != HG_SUCCESS) {
margo_destroy(handle);
return -1;
}
hret = margo_forward(handle, &in);
if(hret != HG_SUCCESS) {
margo_destroy(handle);
return -1;
}
hret = margo_get_output(handle, &out);
if(hret != HG_SUCCESS) {
margo_destroy(handle);
return -1;
}
*max_keys = out.nkeys;
ret = out.ret;
if(ret == 0) {
hg_size_t s;
for (i=0; i < out.nkeys; i++) {
s = ksizes[i] > out.ksizes[i] ? out.ksizes[i] : ksizes[i];
ksizes[i] = s;
memcpy(keys[i], out.keys[i], s);
if(s < out.ksizes[i]) ret = -1; // truncated key
}
for(i=0; i< out.nvalues; i++) {
s = vsizes[i] > out.vsizes[i] ? out.vsizes[i] : vsizes[i];
vsizes[i] = s;
memcpy(values[i], out.values[i], s);
if(s < out.vsizes[i]) return -1; // truncated value
}
}
margo_free_output(handle, &out);
margo_destroy(handle);
return ret;
}
#endif
int sdskv_shutdown_service(sdskv_client_t client, hg_addr_t addr)
{
return margo_shutdown_remote_instance(client->mid, addr);
......
......@@ -13,397 +13,97 @@
#include "sdskv-common.h"
// setup to support opaque type handling
typedef char* kv_data_t;
// ------------- OPEN ------------- //
MERCURY_GEN_PROC(open_in_t,
((hg_string_t)(name)))
MERCURY_GEN_PROC(open_out_t, ((uint64_t)(db_id)) ((int32_t)(ret)))
// ------------- PUT ------------- //
typedef char* kv_ptr_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;
MERCURY_GEN_PROC(put_out_t, ((int32_t)(ret)))
hg_size_t size;
kv_ptr_t data;
} kv_data_t;
static inline hg_return_t hg_proc_put_in_t(hg_proc_t proc, void *data)
static inline hg_return_t hg_proc_kv_data_t(hg_proc_t proc, void *arg)
{
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;
kv_data_t *in = (kv_data_t*)arg;
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);
ret = hg_proc_hg_size_t(proc, &in->size);
if(ret != HG_SUCCESS) return ret;
if (in->vsize) {
if (in->size) {
switch (hg_proc_get_op(proc)) {
case HG_ENCODE:
ret = hg_proc_raw(proc, in->value, in->vsize);
ret = hg_proc_raw(proc, in->data, in->size);
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);
in->data = (kv_ptr_t)malloc(in->size);
ret = hg_proc_raw(proc, in->data, in->size);
if(ret != HG_SUCCESS) return ret;
break;
case HG_FREE:
free(in->value);
free(in->data);
break;
default:
break;
}
}
return HG_SUCCESS;
}
// ------------- GET ------------- //
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;
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;
}
// ------------- OPEN ------------- //
MERCURY_GEN_PROC(open_in_t,
((hg_string_t)(name)))
MERCURY_GEN_PROC(open_out_t, ((uint64_t)(db_id)) ((int32_t)(ret)))
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;
// ------------- PUT ------------- //
MERCURY_GEN_PROC(put_in_t, ((uint64_t)(db_id))\
((kv_data_t)(key))\
((kv_data_t)(value)))
MERCURY_GEN_PROC(put_out_t, ((int32_t)(ret)))
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;
// ------------- GET ------------- //
MERCURY_GEN_PROC(get_in_t, ((uint64_t)(db_id))\
((kv_data_t)(key))\
((hg_size_t)(vsize)))
return HG_SUCCESS;
}
MERCURY_GEN_PROC(get_out_t, ((int32_t)(ret))\
((kv_data_t)(value)))
// ------------- LENGTH ------------- //
typedef struct {
uint64_t db_id;
kv_data_t key;
hg_size_t ksize;
} length_in_t;
MERCURY_GEN_PROC(length_in_t, ((uint64_t)(db_id))((kv_data_t)(key)))
MERCURY_GEN_PROC(length_out_t, ((hg_size_t)(size)) ((int32_t)(ret)))
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;
}
// ------------- ERASE ------------- //
typedef struct {
uint64_t db_id;
kv_data_t key;
hg_size_t ksize;
} erase_in_t;
static inline hg_return_t hg_proc_erase_in_t(hg_proc_t proc, void *data)
{
hg_return_t ret;
erase_in_t *in = (erase_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;
}
MERCURY_GEN_PROC(erase_out_t, ((int32_t)(ret)))
MERCURY_GEN_PROC(erase_in_t, ((uint64_t)(db_id))((kv_data_t)(key)))
// ------------- LIST KEYS ------------- //
typedef struct {
uint64_t db_id;
kv_data_t start_key;
hg_size_t start_ksize;
hg_size_t max_keys;
hg_bulk_t ksizes_bulk_handle;
hg_bulk_t keys_bulk_handle;
} list_keys_in_t;
MERCURY_GEN_PROC(list_keys_in_t, ((uint64_t)(db_id))\
((kv_data_t)(start_key))\
((hg_size_t)(max_keys))\
((hg_bulk_t)(ksizes_bulk_handle))\
((hg_bulk_t)(keys_bulk_handle)))
MERCURY_GEN_PROC(list_keys_out_t, ((hg_size_t)(nkeys)) ((int32_t)(ret)))
static inline hg_return_t hg_proc_list_keys_in_t(hg_proc_t proc, void *data)
{
hg_return_t ret;
list_keys_in_t *in = (list_keys_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);
if(ret != HG_SUCCESS) return ret;
ret = hg_proc_hg_bulk_t(proc, &in->ksizes_bulk_handle);
if(ret != HG_SUCCESS) return ret;
ret = hg_proc_hg_bulk_t(proc, &in->keys_bulk_handle);
return ret;
}
// ------------- LIST KEYVALS ------------- //
typedef struct {
uint64_t db_id;
kv_data_t start_key;
hg_size_t start_ksize;
hg_size_t max_keys;
hg_bulk_t ksizes_bulk_handle;
hg_bulk_t keys_bulk_handle;
hg_bulk_t vsizes_bulk_handle;
hg_bulk_t vals_bulk_handle;
} list_keyvals_in_t;
MERCURY_GEN_PROC(list_keyvals_in_t, ((uint64_t)(db_id))\
((kv_data_t)(start_key))\
((hg_size_t)(max_keys))\