Commit 7835a534 authored by Matthieu Dorier's avatar Matthieu Dorier

finished implementing multi-target

parent 55295b22
......@@ -38,21 +38,86 @@ int bake_makepool(
mode_t pool_mode);
/**
* Initializes a BAKE server instance.
* Initializes a BAKE provider.
*
* @param[in] mid Margo instance identifier
* @param[in] mplex_id Multiplex id
* @param[in] pool Pool on which to run the RPC handlers
* @param[in] pool_name path to PMEM backend file
* @param[in] target_name path to PMEM backend file
* @param[out] provider resulting provider
* @returns 0 on success, -1 otherwise
*/
int bake_provider_register(
margo_instance_id mid,
uint32_t mplex_id,
ABT_pool pool,
const char *pool_name,
bake_provider_t* provider);
margo_instance_id mid,
uint8_t mplex_id,
ABT_pool pool,
bake_provider_t* provider);
/**
* Makes the provider start managing a target.
* The target must have been previously created with bake_makepool,
* and it should not be managed by another provider (whether in this
* proccess or another).
*
* @param provider Bake provider
* @param target_name path to pmem target
* @param target_id resulting id identifying the target
*
* @return 0 on success, -1 on failure
*/
int bake_provider_add_storage_target(
bake_provider_t provider,
const char *target_name,
bake_target_id_t* target_id);
/**
* Makes the provider stop managing a target.
*
* @param provider Bake provider
* @param target_id id of the target to remove
*
* @return 0 on success, -1 on failure
*/
int bake_provider_remove_storage_target(
bake_provider_t provider,
bake_target_id_t target_id);
/**
* Removes all the targets associated with a provider.
*
* @param provider Bake provider
*
* @return 0 on success, -1 on failure
*/
int bake_provider_remove_all_storage_targets(
bake_provider_t provider);
/**
* Returns the number of targets that this provider manages.
*
* @param provider Bake provider
* @param num_targets resulting number of targets
*
* @return 0 on success, -1 on failure
*/
int bake_provider_count_storage_targets(
bake_provider_t provider,
uint64_t* num_targets);
/**
* List the target ids of the targets managed by this provider.
* The targets array must be pre-allocated with at least enough
* space to hold all the targets (use bake_provider_count_storage_targets
* to know how many storage targets are managed).
*
* @param provider Bake provider
* @param targets resulting targer ids
*
* @return 0 on success, -1 on failure
*/
int bake_provider_list_storage_targets(
bake_provider_t provider,
bake_target_id_t* targets);
#ifdef __cplusplus
}
......
......@@ -48,40 +48,61 @@ static int bake_client_register(bake_client_t client, margo_instance_id mid)
{
client->mid = mid;
/* register RPCs */
client->bake_probe_id =
MARGO_REGISTER(mid, "bake_probe_rpc",
bake_probe_in_t, bake_probe_out_t, NULL);
client->bake_shutdown_id =
MARGO_REGISTER(mid, "bake_shutdown_rpc",
void, void, NULL);
client->bake_create_id =
MARGO_REGISTER(mid, "bake_create_rpc",
bake_create_in_t, bake_create_out_t, NULL);
client->bake_write_id =
MARGO_REGISTER(mid, "bake_write_rpc",
bake_write_in_t, bake_write_out_t, NULL);
client->bake_eager_write_id =
MARGO_REGISTER(mid, "bake_eager_write_rpc",
bake_eager_write_in_t, bake_eager_write_out_t, NULL);
client->bake_eager_read_id =
MARGO_REGISTER(mid, "bake_eager_read_rpc",
bake_eager_read_in_t, bake_eager_read_out_t, NULL);
client->bake_persist_id =
MARGO_REGISTER(mid, "bake_persist_rpc",
bake_persist_in_t, bake_persist_out_t, NULL);
client->bake_create_write_persist_id =
MARGO_REGISTER(mid, "bake_create_write_persist_rpc",
bake_create_write_persist_in_t, bake_create_write_persist_out_t, NULL);
client->bake_get_size_id =
MARGO_REGISTER(mid, "bake_get_size_rpc",
bake_get_size_in_t, bake_get_size_out_t, NULL);
client->bake_read_id =
MARGO_REGISTER(mid, "bake_read_rpc",
bake_read_in_t, bake_read_out_t, NULL);
client->bake_noop_id =
MARGO_REGISTER(mid, "bake_noop_rpc",
void, void, NULL);
/* check if RPCs have already been registered */
hg_bool_t flag;
hg_id_t id;
margo_registered_name(mid, "bake_probe_rpc", &id, &flag);
if(flag == HG_TRUE) { /* RPCs already registered */
margo_registered_name(mid, "bake_probe_rpc", &client->bake_probe_id, &flag);
margo_registered_name(mid, "bake_shutdown_rpc", &client->bake_shutdown_id, &flag);
margo_registered_name(mid, "bake_create_rpc", &client->bake_create_id, &flag);
margo_registered_name(mid, "bake_write_rpc", &client->bake_write_id, &flag);
margo_registered_name(mid, "bake_eager_write_rpc", &client->bake_eager_write_id, &flag);
margo_registered_name(mid, "bake_eager_read_rpc", &client->bake_eager_read_id, &flag);
margo_registered_name(mid, "bake_persist_rpc", &client->bake_persist_id, &flag);
margo_registered_name(mid, "bake_create_write_persist_rpc", &client->bake_create_write_persist_id, &flag);
margo_registered_name(mid, "bake_get_size_rpc", &client->bake_get_size_id, &flag);
margo_registered_name(mid, "bake_read_rpc", &client->bake_read_id, &flag);
margo_registered_name(mid, "bake_noop_rpc", &client->bake_noop_id, &flag);
} else { /* RPCs not already registered */
client->bake_probe_id =
MARGO_REGISTER(mid, "bake_probe_rpc",
bake_probe_in_t, bake_probe_out_t, NULL);
client->bake_shutdown_id =
MARGO_REGISTER(mid, "bake_shutdown_rpc",
void, void, NULL);
client->bake_create_id =
MARGO_REGISTER(mid, "bake_create_rpc",
bake_create_in_t, bake_create_out_t, NULL);
client->bake_write_id =
MARGO_REGISTER(mid, "bake_write_rpc",
bake_write_in_t, bake_write_out_t, NULL);
client->bake_eager_write_id =
MARGO_REGISTER(mid, "bake_eager_write_rpc",
bake_eager_write_in_t, bake_eager_write_out_t, NULL);
client->bake_eager_read_id =
MARGO_REGISTER(mid, "bake_eager_read_rpc",
bake_eager_read_in_t, bake_eager_read_out_t, NULL);
client->bake_persist_id =
MARGO_REGISTER(mid, "bake_persist_rpc",
bake_persist_in_t, bake_persist_out_t, NULL);
client->bake_create_write_persist_id =
MARGO_REGISTER(mid, "bake_create_write_persist_rpc",
bake_create_write_persist_in_t, bake_create_write_persist_out_t, NULL);
client->bake_get_size_id =
MARGO_REGISTER(mid, "bake_get_size_rpc",
bake_get_size_in_t, bake_get_size_out_t, NULL);
client->bake_read_id =
MARGO_REGISTER(mid, "bake_read_rpc",
bake_read_in_t, bake_read_out_t, NULL);
client->bake_noop_id =
MARGO_REGISTER(mid, "bake_noop_rpc",
void, void, NULL);
}
return(0);
}
......@@ -160,10 +181,11 @@ int bake_probe(
if(max_targets == 0) {
*num_targets = out.num_targets;
} else {
uint64_t s = *num_targets > max_targets ? max_targets : *num_targets;
uint64_t s = out.num_targets > max_targets ? max_targets : out.num_targets;
if(s > 0) {
memcpy(bti, out.targets, sizeof(*bti)*s);
}
*num_targets = s;
}
}
......@@ -440,7 +462,8 @@ int bake_create(
}
ret = out.ret;
*rid = out.rid;
if(ret == 0)
*rid = out.rid;
margo_free_output(handle, &out);
margo_destroy(handle);
......@@ -519,7 +542,6 @@ int bake_create_write_persist(
hret = margo_create(provider->client->mid, provider->addr,
provider->client->bake_create_write_persist_id, &handle);
margo_set_target_id(handle, provider->mplex_id);
if(hret != HG_SUCCESS)
{
......@@ -527,6 +549,8 @@ int bake_create_write_persist(
return(-1);
}
margo_set_target_id(handle, provider->mplex_id);
hret = margo_forward(handle, &in);
if(hret != HG_SUCCESS)
{
......
......@@ -13,12 +13,18 @@
#include <libpmemobj.h>
#include <bake-server.h>
typedef enum {
MODE_TARGETS = 0,
MODE_PROVIDERS = 1
} mplex_mode_t;
struct options
{
char *listen_addr_str;
unsigned num_pools;
char **bake_pools;
char *host_file;
mplex_mode_t mplex_mode;
};
static void usage(int argc, char **argv)
......@@ -27,6 +33,7 @@ static void usage(int argc, char **argv)
fprintf(stderr, " listen_addr is the Mercury address to listen on\n");
fprintf(stderr, " bake_pool is the path to the BAKE pool\n");
fprintf(stderr, " [-f filename] to write the server address to a file\n");
fprintf(stderr, " [-m mode] multiplexing mode (providers or targets) for managing multiple pools (default is targets)\n");
fprintf(stderr, "Example: ./bake-server-daemon tcp://localhost:1234 /dev/shm/foo.dat /dev/shm/bar.dat\n");
return;
}
......@@ -38,13 +45,23 @@ static void parse_args(int argc, char **argv, struct options *opts)
memset(opts, 0, sizeof(*opts));
/* get options */
while((opt = getopt(argc, argv, "f:")) != -1)
while((opt = getopt(argc, argv, "f:m:")) != -1)
{
switch(opt)
{
case 'f':
opts->host_file = optarg;
break;
case 'm':
if(0 == strcmp(optarg, "targets"))
opts->mplex_mode = MODE_TARGETS;
else if(0 == strcmp(optarg, "providers"))
opts->mplex_mode = MODE_PROVIDERS;
else {
fprintf(stderr, "Unrecognized multiplexing mode \"%s\"\n", optarg);
exit(EXIT_FAILURE);
}
break;
default:
usage(argc, argv);
exit(EXIT_FAILURE);
......@@ -125,18 +142,62 @@ int main(int argc, char **argv)
}
/* initialize the BAKE server */
int i;
for(i=0; i< opts.num_pools; i++) {
ret = bake_provider_register(mid, i+1,
BAKE_ABT_POOL_DEFAULT, opts.bake_pools[i],
BAKE_PROVIDER_IGNORE);
}
if(opts.mplex_mode == MODE_PROVIDERS) {
int i;
for(i=0; i< opts.num_pools; i++) {
bake_provider_t provider;
bake_target_id_t tid;
ret = bake_provider_register(mid, i+1,
BAKE_ABT_POOL_DEFAULT,
&provider);
if(ret != 0)
{
fprintf(stderr, "Error: bake_provider_register()\n");
margo_finalize(mid);
return(-1);
}
ret = bake_provider_add_storage_target(provider, opts.bake_pools[i], &tid);
if(ret != 0)
{
fprintf(stderr, "Error: bake_provider_add_storage_target()\n");
margo_finalize(mid);
return(-1);
}
printf("Provider %d managing new target at multiplex id %d\n", i, i+1);
}
if(ret != 0)
{
fprintf(stderr, "Error: bake_provider_register()\n");
margo_finalize(mid);
return(-1);
} else {
int i;
bake_provider_t provider;
ret = bake_provider_register(mid, 1,
BAKE_ABT_POOL_DEFAULT,
&provider);
if(ret != 0)
{
fprintf(stderr, "Error: bake_provider_register()\n");
margo_finalize(mid);
return(-1);
}
for(i=0; i < opts.num_pools; i++) {
bake_target_id_t tid;
ret = bake_provider_add_storage_target(provider, opts.bake_pools[i], &tid);
if(ret != 0)
{
fprintf(stderr, "Error: bake_provider_add_storage_target()\n");
margo_finalize(mid);
return(-1);
}
printf("Provider %d managing new target at multiplex id %d\n", i, i+1);
}
}
/* suspend until the BAKE server gets a shutdown signal from the client */
......
This diff is collapsed.
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