Skip to content

Commit

Permalink
Unique names for data files.
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelkgutierrez committed May 10, 2018
1 parent 4f377c4 commit 0f56018
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 16 deletions.
3 changes: 2 additions & 1 deletion src/sdsdkv-client.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ struct sdsdkv_client : public personality {
if (rc != SDSKV_SUCCESS) return sdskv2irc(rc);
//
sdskv_database_id_t db_id;
rc = sdskv_open(kvph, m_config->db_name.c_str(), &db_id);
const std::string db_name = personality::m_get_db_name(i);
rc = sdskv_open(kvph, db_name.c_str(), &db_id);
if (rc != SDSKV_SUCCESS) return sdskv2irc(rc);
//
m_ph_dbs.push_back(std::make_pair(kvph, db_id));
Expand Down
3 changes: 0 additions & 3 deletions src/sdsdkv-config.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ class sdsdkv_iconfig {
//
std::string db_path;
//
std::string db_name;
//
std::string comm_protocol;
//
sdsdkv_iconfig(void) = default;
Expand All @@ -93,7 +91,6 @@ class sdsdkv_iconfig {
cmp_fn = config.cmp_fn;
group_name = string(config.group_name);
db_path = string(config.db_path);
db_name = string(config.db_name);
comm_protocol = string(config.comm_protocol);
//
return SDSDKV_SUCCESS;
Expand Down
16 changes: 14 additions & 2 deletions src/sdsdkv-mpi.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct sdsdkv_mpi {
MPI_Comm m_world_comm;
/** Personality communicator. */
MPI_Comm m_personality_comm;
/** My ID in world communicator. */
/** Size of world communicator. */
int m_world_size;
/** My ID in world communicator. */
int m_world_id;
Expand All @@ -36,6 +36,8 @@ struct sdsdkv_mpi {
int m_pgroup_id;
/** Server delegate's world_id. */
int m_server_delegate_world_id;
/** Total number of servers. */
int m_num_servers;
public:
//
sdsdkv_mpi(void)
Expand All @@ -45,7 +47,8 @@ struct sdsdkv_mpi {
, m_world_id(0)
, m_pgroup_size(0)
, m_pgroup_id(0)
, m_server_delegate_world_id(0) { }
, m_server_delegate_world_id(0)
, m_num_servers(0) { }
//
int
init(
Expand Down Expand Up @@ -89,6 +92,15 @@ struct sdsdkv_mpi {
m_world_comm
);
if (rc != MPI_SUCCESS) goto err;
// Share number of servers with world.
rc = MPI_Bcast(
&m_pgroup_size,
1,
MPI_INT,
m_server_delegate_world_id,
m_world_comm
);
if (rc != MPI_SUCCESS) goto err;
//
return SDSDKV_SUCCESS;
err:
Expand Down
11 changes: 11 additions & 0 deletions src/sdsdkv-personality.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,17 @@ class personality {
//
return result;
}
//
static std::string
m_get_db_name(int id)
{
// Database instance name prefix.
static const char db_prefix[] = "db";
const std::string ids = std::to_string(id);
const std::string dbp = std::string(db_prefix);
//
return dbp + ids;
}
public:
//
personality(void)
Expand Down
5 changes: 3 additions & 2 deletions src/sdsdkv-server.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,11 @@ struct sdsdkv_server : public personality {
int
m_keyval_add_db(void)
{
const int pid = m_mpi->get_pgroup_id();
const std::string db_name = personality::m_get_db_name(pid);
int rc = sdskv_provider_add_database(
m_provider,
// TODO(skg) make unique for each server.
m_config->db_name.c_str(),
db_name.c_str(),
m_config->db_path.c_str(),
sdsdkv_iconfig::get_real_db_type(m_config->db_type),
m_config->cmp_fn,
Expand Down
2 changes: 0 additions & 2 deletions src/sdsdkv.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,6 @@ typedef struct sdsdkv_config {
char *group_name;
/** If applicable, the path where database files will be written. */
char *db_path;
/** Database name. */
char *db_name;
/** Communication protocol. */
char *comm_protocol;
} sdsdkv_config;
Expand Down
14 changes: 8 additions & 6 deletions tests/trivial.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

#include "mpi.h"

#include <string>

#define ABORT(id, rc) \
do { \
abort_job(__LINE__, id, rc); \
Expand Down Expand Up @@ -47,14 +49,16 @@ main(int argc, char **argv)
erc = MPI_Comm_size(MPI_COMM_WORLD, &numpe);
if (erc != MPI_SUCCESS) ABORT(rank, erc);

char *db_path = getenv("PWD");
if (!db_path) db_path = (char *)"/tmp";
char *db_prefix = getenv("PWD");
if (!db_prefix) db_prefix = (char *)"/tmp";

std::string db_name = std::string(db_prefix) + "/db-name";

sdsdkv_config dkv_config = {
/* .init_comm = */
MPI_COMM_WORLD,
/* .personality = */
(rank == 0) ? SDSDKV_PERSONALITY_SERVER : SDSDKV_PERSONALITY_CLIENT,
(rank % 2 == 0) ? SDSDKV_PERSONALITY_SERVER : SDSDKV_PERSONALITY_CLIENT,
/* .hash_be = */
SDSDKV_HASHING_CH_PLACEMENT,
/* .db_type = */
Expand All @@ -64,9 +68,7 @@ main(int argc, char **argv)
/* .group_name = */
(char *)"groupname",
/* .db_path = */
db_path,
/* .db_name = */
(char *)"TEST-DB",
(char *)db_name.c_str(),
/* .comm_protocol */
(char *)"ofi+tcp",
};
Expand Down

0 comments on commit 0f56018

Please sign in to comment.