Commit 160f2917 authored by Matthieu Dorier's avatar Matthieu Dorier

added proxy function for put_packed

parent 0885eaad
......@@ -200,6 +200,34 @@ int sdskv_put_packed(sdskv_provider_handle_t provider,
size_t num, const void* packed_keys, const hg_size_t *ksizes,
const void* packed_values, const hg_size_t *vsizes);
/**
* @brief Puts multiple key/value pairs into the database.
* This method will send all the key/value pairs in batch,
* thus optimizing transfers by avoiding many RPC round trips.
* This version of put_multi assumes that the keys are packed
* in back to back in a single buffer, and so are the values.
* This proxy version takes a bulk handle instead of the 4
* buffers of sdskv_put_packed. The bulk handle should point
* to memory with the following layout:
* [num key sizes][ packed keys ][num val sizes][ packed values ]
* Where the key sizes and value sizes are of type hg_size_t.
*
* If the origin_addr is NULL, the server will consider that the
* bulk handle points to the sender's memory and will use the sender's
* address.
*
* @param provider provider handle managing the database
* @param db_id targeted database id
* @param origin_addr Mercury address of the process owning the bulk handles
* @param num number of key/value pairs to put
* @param packed_data bulk handle to a buffer containing the key sizes, keys, value sizes, and values
*
* @return SDSKV_SUCCESS or error code defined in sdskv-common.h
*/
int sdskv_proxy_put_packed(sdskv_provider_handle_t provider,
sdskv_database_id_t db_id, const char* origin_addr,
size_t num, hg_bulk_t packed_data, hg_size_t packed_data_size);
/**
* @brief Gets the value associated with a given key.
* vsize needs to be set to the current size of the allocated
......
......@@ -601,13 +601,7 @@ int sdskv_put_packed(sdskv_provider_handle_t provider,
{
hg_return_t hret;
int ret = SDSKV_SUCCESS;
hg_handle_t handle;
put_packed_in_t in;
put_packed_out_t out;
in.db_id = db_id;
in.num_keys = num;
hg_bulk_t bulk_handle = HG_BULK_NULL;
hg_size_t keys_buffer_size = 0;
hg_size_t vals_buffer_size = 0;
......@@ -616,19 +610,42 @@ int sdskv_put_packed(sdskv_provider_handle_t provider,
keys_buffer_size += ksizes[i];
vals_buffer_size += vsizes[i];
}
in.bulk_size = keys_buffer_size + vals_buffer_size + 2*num*sizeof(size_t);
hg_size_t bulk_size = keys_buffer_size + vals_buffer_size + 2*num*sizeof(size_t);
hg_size_t seg_sizes[4] = { num*sizeof(size_t), num*sizeof(size_t), keys_buffer_size, vals_buffer_size };
void* seg_ptrs[4] = { (void*)ksizes, (void*)vsizes, (void*)packed_keys, (void*)packed_values };
int num_seg = vals_buffer_size == 0 ? 3 : 4;
hret = margo_bulk_create(provider->client->mid, num_seg, seg_ptrs, seg_sizes,
HG_BULK_READ_ONLY, &in.bulk_handle);
HG_BULK_READ_ONLY, &bulk_handle);
if(hret != HG_SUCCESS) {
fprintf(stderr,"[SDSKV] margo_bulk_create() failed in sdskv_put_packed()\n");
return SDSKV_ERR_MERCURY;
}
ret = sdskv_proxy_put_packed(provider, db_id, NULL,
num, bulk_handle, bulk_size);
margo_bulk_free(bulk_handle);
return ret;
}
int sdskv_proxy_put_packed(sdskv_provider_handle_t provider,
sdskv_database_id_t db_id, const char* origin_addr,
size_t num, hg_bulk_t packed_data, hg_size_t bulk_data_size)
{
hg_return_t hret;
int ret = SDSKV_SUCCESS;
hg_handle_t handle;
put_packed_in_t in;
put_packed_out_t out;
in.db_id = db_id;
in.num_keys = num;
in.origin_addr = (char*)origin_addr;
in.bulk_handle = packed_data;
in.bulk_size = bulk_data_size;
/* create handle */
hret = margo_create(
provider->client->mid,
......@@ -659,7 +676,6 @@ int sdskv_put_packed(sdskv_provider_handle_t provider,
ret = out.ret;
margo_free_output(handle, &out);
margo_bulk_free(in.bulk_handle);
margo_destroy(handle);
return ret;
......
......@@ -194,6 +194,7 @@ MERCURY_GEN_PROC(put_multi_out_t, ((int32_t)(ret)))
// ------------- PUT PACKED ------------- //
MERCURY_GEN_PROC(put_packed_in_t, \
((uint64_t)(db_id))\
((hg_string_t)(origin_addr))\
((hg_size_t)(num_keys))\
((hg_size_t)(bulk_size))\
((hg_bulk_t)(bulk_handle)))
......
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