sdskv-server.cc 83.5 KB
Newer Older
Matthieu Dorier's avatar
Matthieu Dorier committed
1 2 3 4 5 6 7
/*
 * (C) 2015 The University of Chicago
 * 
 * See COPYRIGHT in top-level directory.
 */

#include <map>
Matthieu Dorier's avatar
Matthieu Dorier committed
8
#include <iostream>
Matthieu Dorier's avatar
Matthieu Dorier committed
9
#include <unordered_map>
10 11
#include <remi/remi-client.h>
#include <remi/remi-server.h>
Matthieu Dorier's avatar
Matthieu Dorier committed
12 13 14 15 16 17 18 19 20 21
#define SDSKV
#include "datastore/datastore_factory.h"
#include "sdskv-rpc-types.h"
#include "sdskv-server.h"

struct sdskv_server_context_t
{
    std::unordered_map<sdskv_database_id_t, AbstractDataStore*> databases;
    std::map<std::string, sdskv_database_id_t> name2id;
    std::map<sdskv_database_id_t, std::string> id2name;
22
    std::map<std::string, sdskv_compare_fn> compfunctions;
23 24
    remi_client_t   remi_client;
    remi_provider_t remi_provider;
25 26 27
    sdskv_pre_migration_callback_fn pre_migration_callback;
    sdskv_post_migration_callback_fn post_migration_callback;
    void* migration_uargs;
28

29 30 31 32
    ABT_rwlock lock; // write-locked during migration, read-locked by all other
    // operations. There should be something better to avoid locking everything
    // but we are going with that for simplicity for now.

33 34 35
    hg_id_t sdskv_open_id;
    hg_id_t sdskv_count_databases_id;
    hg_id_t sdskv_list_databases_id;
36
    hg_id_t sdskv_put_id;
Matthieu Dorier's avatar
Matthieu Dorier committed
37
    hg_id_t sdskv_put_multi_id;
38 39
    hg_id_t sdskv_bulk_put_id;
    hg_id_t sdskv_get_id;
Matthieu Dorier's avatar
Matthieu Dorier committed
40
    hg_id_t sdskv_get_multi_id;
41 42
    hg_id_t sdskv_exists_id;
    hg_id_t sdskv_erase_id;
Matthieu Dorier's avatar
Matthieu Dorier committed
43
    hg_id_t sdskv_erase_multi_id;
44
    hg_id_t sdskv_length_id;
Matthieu Dorier's avatar
Matthieu Dorier committed
45
    hg_id_t sdskv_length_multi_id;
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
    hg_id_t sdskv_bulk_get_id;
    hg_id_t sdskv_list_keys_id;
    hg_id_t sdskv_list_keyvals_id;
    /* migration */
    hg_id_t sdskv_migrate_keys_id;
    hg_id_t sdskv_migrate_key_range_id;
    hg_id_t sdskv_migrate_keys_prefixed_id;
    hg_id_t sdskv_migrate_all_keys_id;
    hg_id_t sdskv_migrate_database_id;
};

template<typename F>
struct scoped_call {
    F _f;
    scoped_call(const F& f) : _f(f) {}
    ~scoped_call() { _f(); }
Matthieu Dorier's avatar
Matthieu Dorier committed
62 63
};

64 65 66 67 68
template<typename F>
inline scoped_call<F> at_exit(F&& f) {
    return scoped_call<F>(std::forward<F>(f));
}

69 70 71
DECLARE_MARGO_RPC_HANDLER(sdskv_open_ult)
DECLARE_MARGO_RPC_HANDLER(sdskv_count_db_ult)
DECLARE_MARGO_RPC_HANDLER(sdskv_list_db_ult)
Matthieu Dorier's avatar
Matthieu Dorier committed
72
DECLARE_MARGO_RPC_HANDLER(sdskv_put_ult)
Matthieu Dorier's avatar
Matthieu Dorier committed
73
DECLARE_MARGO_RPC_HANDLER(sdskv_put_multi_ult)
Matthieu Dorier's avatar
Matthieu Dorier committed
74
DECLARE_MARGO_RPC_HANDLER(sdskv_length_ult)
Matthieu Dorier's avatar
Matthieu Dorier committed
75
DECLARE_MARGO_RPC_HANDLER(sdskv_length_multi_ult)
Matthieu Dorier's avatar
Matthieu Dorier committed
76
DECLARE_MARGO_RPC_HANDLER(sdskv_get_ult)
Matthieu Dorier's avatar
Matthieu Dorier committed
77
DECLARE_MARGO_RPC_HANDLER(sdskv_get_multi_ult)
Matthieu Dorier's avatar
Matthieu Dorier committed
78 79
DECLARE_MARGO_RPC_HANDLER(sdskv_bulk_put_ult)
DECLARE_MARGO_RPC_HANDLER(sdskv_bulk_get_ult)
80
DECLARE_MARGO_RPC_HANDLER(sdskv_list_keys_ult)
81
DECLARE_MARGO_RPC_HANDLER(sdskv_list_keyvals_ult)
Matthieu Dorier's avatar
Matthieu Dorier committed
82
DECLARE_MARGO_RPC_HANDLER(sdskv_erase_ult)
Matthieu Dorier's avatar
Matthieu Dorier committed
83
DECLARE_MARGO_RPC_HANDLER(sdskv_erase_multi_ult)
84
DECLARE_MARGO_RPC_HANDLER(sdskv_exists_ult)
85 86 87 88
DECLARE_MARGO_RPC_HANDLER(sdskv_migrate_keys_ult)
DECLARE_MARGO_RPC_HANDLER(sdskv_migrate_key_range_ult)
DECLARE_MARGO_RPC_HANDLER(sdskv_migrate_keys_prefixed_ult)
DECLARE_MARGO_RPC_HANDLER(sdskv_migrate_all_keys_ult)
89
DECLARE_MARGO_RPC_HANDLER(sdskv_migrate_database_ult)
Matthieu Dorier's avatar
Matthieu Dorier committed
90

Matthieu Dorier's avatar
Matthieu Dorier committed
91 92
static void sdskv_server_finalize_cb(void *data);

93 94 95 96
static int sdskv_pre_migration_callback(remi_fileset_t fileset, void* uargs);

static int sdskv_post_migration_callback(remi_fileset_t fileset, void* uargs);

Matthieu Dorier's avatar
Matthieu Dorier committed
97 98
extern "C" int sdskv_provider_register(
        margo_instance_id mid,
99
        uint16_t provider_id,
Matthieu Dorier's avatar
Matthieu Dorier committed
100 101 102 103
        ABT_pool abt_pool,
        sdskv_provider_t* provider)
{
    sdskv_server_context_t *tmp_svr_ctx;
104
    int ret;
Matthieu Dorier's avatar
Matthieu Dorier committed
105 106 107 108 109

    /* check if a provider with the same multiplex id already exists */
    {
        hg_id_t id;
        hg_bool_t flag;
110
        margo_provider_registered_name(mid, "sdskv_put_rpc", provider_id, &id, &flag);
Matthieu Dorier's avatar
Matthieu Dorier committed
111
        if(flag == HG_TRUE) {
112
            fprintf(stderr, "sdskv_provider_register(): a provider with the same provider id (%d) already exists\n", provider_id);
113
            return SDSKV_ERR_MERCURY;
Matthieu Dorier's avatar
Matthieu Dorier committed
114 115 116
        }
    }

117 118 119
    /* check if a REMI provider exists with the same provider id */
    {
        int flag;
120
        remi_provider_registered(mid, provider_id, &flag, NULL, NULL, NULL);
121 122 123 124 125 126
        if(flag) {
            fprintf(stderr, "sdskv_provider_register(): a REMI provider with the same (%d) already exists\n", provider_id);
            return SDSKV_ERR_REMI;
        }
    }

Matthieu Dorier's avatar
Matthieu Dorier committed
127
    /* allocate the resulting structure */    
Matthieu Dorier's avatar
Matthieu Dorier committed
128
    tmp_svr_ctx = new sdskv_server_context_t;
Matthieu Dorier's avatar
Matthieu Dorier committed
129
    if(!tmp_svr_ctx)
130
        return SDSKV_ERR_ALLOCATION;
Matthieu Dorier's avatar
Matthieu Dorier committed
131

132 133
    tmp_svr_ctx->remi_client   = REMI_CLIENT_NULL;
    tmp_svr_ctx->remi_provider = REMI_PROVIDER_NULL;
134 135 136
    tmp_svr_ctx->pre_migration_callback = NULL;
    tmp_svr_ctx->post_migration_callback = NULL;
    tmp_svr_ctx->migration_uargs = NULL;
137 138 139 140 141 142 143 144

    /* Create rwlock */
    ret = ABT_rwlock_create(&(tmp_svr_ctx->lock));
    if(ret != ABT_SUCCESS) {
        free(tmp_svr_ctx);
        return SDSKV_ERR_ARGOBOTS;
    }

Matthieu Dorier's avatar
Matthieu Dorier committed
145 146
    /* register RPCs */
    hg_id_t rpc_id;
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
    rpc_id = MARGO_REGISTER_PROVIDER(mid, "sdskv_open_rpc",
            open_in_t, open_out_t,
            sdskv_open_ult, provider_id, abt_pool);
    tmp_svr_ctx->sdskv_open_id = rpc_id;
    margo_register_data(mid, rpc_id, (void*)tmp_svr_ctx, NULL);
    rpc_id = MARGO_REGISTER_PROVIDER(mid, "sdskv_count_databases_rpc",
            void, count_db_out_t,
            sdskv_count_db_ult, provider_id, abt_pool);
    tmp_svr_ctx->sdskv_count_databases_id = rpc_id;
    margo_register_data(mid, rpc_id, (void*)tmp_svr_ctx, NULL);
    rpc_id = MARGO_REGISTER_PROVIDER(mid, "sdskv_list_databases_rpc",
            list_db_in_t, list_db_out_t,
            sdskv_list_db_ult, provider_id, abt_pool);
    tmp_svr_ctx->sdskv_list_databases_id = rpc_id;
    margo_register_data(mid, rpc_id, (void*)tmp_svr_ctx, NULL);
162
    rpc_id = MARGO_REGISTER_PROVIDER(mid, "sdskv_put_rpc",
Matthieu Dorier's avatar
Matthieu Dorier committed
163
            put_in_t, put_out_t,
164
            sdskv_put_ult, provider_id, abt_pool);
165
    tmp_svr_ctx->sdskv_put_id = rpc_id;
166
    margo_register_data(mid, rpc_id, (void*)tmp_svr_ctx, NULL);
Matthieu Dorier's avatar
Matthieu Dorier committed
167 168 169 170 171
    rpc_id = MARGO_REGISTER_PROVIDER(mid, "sdskv_put_multi_rpc",
            put_multi_in_t, put_multi_out_t,
            sdskv_put_multi_ult, provider_id, abt_pool);
    tmp_svr_ctx->sdskv_put_multi_id = rpc_id;
    margo_register_data(mid, rpc_id, (void*)tmp_svr_ctx, NULL);
172
    rpc_id = MARGO_REGISTER_PROVIDER(mid, "sdskv_bulk_put_rpc",
Matthieu Dorier's avatar
Matthieu Dorier committed
173
            bulk_put_in_t, bulk_put_out_t,
174
            sdskv_bulk_put_ult, provider_id, abt_pool);
175
    tmp_svr_ctx->sdskv_bulk_put_id = rpc_id;
176 177
    margo_register_data(mid, rpc_id, (void*)tmp_svr_ctx, NULL);
    rpc_id = MARGO_REGISTER_PROVIDER(mid, "sdskv_get_rpc",
Matthieu Dorier's avatar
Matthieu Dorier committed
178
            get_in_t, get_out_t,
179
            sdskv_get_ult, provider_id, abt_pool);
180
    tmp_svr_ctx->sdskv_get_id = rpc_id;
181
    margo_register_data(mid, rpc_id, (void*)tmp_svr_ctx, NULL);
Matthieu Dorier's avatar
Matthieu Dorier committed
182 183 184 185 186
    rpc_id = MARGO_REGISTER_PROVIDER(mid, "sdskv_get_multi_rpc",
            get_multi_in_t, get_multi_out_t,
            sdskv_get_multi_ult, provider_id, abt_pool);
    tmp_svr_ctx->sdskv_get_multi_id = rpc_id;
    margo_register_data(mid, rpc_id, (void*)tmp_svr_ctx, NULL);
187
    rpc_id = MARGO_REGISTER_PROVIDER(mid, "sdskv_length_rpc",
Matthieu Dorier's avatar
Matthieu Dorier committed
188
            length_in_t, length_out_t,
189
            sdskv_length_ult, provider_id, abt_pool);
190
    tmp_svr_ctx->sdskv_length_id = rpc_id;
191
    margo_register_data(mid, rpc_id, (void*)tmp_svr_ctx, NULL);
Matthieu Dorier's avatar
Matthieu Dorier committed
192 193 194 195 196
    rpc_id = MARGO_REGISTER_PROVIDER(mid, "sdskv_length_multi_rpc",
            length_multi_in_t, length_multi_out_t,
            sdskv_length_multi_ult, provider_id, abt_pool);
    tmp_svr_ctx->sdskv_length_multi_id = rpc_id;
    margo_register_data(mid, rpc_id, (void*)tmp_svr_ctx, NULL);
197 198 199
    rpc_id = MARGO_REGISTER_PROVIDER(mid, "sdskv_exists_rpc",
            exists_in_t, exists_out_t,
            sdskv_exists_ult, provider_id, abt_pool);
200
    tmp_svr_ctx->sdskv_exists_id = rpc_id;
201
    margo_register_data(mid, rpc_id, (void*)tmp_svr_ctx, NULL);
202
    rpc_id = MARGO_REGISTER_PROVIDER(mid, "sdskv_bulk_get_rpc",
Matthieu Dorier's avatar
Matthieu Dorier committed
203
            bulk_get_in_t, bulk_get_out_t,
204
            sdskv_bulk_get_ult, provider_id, abt_pool);
205
    tmp_svr_ctx->sdskv_bulk_get_id = rpc_id;
206 207
    margo_register_data(mid, rpc_id, (void*)tmp_svr_ctx, NULL);
    rpc_id = MARGO_REGISTER_PROVIDER(mid, "sdskv_list_keys_rpc",
208
            list_keys_in_t, list_keys_out_t,
209
            sdskv_list_keys_ult, provider_id, abt_pool);
210
    tmp_svr_ctx->sdskv_list_keys_id = rpc_id;
211 212
    margo_register_data(mid, rpc_id, (void*)tmp_svr_ctx, NULL);
    rpc_id = MARGO_REGISTER_PROVIDER(mid, "sdskv_list_keyvals_rpc",
213
            list_keyvals_in_t, list_keyvals_out_t,
214
            sdskv_list_keyvals_ult, provider_id, abt_pool);
215
    tmp_svr_ctx->sdskv_list_keyvals_id = rpc_id;
216 217
    margo_register_data(mid, rpc_id, (void*)tmp_svr_ctx, NULL);
    rpc_id = MARGO_REGISTER_PROVIDER(mid, "sdskv_erase_rpc",
Matthieu Dorier's avatar
Matthieu Dorier committed
218
            erase_in_t, erase_out_t,
219
            sdskv_erase_ult, provider_id, abt_pool);
220
    tmp_svr_ctx->sdskv_erase_id = rpc_id;
221
    margo_register_data(mid, rpc_id, (void*)tmp_svr_ctx, NULL);
Matthieu Dorier's avatar
Matthieu Dorier committed
222 223 224 225 226
    rpc_id = MARGO_REGISTER_PROVIDER(mid, "sdskv_erase_multi_rpc",
            erase_multi_in_t, erase_multi_out_t,
            sdskv_erase_multi_ult, provider_id, abt_pool);
    tmp_svr_ctx->sdskv_erase_multi_id = rpc_id;
    margo_register_data(mid, rpc_id, (void*)tmp_svr_ctx, NULL);
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
    /* migration RPC */
    rpc_id = MARGO_REGISTER_PROVIDER(mid, "sdskv_migrate_keys_rpc",
            migrate_keys_in_t, migrate_keys_out_t,
            sdskv_migrate_keys_ult, provider_id, abt_pool);
    tmp_svr_ctx->sdskv_migrate_keys_id = rpc_id;
    margo_register_data(mid, rpc_id, (void*)tmp_svr_ctx, NULL);
    rpc_id = MARGO_REGISTER_PROVIDER(mid, "sdskv_migrate_key_range_rpc",
            migrate_key_range_in_t, migrate_keys_out_t,
            sdskv_migrate_key_range_ult, provider_id, abt_pool);
    tmp_svr_ctx->sdskv_migrate_key_range_id = rpc_id;
    margo_register_data(mid, rpc_id, (void*)tmp_svr_ctx, NULL);
    rpc_id = MARGO_REGISTER_PROVIDER(mid, "sdskv_migrate_keys_prefixed_rpc",
            migrate_keys_prefixed_in_t, migrate_keys_out_t,
            sdskv_migrate_keys_prefixed_ult, provider_id, abt_pool);
    tmp_svr_ctx->sdskv_migrate_keys_prefixed_id = rpc_id;
    margo_register_data(mid, rpc_id, (void*)tmp_svr_ctx, NULL);
    rpc_id = MARGO_REGISTER_PROVIDER(mid, "sdskv_migrate_all_keys_rpc",
            migrate_all_keys_in_t, migrate_keys_out_t,
            sdskv_migrate_all_keys_ult, provider_id, abt_pool);
    tmp_svr_ctx->sdskv_migrate_all_keys_id = rpc_id;
    margo_register_data(mid, rpc_id, (void*)tmp_svr_ctx, NULL);
248 249 250 251 252 253 254
    rpc_id = MARGO_REGISTER_PROVIDER(mid, "sdskv_migrate_database_rpc",
            migrate_database_in_t, migrate_database_out_t,
            sdskv_migrate_database_ult, provider_id, abt_pool);
    tmp_svr_ctx->sdskv_migrate_database_id = rpc_id;
    margo_register_data(mid, rpc_id, (void*)tmp_svr_ctx, NULL);

    /* register a REMI client */
255
    ret = remi_client_init(mid, ABT_IO_INSTANCE_NULL, &(tmp_svr_ctx->remi_client));
256
    if(ret != REMI_SUCCESS) {
257
        sdskv_server_finalize_cb(tmp_svr_ctx);
258 259 260 261
        return SDSKV_ERR_REMI;
    }

    /* register a REMI provider */
262
    ret = remi_provider_register(mid, ABT_IO_INSTANCE_NULL, provider_id, abt_pool, &(tmp_svr_ctx->remi_provider));
263
    if(ret != REMI_SUCCESS) {
264
        sdskv_server_finalize_cb(tmp_svr_ctx);
265 266 267
        return SDSKV_ERR_REMI;
    }
    ret = remi_provider_register_migration_class(tmp_svr_ctx->remi_provider,
Matthieu Dorier's avatar
Matthieu Dorier committed
268
            "sdskv", sdskv_pre_migration_callback,
269 270
            sdskv_post_migration_callback, NULL, tmp_svr_ctx);
    if(ret != REMI_SUCCESS) {
271
        sdskv_server_finalize_cb(tmp_svr_ctx);
272 273 274
        return SDSKV_ERR_REMI;
    }

275 276 277
    /* install the bake server finalize callback */
    margo_push_finalize_callback(mid, &sdskv_server_finalize_cb, tmp_svr_ctx);

Matthieu Dorier's avatar
Matthieu Dorier committed
278 279 280
    if(provider != SDSKV_PROVIDER_IGNORE)
        *provider = tmp_svr_ctx;

281
    return SDSKV_SUCCESS;
Matthieu Dorier's avatar
Matthieu Dorier committed
282 283
}

284
extern "C" int sdskv_provider_add_comparison_function(
285 286 287 288 289 290 291 292 293 294 295
        sdskv_provider_t provider,
        const char* function_name,
        sdskv_compare_fn comp_fn) 
{
    if(provider->compfunctions.find(std::string(function_name))
        != provider->compfunctions.end())
        return SDSKV_ERR_COMP_FUNC;
    provider->compfunctions[std::string(function_name)] = comp_fn;
    return SDSKV_SUCCESS;
}

296
extern "C" int sdskv_provider_attach_database(
Matthieu Dorier's avatar
Matthieu Dorier committed
297
        sdskv_provider_t provider,
298
        const sdskv_config_t* config,
Matthieu Dorier's avatar
Matthieu Dorier committed
299 300
        sdskv_database_id_t* db_id)
{
301 302 303 304 305 306 307 308 309
    sdskv_compare_fn comp_fn = NULL;
    if(config->db_comp_fn_name) {
        std::string k(config->db_comp_fn_name);
        auto it = provider->compfunctions.find(k);
        if(it == provider->compfunctions.end())
            return SDSKV_ERR_COMP_FUNC;
        comp_fn = it->second;
    }

310 311
    auto db = datastore_factory::open_datastore(config->db_type, 
            std::string(config->db_name), std::string(config->db_path));
312
    if(db == nullptr) return SDSKV_ERR_DB_CREATE;
313
    if(comp_fn) {
314
        db->set_comparison_function(config->db_comp_fn_name, comp_fn);
315
    }
Matthieu Dorier's avatar
Matthieu Dorier committed
316
    sdskv_database_id_t id = (sdskv_database_id_t)(db);
317 318 319
    if(config->db_no_overwrite) {
        db->set_no_overwrite();
    }
Matthieu Dorier's avatar
Matthieu Dorier committed
320

321 322 323
    ABT_rwlock_wrlock(provider->lock);
    auto r = at_exit([provider]() { ABT_rwlock_unlock(provider->lock); });

324 325
    provider->name2id[std::string(config->db_name)] = id;
    provider->id2name[id] = std::string(config->db_name);
Matthieu Dorier's avatar
Matthieu Dorier committed
326 327
    provider->databases[id] = db;

328 329
    *db_id = id;

330
    return SDSKV_SUCCESS;
Matthieu Dorier's avatar
Matthieu Dorier committed
331 332 333 334 335 336
}

extern "C" int sdskv_provider_remove_database(
        sdskv_provider_t provider,
        sdskv_database_id_t db_id)
{
337 338
    ABT_rwlock_wrlock(provider->lock);
    auto r = at_exit([provider]() { ABT_rwlock_unlock(provider->lock); });
Matthieu Dorier's avatar
Matthieu Dorier committed
339 340 341 342 343 344 345
    if(provider->databases.count(db_id)) {
        auto dbname = provider->id2name[db_id];
        provider->id2name.erase(db_id);
        provider->name2id.erase(dbname);
        auto db = provider->databases[db_id];
        delete db;
        provider->databases.erase(db_id);
346
        return SDSKV_SUCCESS;
Matthieu Dorier's avatar
Matthieu Dorier committed
347
    } else {
348
        return SDSKV_ERR_UNKNOWN_DB;
Matthieu Dorier's avatar
Matthieu Dorier committed
349 350 351 352 353 354
    }
}

extern "C" int sdskv_provider_remove_all_databases(
        sdskv_provider_t provider)
{
355 356
    ABT_rwlock_wrlock(provider->lock);
    auto r = at_exit([provider]() { ABT_rwlock_unlock(provider->lock); });
Matthieu Dorier's avatar
Matthieu Dorier committed
357 358 359 360 361 362 363
    for(auto db : provider->databases) {
        delete db.second;
    }
    provider->databases.clear();
    provider->name2id.clear();
    provider->id2name.clear();

364
    return SDSKV_SUCCESS;
Matthieu Dorier's avatar
Matthieu Dorier committed
365 366 367 368 369 370
}

extern "C" int sdskv_provider_count_databases(
        sdskv_provider_t provider,
        uint64_t* num_db)
{
371 372
    ABT_rwlock_rdlock(provider->lock);
    auto r = at_exit([provider]() { ABT_rwlock_unlock(provider->lock); });
Matthieu Dorier's avatar
Matthieu Dorier committed
373
    *num_db = provider->databases.size();
374
    return SDSKV_SUCCESS;
Matthieu Dorier's avatar
Matthieu Dorier committed
375 376 377 378 379 380 381
}

extern "C" int sdskv_provider_list_databases(
        sdskv_provider_t provider,
        sdskv_database_id_t* targets)
{
    unsigned i = 0;
382 383
    ABT_rwlock_rdlock(provider->lock);
    auto r = at_exit([provider]() { ABT_rwlock_unlock(provider->lock); });
Matthieu Dorier's avatar
Matthieu Dorier committed
384 385 386 387
    for(auto p : provider->name2id) {
        targets[i] = p.second;
        i++;
    }
388
    return SDSKV_SUCCESS;
Matthieu Dorier's avatar
Matthieu Dorier committed
389 390
}

391 392 393 394 395 396 397
extern "C" int sdskv_provider_compute_database_size(
        sdskv_provider_t provider,
        sdskv_database_id_t database_id,
        size_t* size)
{
    int ret;
    // find the database
398
    ABT_rwlock_rdlock(provider->lock);
399 400
    auto it = provider->databases.find(database_id);
    if(it == provider->databases.end()) {
401
        ABT_rwlock_unlock(provider->lock);
402 403 404
        return SDSKV_ERR_UNKNOWN_DB;
    }
    auto database = it->second;
405 406
    ABT_rwlock_unlock(provider->lock);

407 408 409 410 411 412 413 414 415 416
    database->sync();

    /* create a fileset */
    remi_fileset_t fileset = database->create_and_populate_fileset();
    if(fileset == REMI_FILESET_NULL) {
        return SDSKV_OP_NOT_IMPL;
    }
    /* issue the migration */
    ret = remi_fileset_compute_size(fileset, 0, size);
    if(ret != REMI_SUCCESS) {
417
        std::cerr << "[SDSKV] error: remi_fileset_compute_size returned " << ret << std::endl;
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434
        return SDSKV_ERR_REMI;
    }
    return SDSKV_SUCCESS;
}

extern "C" int sdskv_provider_set_migration_callbacks(
        sdskv_provider_t provider,
        sdskv_pre_migration_callback_fn pre_cb,
        sdskv_post_migration_callback_fn  post_cb,
        void* uargs)
{
    provider->pre_migration_callback = pre_cb;
    provider->post_migration_callback = post_cb;
    provider->migration_uargs = uargs;
    return SDSKV_SUCCESS;
}

435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575
static void sdskv_open_ult(hg_handle_t handle)
{

    hg_return_t hret;
    open_in_t in;
    open_out_t out;

    margo_instance_id mid = margo_hg_handle_get_instance(handle);
    assert(mid);
    const struct hg_info* info = margo_get_info(handle);
    sdskv_provider_t svr_ctx = 
        (sdskv_provider_t)margo_registered_data(mid, info->id);
    if(!svr_ctx) {
        fprintf(stderr, "Error (sdskv_open_ult): SDSKV could not find provider with id\n"); 
        out.ret = SDSKV_ERR_UNKNOWN_PR;
        margo_respond(handle, &out);
        margo_destroy(handle);
        return;
    }

    hret = margo_get_input(handle, &in);
    if(hret != HG_SUCCESS) {
        out.ret = SDSKV_ERR_MERCURY;
        margo_respond(handle, &out);
        margo_destroy(handle);
        return;
    }

    ABT_rwlock_rdlock(svr_ctx->lock);
    auto it = svr_ctx->name2id.find(std::string(in.name));
    if(it == svr_ctx->name2id.end()) {
        ABT_rwlock_unlock(svr_ctx->lock);
        out.ret = SDSKV_ERR_DB_NAME;
        margo_respond(handle, &out);
        margo_free_input(handle, &in);
        margo_destroy(handle);
        return;
    }
    auto db = it->second;
    ABT_rwlock_unlock(svr_ctx->lock);

    out.db_id = db;
    out.ret  = SDSKV_SUCCESS;

    margo_respond(handle, &out);
    margo_free_input(handle, &in);
    margo_destroy(handle);
    return;
}
DEFINE_MARGO_RPC_HANDLER(sdskv_open_ult)

static void sdskv_count_db_ult(hg_handle_t handle)
{

    hg_return_t hret;
    count_db_out_t out;

    margo_instance_id mid = margo_hg_handle_get_instance(handle);
    assert(mid);
    const struct hg_info* info = margo_get_info(handle);
    sdskv_provider_t svr_ctx = 
        (sdskv_provider_t)margo_registered_data(mid, info->id);
    if(!svr_ctx) {
        fprintf(stderr, "Error (sdskv_count_db_ult): SDSKV could not find provider with id\n"); 
        out.ret = SDSKV_ERR_UNKNOWN_PR;
        margo_respond(handle, &out);
        margo_destroy(handle);
        return;
    }

    uint64_t count;
    sdskv_provider_count_databases(svr_ctx, &count);

    out.count = count;
    out.ret  = SDSKV_SUCCESS;

    margo_respond(handle, &out);
    margo_destroy(handle);
    return;
}
DEFINE_MARGO_RPC_HANDLER(sdskv_count_db_ult)

static void sdskv_list_db_ult(hg_handle_t handle)
{

    hg_return_t hret;
    list_db_in_t in;
    list_db_out_t out;

    margo_instance_id mid = margo_hg_handle_get_instance(handle);
    assert(mid);
    const struct hg_info* info = margo_get_info(handle);
    sdskv_provider_t svr_ctx = 
        (sdskv_provider_t)margo_registered_data(mid, info->id);
    if(!svr_ctx) {
        fprintf(stderr, "Error (sdskv_list_db_ult): SDSKV could not find provider with id\n"); 
        out.ret = SDSKV_ERR_UNKNOWN_PR;
        margo_respond(handle, &out);
        margo_destroy(handle);
        return;
    }

    hret = margo_get_input(handle, &in);
    if(hret != HG_SUCCESS) {
        out.ret = SDSKV_ERR_MERCURY;
        margo_respond(handle, &out);
        margo_destroy(handle);
        return;
    }

    std::vector<std::string> db_names;
    std::vector<uint64_t> db_ids;

    out.count = 0;

    ABT_rwlock_rdlock(svr_ctx->lock);
    unsigned i = 0;
    for(const auto& p : svr_ctx->name2id) {
        if(i >= in.count)
            break;
        db_names.push_back(p.first);
        db_ids.push_back(p.second);
        i += 1;
    }
    ABT_rwlock_unlock(svr_ctx->lock);
    out.count = i;
    out.db_names = (char**)malloc(out.count*sizeof(char*));
    for(i=0; i < out.count; i++) {
        out.db_names[i] = const_cast<char*>(db_names[i].c_str());
    }
    out.db_ids = &db_ids[0];
    out.ret    = SDSKV_SUCCESS;

    margo_respond(handle, &out);
    margo_free_input(handle, &in);
    margo_destroy(handle);
    free(out.db_names);
    return;
}
DEFINE_MARGO_RPC_HANDLER(sdskv_list_db_ult)

Matthieu Dorier's avatar
Matthieu Dorier committed
576 577 578 579 580 581 582 583 584 585
static void sdskv_put_ult(hg_handle_t handle)
{
    hg_return_t hret;
    put_in_t in;
    put_out_t out;

    margo_instance_id mid = margo_hg_handle_get_instance(handle);
    assert(mid);
    const struct hg_info* info = margo_get_info(handle);
    sdskv_provider_t svr_ctx = 
586
        (sdskv_provider_t)margo_registered_data(mid, info->id);
Matthieu Dorier's avatar
Matthieu Dorier committed
587
    if(!svr_ctx) {
Matthieu Dorier's avatar
Matthieu Dorier committed
588
        fprintf(stderr, "Error (sdskv_put_ult): SDSKV could not find provider\n"); 
589
        out.ret = SDSKV_ERR_UNKNOWN_PR;
Matthieu Dorier's avatar
Matthieu Dorier committed
590 591 592 593
        margo_respond(handle, &out);
        margo_destroy(handle);
        return;
    }
594

Matthieu Dorier's avatar
Matthieu Dorier committed
595 596
    hret = margo_get_input(handle, &in);
    if(hret != HG_SUCCESS) {
597
        out.ret = SDSKV_ERR_MERCURY;
Matthieu Dorier's avatar
Matthieu Dorier committed
598 599 600 601 602
        margo_respond(handle, &out);
        margo_destroy(handle);
        return;
    }

603
    ABT_rwlock_rdlock(svr_ctx->lock);
Matthieu Dorier's avatar
Matthieu Dorier committed
604 605
    auto it = svr_ctx->databases.find(in.db_id);
    if(it == svr_ctx->databases.end()) {
606
        ABT_rwlock_unlock(svr_ctx->lock);
607
        out.ret = SDSKV_ERR_UNKNOWN_DB;
Matthieu Dorier's avatar
Matthieu Dorier committed
608 609 610 611 612
        margo_respond(handle, &out);
        margo_free_input(handle, &in);
        margo_destroy(handle);
        return;
    }
613 614
    auto db = it->second;
    ABT_rwlock_unlock(svr_ctx->lock);
Matthieu Dorier's avatar
Matthieu Dorier committed
615

616 617
    ds_bulk_t kdata(in.key.data, in.key.data+in.key.size);
    ds_bulk_t vdata(in.value.data, in.value.data+in.value.size);
Matthieu Dorier's avatar
Matthieu Dorier committed
618

619
    if(db->put(kdata, vdata)) {
620
        out.ret = SDSKV_SUCCESS;
Matthieu Dorier's avatar
Matthieu Dorier committed
621
    } else {
622
        out.ret = SDSKV_ERR_PUT;
Matthieu Dorier's avatar
Matthieu Dorier committed
623 624 625 626 627 628 629 630
    }

    margo_respond(handle, &out);
    margo_free_input(handle, &in);
    margo_destroy(handle);
}
DEFINE_MARGO_RPC_HANDLER(sdskv_put_ult)

Matthieu Dorier's avatar
Matthieu Dorier committed
631
static void sdskv_put_multi_ult(hg_handle_t handle)
Matthieu Dorier's avatar
Matthieu Dorier committed
632
{
Matthieu Dorier's avatar
Matthieu Dorier committed
633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653
    hg_return_t hret;
    put_multi_in_t in;
    put_multi_out_t out;
    out.ret = SDSKV_SUCCESS;
    std::vector<char> local_keys_buffer;
    std::vector<char> local_vals_buffer;
    hg_bulk_t local_keys_bulk_handle;
    hg_bulk_t local_vals_bulk_handle;

    auto r1 = at_exit([&handle]() { margo_destroy(handle); });
    auto r2 = at_exit([&handle,&out]() { margo_respond(handle, &out); });


    margo_instance_id mid = margo_hg_handle_get_instance(handle);
    const struct hg_info* info = margo_get_info(handle);
    sdskv_provider_t svr_ctx = 
        (sdskv_provider_t)margo_registered_data(mid, info->id);
    if(!svr_ctx) {
        out.ret = SDSKV_ERR_UNKNOWN_PR;
        return;
    }
Matthieu Dorier's avatar
Matthieu Dorier committed
654

655

Matthieu Dorier's avatar
Matthieu Dorier committed
656 657 658 659 660 661 662
    hret = margo_get_input(handle, &in);
    if(hret != HG_SUCCESS) {
        out.ret = SDSKV_ERR_MERCURY;
        return;
    }
    auto r3 = at_exit([&handle,&in]() { margo_free_input(handle, &in); });

663
    ABT_rwlock_rdlock(svr_ctx->lock);
Matthieu Dorier's avatar
Matthieu Dorier committed
664 665
    auto it = svr_ctx->databases.find(in.db_id);
    if(it == svr_ctx->databases.end()) {
666
        ABT_rwlock_unlock(svr_ctx->lock); 
Matthieu Dorier's avatar
Matthieu Dorier committed
667 668 669
        out.ret = SDSKV_ERR_UNKNOWN_DB;
        return;
    }
670 671
    auto db = it->second;
    ABT_rwlock_unlock(svr_ctx->lock);
Matthieu Dorier's avatar
Matthieu Dorier committed
672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723

    // allocate a buffer to receive the keys and a buffer to receive the values
    local_keys_buffer.resize(in.keys_bulk_size);
    local_vals_buffer.resize(in.vals_bulk_size);
    std::vector<void*> keys_addr(1); keys_addr[0] = (void*)local_keys_buffer.data();
    std::vector<void*> vals_addr(1); vals_addr[0] = (void*)local_vals_buffer.data();
    
    /* create bulk handle to receive keys */
    hret = margo_bulk_create(mid, 1, keys_addr.data(), &in.keys_bulk_size,
            HG_BULK_WRITE_ONLY, &local_keys_bulk_handle);
    if(hret != HG_SUCCESS) {
        out.ret = SDSKV_ERR_MERCURY;
        return;
    }
    auto r6 = at_exit([&local_keys_bulk_handle]() { margo_bulk_free(local_keys_bulk_handle); });

    /* create bulk handle to receive values */
    hret = margo_bulk_create(mid, 1, vals_addr.data(), &in.vals_bulk_size,
            HG_BULK_WRITE_ONLY, &local_vals_bulk_handle);
    if(hret != HG_SUCCESS) {
        out.ret = SDSKV_ERR_MERCURY;
        return;
    }
    auto r7 = at_exit([&local_vals_bulk_handle]() { margo_bulk_free(local_vals_bulk_handle); });

    /* transfer keys */
    hret = margo_bulk_transfer(mid, HG_BULK_PULL, info->addr, in.keys_bulk_handle, 0,
            local_keys_bulk_handle, 0, in.keys_bulk_size);
    if(hret != HG_SUCCESS) {
        out.ret = SDSKV_ERR_MERCURY;
        return;
    }

    /* transfer values */
    hret = margo_bulk_transfer(mid, HG_BULK_PULL, info->addr, in.vals_bulk_handle, 0,
            local_vals_bulk_handle, 0, in.vals_bulk_size);
    if(hret != HG_SUCCESS) {
        out.ret = SDSKV_ERR_MERCURY;
        return;
    }

    /* interpret beginning of the key buffer as a list of key sizes */
    hg_size_t* key_sizes = (hg_size_t*)local_keys_buffer.data();
    /* interpret beginning of the value buffer as a list of value sizes */
    hg_size_t* val_sizes = (hg_size_t*)local_vals_buffer.data();

    /* go through the key/value pairs and insert them */
    uint64_t keys_offset = sizeof(hg_size_t)*in.num_keys;
    uint64_t vals_offset = sizeof(hg_size_t)*in.num_keys;
    for(unsigned i=0; i < in.num_keys; i++) {
        ds_bulk_t kdata(local_keys_buffer.data()+keys_offset, local_keys_buffer.data()+keys_offset+key_sizes[i]);
        ds_bulk_t vdata(local_vals_buffer.data()+vals_offset, local_vals_buffer.data()+vals_offset+val_sizes[i]);
724
        db->put(kdata, vdata);
Matthieu Dorier's avatar
Matthieu Dorier committed
725 726 727 728 729 730 731 732 733 734
        keys_offset += key_sizes[i];
        vals_offset += val_sizes[i];
    }

    return;
}
DEFINE_MARGO_RPC_HANDLER(sdskv_put_multi_ult)

static void sdskv_length_ult(hg_handle_t handle)
{
Matthieu Dorier's avatar
Matthieu Dorier committed
735 736 737 738 739 740 741 742
    hg_return_t hret;
    length_in_t in;
    length_out_t out;

    margo_instance_id mid = margo_hg_handle_get_instance(handle);
    assert(mid);
    const struct hg_info* info = margo_get_info(handle);
    sdskv_provider_t svr_ctx = 
743
        (sdskv_provider_t)margo_registered_data(mid, info->id);
Matthieu Dorier's avatar
Matthieu Dorier committed
744 745
    if(!svr_ctx) {
        fprintf(stderr, "Error: SDSKV could not find provider\n"); 
746
        out.ret = SDSKV_ERR_UNKNOWN_PR;
Matthieu Dorier's avatar
Matthieu Dorier committed
747 748 749 750 751 752 753
        margo_respond(handle, &out);
        margo_destroy(handle);
        return;
    }

    hret = margo_get_input(handle, &in);
    if(hret != HG_SUCCESS) {
754
        out.ret = SDSKV_ERR_MERCURY;
Matthieu Dorier's avatar
Matthieu Dorier committed
755 756 757 758 759
        margo_respond(handle, &out);
        margo_destroy(handle);
        return;
    }

760
    ABT_rwlock_rdlock(svr_ctx->lock);
Matthieu Dorier's avatar
Matthieu Dorier committed
761 762
    auto it = svr_ctx->databases.find(in.db_id);
    if(it == svr_ctx->databases.end()) {
763
        ABT_rwlock_unlock(svr_ctx->lock);
764
        out.ret = SDSKV_ERR_UNKNOWN_DB;
Matthieu Dorier's avatar
Matthieu Dorier committed
765 766 767 768 769
        margo_respond(handle, &out);
        margo_free_input(handle, &in);
        margo_destroy(handle);
        return;
    }
770 771
    auto db = it->second;
    ABT_rwlock_unlock(svr_ctx->lock);
Matthieu Dorier's avatar
Matthieu Dorier committed
772
    
773
    ds_bulk_t kdata(in.key.data, in.key.data+in.key.size);
Matthieu Dorier's avatar
Matthieu Dorier committed
774 775

    ds_bulk_t vdata;
776
    if(db->get(kdata, vdata)) {
Matthieu Dorier's avatar
Matthieu Dorier committed
777
        out.size = vdata.size();
778
        out.ret  = SDSKV_SUCCESS;
Matthieu Dorier's avatar
Matthieu Dorier committed
779 780
    } else {
        out.size = 0;
781
        out.ret  = SDSKV_ERR_UNKNOWN_KEY;
Matthieu Dorier's avatar
Matthieu Dorier committed
782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802
    }

    margo_respond(handle, &out);
    margo_free_input(handle, &in);
    margo_destroy(handle); 

    return;
}
DEFINE_MARGO_RPC_HANDLER(sdskv_length_ult)

static void sdskv_get_ult(hg_handle_t handle)
{

    hg_return_t hret;
    get_in_t in;
    get_out_t out;

    margo_instance_id mid = margo_hg_handle_get_instance(handle);
    assert(mid);
    const struct hg_info* info = margo_get_info(handle);
    sdskv_provider_t svr_ctx = 
803
        (sdskv_provider_t)margo_registered_data(mid, info->id);
Matthieu Dorier's avatar
Matthieu Dorier committed
804 805
    if(!svr_ctx) {
        fprintf(stderr, "Error: SDSKV could not find provider\n"); 
806
        out.ret = SDSKV_ERR_UNKNOWN_PR;
Matthieu Dorier's avatar
Matthieu Dorier committed
807 808 809 810 811 812 813
        margo_respond(handle, &out);
        margo_destroy(handle);
        return;
    }

    hret = margo_get_input(handle, &in);
    if(hret != HG_SUCCESS) {
814
        out.ret = SDSKV_ERR_MERCURY;
815 816
        out.value.data = nullptr;
        out.value.size = 0;
Matthieu Dorier's avatar
Matthieu Dorier committed
817 818 819 820 821
        margo_respond(handle, &out);
        margo_destroy(handle);
        return;
    }

822
    ABT_rwlock_rdlock(svr_ctx->lock);
Matthieu Dorier's avatar
Matthieu Dorier committed
823 824
    auto it = svr_ctx->databases.find(in.db_id);
    if(it == svr_ctx->databases.end()) {
825
        ABT_rwlock_unlock(svr_ctx->lock);
826
        out.ret = SDSKV_ERR_UNKNOWN_DB;
827 828
        out.value.data = nullptr;
        out.value.size = 0;
Matthieu Dorier's avatar
Matthieu Dorier committed
829 830 831 832 833
        margo_respond(handle, &out);
        margo_free_input(handle, &in);
        margo_destroy(handle);
        return;
    }
834 835
    auto db = it->second;
    ABT_rwlock_unlock(svr_ctx->lock);
Matthieu Dorier's avatar
Matthieu Dorier committed
836
    
837
    ds_bulk_t kdata(in.key.data, in.key.data+in.key.size);
Matthieu Dorier's avatar
Matthieu Dorier committed
838 839

    ds_bulk_t vdata;
840
    if(db->get(kdata, vdata)) {
Matthieu Dorier's avatar
Matthieu Dorier committed
841
        if(vdata.size() <= in.vsize) {
842 843
            out.value.size = vdata.size();
            out.value.data = vdata.data();
844
            out.ret = SDSKV_SUCCESS;
Matthieu Dorier's avatar
Matthieu Dorier committed
845
        } else {
846 847
            out.value.size = 0;
            out.value.data = nullptr;
848
            out.ret = SDSKV_ERR_SIZE;
Matthieu Dorier's avatar
Matthieu Dorier committed
849 850
        }
    } else {
851 852
        out.value.size = 0;
        out.value.data = nullptr;
853
        out.ret   = SDSKV_ERR_UNKNOWN_KEY;
Matthieu Dorier's avatar
Matthieu Dorier committed
854 855 856 857 858 859 860 861 862 863
    }

    margo_respond(handle, &out);
    margo_free_input(handle, &in);
    margo_destroy(handle); 

    return;
}
DEFINE_MARGO_RPC_HANDLER(sdskv_get_ult)

Matthieu Dorier's avatar
Matthieu Dorier committed
864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897
static void sdskv_get_multi_ult(hg_handle_t handle)
{

    hg_return_t hret;
    get_multi_in_t in;
    get_multi_out_t out;
    out.ret = SDSKV_SUCCESS;
    std::vector<char> local_keys_buffer;
    std::vector<char> local_vals_buffer;
    hg_bulk_t local_keys_bulk_handle;
    hg_bulk_t local_vals_bulk_handle;

    auto r1 = at_exit([&handle]() { margo_destroy(handle); });
    auto r2 = at_exit([&handle,&out]() { margo_respond(handle, &out); });

    /* get margo instance and provider */
    margo_instance_id mid = margo_hg_handle_get_instance(handle);
    const struct hg_info* info = margo_get_info(handle);
    sdskv_provider_t svr_ctx = 
        (sdskv_provider_t)margo_registered_data(mid, info->id);
    if(!svr_ctx) {
        out.ret = SDSKV_ERR_UNKNOWN_PR;
        return;
    }

    /* deserialize input */
    hret = margo_get_input(handle, &in);
    if(hret != HG_SUCCESS) {
        out.ret = SDSKV_ERR_MERCURY;
        return;
    }
    auto r3 = at_exit([&handle,&in]() { margo_free_input(handle, &in); });

    /* find the target database */
898
    ABT_rwlock_rdlock(svr_ctx->lock);
Matthieu Dorier's avatar
Matthieu Dorier committed
899 900
    auto it = svr_ctx->databases.find(in.db_id);
    if(it == svr_ctx->databases.end()) {
901
        ABT_rwlock_unlock(svr_ctx->lock);
Matthieu Dorier's avatar
Matthieu Dorier committed
902 903 904
        out.ret = SDSKV_ERR_UNKNOWN_DB;
        return;
    }
905 906
    auto db = it->second;
    ABT_rwlock_unlock(svr_ctx->lock);
Matthieu Dorier's avatar
Matthieu Dorier committed
907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965

    /* allocate buffers to receive the keys */
    local_keys_buffer.resize(in.keys_bulk_size);
    std::vector<void*> keys_addr(1);
    keys_addr[0] = (void*)local_keys_buffer.data();
    
    /* create bulk handle to receive key sizes and packed keys */
    hret = margo_bulk_create(mid, 1, keys_addr.data(), &in.keys_bulk_size,
            HG_BULK_WRITE_ONLY, &local_keys_bulk_handle);
    if(hret != HG_SUCCESS) {
        out.ret = SDSKV_ERR_MERCURY;
        return;
    }
    auto r6 = at_exit([&local_keys_bulk_handle]() { margo_bulk_free(local_keys_bulk_handle); });

    /* allocate buffer to send/receive the values */
    local_vals_buffer.resize(in.vals_bulk_size);
    std::vector<void*> vals_addr(1);
    vals_addr[0] = (void*)local_vals_buffer.data();

    /* create bulk handle to receive max value sizes and to send values */
    hret = margo_bulk_create(mid, 1, vals_addr.data(), &in.vals_bulk_size,
            HG_BULK_READWRITE, &local_vals_bulk_handle);
    if(hret != HG_SUCCESS) {
        out.ret = SDSKV_ERR_MERCURY;
        return;
    }
    auto r7 = at_exit([&local_vals_bulk_handle]() { margo_bulk_free(local_vals_bulk_handle); });

    /* transfer keys */
    hret = margo_bulk_transfer(mid, HG_BULK_PULL, info->addr, in.keys_bulk_handle, 0,
            local_keys_bulk_handle, 0, in.keys_bulk_size);
    if(hret != HG_SUCCESS) {
        out.ret = SDSKV_ERR_MERCURY;
        return;
    }

    /* transfer sizes allocated by user for the values (beginning of value segment) */
    hret = margo_bulk_transfer(mid, HG_BULK_PULL, info->addr, in.vals_bulk_handle, 0,
            local_vals_bulk_handle, 0, in.num_keys*sizeof(hg_size_t));
    if(hret != HG_SUCCESS) {
        out.ret = SDSKV_ERR_MERCURY;
        return;
    }

    /* interpret beginning of the key buffer as a list of key sizes */
    hg_size_t* key_sizes = (hg_size_t*)local_keys_buffer.data();
    /* find beginning of packed keys */
    char* packed_keys = local_keys_buffer.data() + in.num_keys*sizeof(hg_size_t);
    /* interpret beginning of the value buffer as a list of value sizes */
    hg_size_t* val_sizes = (hg_size_t*)local_vals_buffer.data();
    /* find beginning of region where to pack values */
    char* packed_values = local_vals_buffer.data() + in.num_keys*sizeof(hg_size_t);

    /* go through the key/value pairs and get the values from the database */
    for(unsigned i=0; i < in.num_keys; i++) {
        ds_bulk_t kdata(packed_keys, packed_keys+key_sizes[i]);
        ds_bulk_t vdata;
        size_t client_allocated_value_size = val_sizes[i];
966
        if(db->get(kdata, vdata)) {
Matthieu Dorier's avatar
Matthieu Dorier committed
967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025
            if(vdata.size() > val_sizes[i]) {
                val_sizes[i] = 0;
            } else {
                val_sizes[i] = vdata.size();
                memcpy(packed_values, vdata.data(), val_sizes[i]);
            }
        } else {
            val_sizes[i] = 0;
        }
        packed_keys += key_sizes[i];
        packed_values += client_allocated_value_size;
    }

    /* do a PUSH operation to push back the values to the client */
    hret = margo_bulk_transfer(mid, HG_BULK_PUSH, info->addr, in.vals_bulk_handle, 0,
            local_vals_bulk_handle, 0, in.vals_bulk_size);
    if(hret != HG_SUCCESS) {
        out.ret = SDSKV_ERR_MERCURY;
        return;
    }

    return;
}
DEFINE_MARGO_RPC_HANDLER(sdskv_get_multi_ult)

static void sdskv_length_multi_ult(hg_handle_t handle)
{

    hg_return_t hret;
    length_multi_in_t in;
    length_multi_out_t out;
    out.ret = SDSKV_SUCCESS;
    std::vector<char> local_keys_buffer;
    std::vector<hg_size_t> local_vals_size_buffer;
    hg_bulk_t local_keys_bulk_handle;
    hg_bulk_t local_vals_size_bulk_handle;

    auto r1 = at_exit([&handle]() { margo_destroy(handle); });
    auto r2 = at_exit([&handle,&out]() { margo_respond(handle, &out); });

    /* get margo instance and provider */
    margo_instance_id mid = margo_hg_handle_get_instance(handle);
    const struct hg_info* info = margo_get_info(handle);
    sdskv_provider_t svr_ctx = 
        (sdskv_provider_t)margo_registered_data(mid, info->id);
    if(!svr_ctx) {
        out.ret = SDSKV_ERR_UNKNOWN_PR;
        return;
    }

    /* deserialize input */
    hret = margo_get_input(handle, &in);
    if(hret != HG_SUCCESS) {
        out.ret = SDSKV_ERR_MERCURY;
        return;
    }
    auto r3 = at_exit([&handle,&in]() { margo_free_input(handle, &in); });

    /* find the target database */
1026
    ABT_rwlock_rdlock(svr_ctx->lock);
Matthieu Dorier's avatar
Matthieu Dorier committed
1027 1028
    auto it = svr_ctx->databases.find(in.db_id);
    if(it == svr_ctx->databases.end()) {
1029
        ABT_rwlock_unlock(svr_ctx->lock);
Matthieu Dorier's avatar
Matthieu Dorier committed
1030 1031 1032
        out.ret = SDSKV_ERR_UNKNOWN_DB;
        return;
    }
1033 1034
    auto db = it->second;
    ABT_rwlock_unlock(svr_ctx->lock);
Matthieu Dorier's avatar
Matthieu Dorier committed
1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081

    /* allocate buffers to receive the keys */
    local_keys_buffer.resize(in.keys_bulk_size);
    std::vector<void*> keys_addr(1);
    keys_addr[0] = (void*)local_keys_buffer.data();
    
    /* create bulk handle to receive key sizes and packed keys */
    hret = margo_bulk_create(mid, 1, keys_addr.data(), &in.keys_bulk_size,
            HG_BULK_WRITE_ONLY, &local_keys_bulk_handle);
    if(hret != HG_SUCCESS) {
        out.ret = SDSKV_ERR_MERCURY;
        return;
    }
    auto r6 = at_exit([&local_keys_bulk_handle]() { margo_bulk_free(local_keys_bulk_handle); });

    /* allocate buffer to send the values */
    local_vals_size_buffer.resize(in.num_keys);
    std::vector<void*> vals_sizes_addr(1);
    hg_size_t local_vals_size_buffer_size = in.num_keys * sizeof(hg_size_t);
    vals_sizes_addr[0] = (void*)local_vals_size_buffer.data();

    /* create bulk handle to send values sizes */
    hret = margo_bulk_create(mid, 1, vals_sizes_addr.data(), &local_vals_size_buffer_size,
            HG_BULK_READ_ONLY, &local_vals_size_bulk_handle);
    if(hret != HG_SUCCESS) {
        out.ret = SDSKV_ERR_MERCURY;
        return;
    }
    auto r7 = at_exit([&local_vals_size_bulk_handle]() { margo_bulk_free(local_vals_size_bulk_handle); });

    /* transfer keys */
    hret = margo_bulk_transfer(mid, HG_BULK_PULL, info->addr, in.keys_bulk_handle, 0,
            local_keys_bulk_handle, 0, in.keys_bulk_size);
    if(hret != HG_SUCCESS) {
        out.ret = SDSKV_ERR_MERCURY;
        return;
    }

    /* interpret beginning of the key buffer as a list of key sizes */
    hg_size_t* key_sizes = (hg_size_t*)local_keys_buffer.data();
    /* find beginning of packed keys */
    char* packed_keys = local_keys_buffer.data() + in.num_keys*sizeof(hg_size_t);

    /* go through the key/value pairs and get the values from the database */
    for(unsigned i=0; i < in.num_keys; i++) {
        ds_bulk_t kdata(packed_keys, packed_keys+key_sizes[i]);
        ds_bulk_t vdata;
1082
        if(db->get(kdata, vdata)) {
Matthieu Dorier's avatar
Matthieu Dorier committed
1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101
            local_vals_size_buffer[i] = vdata.size();
        } else {
            local_vals_size_buffer[i] = 0;
        }
        packed_keys += key_sizes[i];
    }

    /* do a PUSH operation to push back the value sizes to the client */
    hret = margo_bulk_transfer(mid, HG_BULK_PUSH, info->addr, in.vals_size_bulk_handle, 0,
            local_vals_size_bulk_handle, 0, local_vals_size_buffer_size);
    if(hret != HG_SUCCESS) {
        out.ret = SDSKV_ERR_MERCURY;
        return;
    }

    return;
}
DEFINE_MARGO_RPC_HANDLER(sdskv_length_multi_ult)

Matthieu Dorier's avatar
Matthieu Dorier committed
1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114

static void sdskv_bulk_put_ult(hg_handle_t handle)
{

    hg_return_t hret;
    bulk_put_in_t in;
    bulk_put_out_t out;
    hg_bulk_t bulk_handle;

    margo_instance_id mid = margo_hg_handle_get_instance(handle);
    assert(mid);
    const struct hg_info* info = margo_get_info(handle);
    sdskv_provider_t svr_ctx = 
1115
        (sdskv_provider_t)margo_registered_data(mid, info->id);
Matthieu Dorier's avatar
Matthieu Dorier committed
1116
    if(!svr_ctx) {
Matthieu Dorier's avatar
Matthieu Dorier committed
1117
        fprintf(stderr, "Error (sdskv_bulk_put_ult): SDSKV could not find provider\n"); 
1118
        out.ret = SDSKV_ERR_UNKNOWN_PR;
Matthieu Dorier's avatar
Matthieu Dorier committed
1119 1120 1121 1122 1123 1124 1125
        margo_respond(handle, &out);
        margo_destroy(handle);
        return;
    }

    hret = margo_get_input(handle, &in);
    if(hret != HG_SUCCESS) {
1126
        out.ret = SDSKV_ERR_MERCURY;
Matthieu Dorier's avatar
Matthieu Dorier committed
1127 1128 1129 1130 1131
        margo_respond(handle, &out);
        margo_destroy(handle);
        return;
    }

1132
    ABT_rwlock_rdlock(svr_ctx->lock);
1133
    auto it = svr_ctx->databases.find(in.db_id);
Matthieu Dorier's avatar
Matthieu Dorier committed
1134
    if(it == svr_ctx->databases.end()) {
1135
        ABT_rwlock_unlock(svr_ctx->lock);
1136
        out.ret = SDSKV_ERR_UNKNOWN_DB;
Matthieu Dorier's avatar
Matthieu Dorier committed
1137 1138 1139 1140 1141
        margo_respond(handle, &out);
        margo_free_input(handle, &in);
        margo_destroy(handle);
        return;
    }
1142 1143
    auto db = it->second;
    ABT_rwlock_unlock(svr_ctx->lock);
1144

1145
    ds_bulk_t vdata(in.vsize);
Matthieu Dorier's avatar
Matthieu Dorier committed
1146

1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171
    if(in.vsize > 0) {

        void *buffer = (void*)vdata.data();
        hg_size_t size = vdata.size();
        hret = margo_bulk_create(mid, 1, (void**)&buffer, &size,
                HG_BULK_WRITE_ONLY, &bulk_handle);
        if(hret != HG_SUCCESS) {
            out.ret = SDSKV_ERR_MERCURY;
            margo_respond(handle, &out);
            margo_free_input(handle, &in);
            margo_destroy(handle);
            return;
        }

        hret = margo_bulk_transfer(mid, HG_BULK_PULL, info->addr, in.handle, 0,
                bulk_handle, 0, vdata.size());
        if(hret != HG_SUCCESS) {
            out.ret = SDSKV_ERR_MERCURY;
            margo_respond(handle, &out);
            margo_free_input(handle, &in);
            margo_bulk_free(bulk_handle);
            margo_destroy(handle);
            return;
        }

Matthieu Dorier's avatar
Matthieu Dorier committed
1172
        margo_bulk_free(bulk_handle);
1173

Matthieu Dorier's avatar
Matthieu Dorier committed
1174 1175
    }

1176
    ds_bulk_t kdata(in.key.data, in.key.data+in.key.size);
Matthieu Dorier's avatar
Matthieu Dorier committed
1177

1178
    auto b = db->put(kdata, vdata);
Matthieu Dorier's avatar
Matthieu Dorier committed
1179 1180

    if(b) {
1181
        out.ret = SDSKV_SUCCESS;
Matthieu Dorier's avatar
Matthieu Dorier committed
1182
    } else {
1183
        out.ret = SDSKV_ERR_PUT;
Matthieu Dorier's avatar
Matthieu Dorier committed
1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205
    }

    margo_respond(handle, &out);
    margo_free_input(handle, &in);
    margo_destroy(handle);

    return;
}
DEFINE_MARGO_RPC_HANDLER(sdskv_bulk_put_ult)

static void sdskv_bulk_get_ult(hg_handle_t handle)
{

    hg_return_t hret;
    bulk_get_in_t in;
    bulk_get_out_t out;
    hg_bulk_t bulk_handle;

    margo_instance_id mid = margo_hg_handle_get_instance(handle);
    assert(mid);
    const struct hg_info* info = margo_get_info(handle);
    sdskv_provider_t svr_ctx = 
1206
        (sdskv_provider_t)margo_registered_data(mid, info->id);
Matthieu Dorier's avatar
Matthieu Dorier committed
1207
    if(!svr_ctx) {
Matthieu Dorier's avatar
Matthieu Dorier committed
1208
        fprintf(stderr, "Error (sdskv_bulk_get_ult): SDSKV could not find provider\n"); 
1209
        out.ret = SDSKV_ERR_UNKNOWN_PR;
Matthieu Dorier's avatar
Matthieu Dorier committed
1210 1211 1212 1213 1214 1215 1216
        margo_respond(handle, &out);
        margo_destroy(handle);
        return;
    }

    hret = margo_get_input(handle, &in);
    if(hret != HG_SUCCESS) {
1217
        out.ret = SDSKV_ERR_MERCURY;
Matthieu Dorier's avatar
Matthieu Dorier committed
1218 1219 1220 1221 1222
        margo_respond(handle, &out);
        margo_destroy(handle);
        return;
    }

1223
    ABT_rwlock_rdlock(svr_ctx->lock);
1224
    auto it = svr_ctx->databases.find(in.db_id);
Matthieu Dorier's avatar
Matthieu Dorier committed
1225
    if(it == svr_ctx->databases.end()) {
1226
        ABT_rwlock_unlock(svr_ctx->lock);
1227
        out.ret = SDSKV_ERR_UNKNOWN_DB;
Matthieu Dorier's avatar
Matthieu Dorier committed
1228 1229 1230 1231 1232
        margo_respond(handle, &out);
        margo_free_input(handle, &in);
        margo_destroy(handle);
        return;
    }
1233 1234
    auto db = it->second;
    ABT_rwlock_unlock(svr_ctx->lock);
Matthieu Dorier's avatar
Matthieu Dorier committed
1235
    
1236
    ds_bulk_t kdata(in.key.data, in.key.data+in.key.size);
Matthieu Dorier's avatar
Matthieu Dorier committed
1237 1238

    ds_bulk_t vdata;
1239
    auto b = db->get(kdata, vdata);
Matthieu Dorier's avatar
Matthieu Dorier committed
1240

1241
    if(!b || vdata.size() > in.vsize) {
Matthieu Dorier's avatar
Matthieu Dorier committed
1242
        out.size = 0;
1243
        out.ret = SDSKV_ERR_SIZE;
Matthieu Dorier's avatar
Matthieu Dorier committed
1244 1245 1246 1247 1248 1249 1250 1251
        margo_respond(handle, &out);
        margo_free_input(handle, &in);
        margo_destroy(handle);
        return;
    }

    void *buffer = (void*)vdata.data();
    hg_size_t size = vdata.size();
1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274
    if(size > 0) {
        hret = margo_bulk_create(mid, 1, (void**)&buffer, &size,
                HG_BULK_READ_ONLY, &bulk_handle);
        if(hret != HG_SUCCESS) {
            out.size = 0;
            out.ret = SDSKV_ERR_MERCURY;
            margo_respond(handle, &out);
            margo_free_input(handle, &in);
            margo_destroy(handle);
            return;
        }

        hret = margo_bulk_transfer(mid, HG_BULK_PUSH, info->addr, in.handle, 0,
                bulk_handle, 0, vdata.size());
        if(hret != HG_SUCCESS) {
            out.size = 0;
            out.ret = SDSKV_ERR_MERCURY;
            margo_respond(handle, &out);
            margo_free_input(handle, &in);
            margo_bulk_free(bulk_handle);
            margo_destroy(handle);
            return;
        }
Matthieu Dorier's avatar
Matthieu Dorier committed
1275 1276 1277 1278

        margo_bulk_free(bulk_handle);
    }

1279
    out.size = size;
1280
    out.ret  = SDSKV_SUCCESS;
Matthieu Dorier's avatar
Matthieu Dorier committed
1281 1282 1283 1284 1285 1286 1287 1288 1289

    margo_respond(handle, &out);
    margo_free_input(handle, &in);
    margo_destroy(handle);

    return;
}
DEFINE_MARGO_RPC_HANDLER(sdskv_bulk_get_ult)

Matthieu Dorier's avatar
Matthieu Dorier committed
1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300
static void sdskv_erase_ult(hg_handle_t handle)
{

    hg_return_t hret;
    erase_in_t in;
    erase_out_t out;

    margo_instance_id mid = margo_hg_handle_get_instance(handle);
    assert(mid);
    const struct hg_info* info = margo_get_info(handle);
    sdskv_provider_t svr_ctx = 
1301
        (sdskv_provider_t)margo_registered_data(mid, info->id);
Matthieu Dorier's avatar
Matthieu Dorier committed
1302
    if(!svr_ctx) {
Matthieu Dorier's avatar
Matthieu Dorier committed
1303
        fprintf(stderr, "Error (sdskv_erase_ult): SDSKV could not find provider\n"); 
1304
        out.ret = SDSKV_ERR_UNKNOWN_PR;
Matthieu Dorier's avatar
Matthieu Dorier committed
1305 1306 1307 1308 1309 1310 1311
        margo_respond(handle, &out);
        margo_destroy(handle);
        return;
    }

    hret = margo_get_input(handle, &in);
    if(hret != HG_SUCCESS) {
1312
        out.ret = SDSKV_ERR_MERCURY;
Matthieu Dorier's avatar
Matthieu Dorier committed
1313 1314 1315 1316 1317
        margo_respond(handle, &out);
        margo_destroy(handle);
        return;
    }

1318
    ABT_rwlock_rdlock(svr_ctx->lock);
Matthieu Dorier's avatar
Matthieu Dorier committed
1319 1320
    auto it = svr_ctx->databases.find(in.db_id);
    if(it == svr_ctx->databases.end()) {
1321
        ABT_rwlock_unlock(svr_ctx->lock);
1322
        out.ret = SDSKV_ERR_UNKNOWN_DB;
Matthieu Dorier's avatar
Matthieu Dorier committed
1323 1324 1325 1326 1327
        margo_respond(handle, &out);
        margo_free_input(handle, &in);
        margo_destroy(handle);
        return;
    }
1328 1329
    auto db = it->second;
    ABT_rwlock_unlock(svr_ctx->lock);
Matthieu Dorier's avatar
Matthieu Dorier committed
1330
    
1331
    ds_bulk_t kdata(in.key.data, in.key.data+in.key.size);
Matthieu Dorier's avatar
Matthieu Dorier committed
1332

1333
    if(db->erase(kdata)) {
1334
        out.ret   = SDSKV_SUCCESS;
Matthieu Dorier's avatar
Matthieu Dorier committed
1335
    } else {
1336
        out.ret   = SDSKV_ERR_ERASE;
Matthieu Dorier's avatar
Matthieu Dorier committed
1337 1338 1339 1340 1341 1342 1343 1344 1345 1346
    }

    margo_respond(handle, &out);
    margo_free_input(handle, &in);
    margo_destroy(handle); 

    return;
}
DEFINE_MARGO_RPC_HANDLER(sdskv_erase_ult)

Matthieu Dorier's avatar
Matthieu Dorier committed
1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378
static void sdskv_erase_multi_ult(hg_handle_t handle)
{

    hg_return_t hret;
    erase_multi_in_t in;
    erase_multi_out_t out;
    out.ret = SDSKV_SUCCESS;
    std::vector<char> local_keys_buffer;
    hg_bulk_t local_keys_bulk_handle;

    auto r1 = at_exit([&handle]() { margo_destroy(handle); });
    auto r2 = at_exit([&handle,&out]() { margo_respond(handle, &out); });

    /* get margo instance and provider */
    margo_instance_id mid = margo_hg_handle_get_instance(handle);
    const struct hg_info* info = margo_get_info(handle);
    sdskv_provider_t svr_ctx = 
        (sdskv_provider_t)margo_registered_data(mid, info->id);
    if(!svr_ctx) {
        out.ret = SDSKV_ERR_UNKNOWN_PR;
        return;
    }

    /* deserialize input */
    hret = margo_get_input(handle, &in);
    if(hret != HG_SUCCESS) {
        out.ret = SDSKV_ERR_MERCURY;
        return;
    }
    auto r3 = at_exit([&handle,&in]() { margo_free_input(handle, &in); });

    /* find the target database */
1379
    ABT_rwlock_rdlock(svr_ctx->lock);
Matthieu Dorier's avatar
Matthieu Dorier committed
1380 1381
    auto it = svr_ctx->databases.find(in.db_id);
    if(it == svr_ctx->databases.end()) {
1382
        ABT_rwlock_unlock(svr_ctx->lock);
Matthieu Dorier's avatar
Matthieu Dorier committed
1383 1384 1385
        out.ret = SDSKV_ERR_UNKNOWN_DB;
        return;
    }
1386 1387
    auto db = it->second;
    ABT_rwlock_unlock(svr_ctx->lock);
Matthieu Dorier's avatar
Matthieu Dorier committed
1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410

    /* allocate buffers to receive the keys */
    local_keys_buffer.resize(in.keys_bulk_size);
    std::vector<void*> keys_addr(1);
    keys_addr[0] = (void*)local_keys_buffer.data();
    
    /* create bulk handle to receive key sizes and packed keys */
    hret = margo_bulk_create(mid, 1, keys_addr.data(), &in.keys_bulk_size,
            HG_BULK_WRITE_ONLY, &local_keys_bulk_handle);
    if(hret != HG_SUCCESS) {
        out.ret = SDSKV_ERR_MERCURY;
        return;
    }
    auto r6 = at_exit([&local_keys_bulk_handle]() { margo_bulk_free(local_keys_bulk_handle); });

    /* interpret beginning of the key buffer as a list of key sizes */
    hg_size_t* key_sizes = (hg_size_t*)local_keys_buffer.data();
    /* find beginning of packed keys */
    char* packed_keys = local_keys_buffer.data() + in.num_keys*sizeof(hg_size_t);

    /* go through the key/value pairs and erase them */
    for(unsigned i=0; i < in.num_keys; i++) {
        ds_bulk_t kdata(packed_keys, packed_keys+key_sizes[i]);
1411
        db->erase(kdata);
Matthieu Dorier's avatar
Matthieu Dorier committed
1412 1413 1414 1415 1416 1417 1418
        packed_keys += key_sizes[i];
    }

    return;
}
DEFINE_MARGO_RPC_HANDLER(sdskv_erase_multi_ult)

1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431
static void sdskv_exists_ult(hg_handle_t handle)
{

    hg_return_t hret;
    exists_in_t in;
    exists_out_t out;

    margo_instance_id mid = margo_hg_handle_get_instance(handle);
    assert(mid);
    const struct hg_info* info = margo_get_info(handle);
    sdskv_provider_t svr_ctx = 
        (sdskv_provider_t)margo_registered_data(mid, info->id);
    if(!svr_ctx) {
Matthieu Dorier's avatar
Matthieu Dorier committed