Commit c6439bcb authored by Matthieu Dorier's avatar Matthieu Dorier

added a helper function

parent 407271a7
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <margo.h> #include <margo.h>
#include <bake-client.h> #include <bake-client.h>
#include <sdskv-client.h> #include <sdskv-client.h>
#include <sdskv-server.h>
/* server-side utilities and routines. Clients are looking for either /* server-side utilities and routines. Clients are looking for either
* libmobject-store.h or librados-mobject-store.h */ * libmobject-store.h or librados-mobject-store.h */
...@@ -40,4 +41,14 @@ int mobject_provider_register( ...@@ -40,4 +41,14 @@ int mobject_provider_register(
const char *cluster_file, const char *cluster_file,
mobject_provider_t* provider); mobject_provider_t* provider);
/**
* Helper function that sets up the appropriate databases
* in a given SDSKV provider.
*
* @param sdskv_prov SDSKV provider
*
* @return 0 on success, negative error code on failure
*/
int mobject_sdskv_provider_setup(sdskv_provider_t sdskv_prov);
#endif #endif
...@@ -60,6 +60,7 @@ src_client_libmobject_store_la_LIBADD = src/omap-iter/libomap-iter.la \ ...@@ -60,6 +60,7 @@ src_client_libmobject_store_la_LIBADD = src/omap-iter/libomap-iter.la \
src_server_libmobject_server_la_SOURCES = \ src_server_libmobject_server_la_SOURCES = \
src/server/mobject-server.c \ src/server/mobject-server.c \
src/server/mobject-daemon-helper.c \
src/server/fake/fake-write-op.cpp \ src/server/fake/fake-write-op.cpp \
src/server/fake/fake-read-op.cpp \ src/server/fake/fake-read-op.cpp \
src/server/fake/fake-db.cpp \ src/server/fake/fake-db.cpp \
......
/*
* (C) 2017 The University of Chicago
*
* See COPYRIGHT in top-level directory.
*/
#include <unistd.h>
#include <sdskv-server.h>
#include "mobject-server.h"
#include "src/server/core/key-types.h"
#define ASSERT(__cond, __msg, ...) { if(!(__cond)) { fprintf(stderr, "[%s:%d] " __msg, __FILE__, __LINE__, __VA_ARGS__); exit(-1); } }
/* comparison functions for SDSKV */
static int oid_map_compare(const void*, size_t, const void*, size_t);
static int name_map_compare(const void*, size_t, const void*, size_t);
static int seg_map_compare(const void*, size_t, const void*, size_t);
static int omap_map_compare(const void*, size_t, const void*, size_t);
int mobject_sdskv_provider_setup(sdskv_provider_t sdskv_prov)
{
int ret;
/* SDSKV provider initialization */
sdskv_database_id_t oid_map_id, name_map_id, seg_map_id, omap_map_id;
ret = sdskv_provider_add_database(sdskv_prov, "oid_map", KVDB_MAP, &oid_map_compare, &oid_map_id);
ASSERT(ret == 0, "sdskv_provider_add_database() failed to add database \"oid_map\" (ret = %d)\n", ret);
ret = sdskv_provider_add_database(sdskv_prov, "name_map", KVDB_MAP, &name_map_compare, &name_map_id);
ASSERT(ret == 0, "sdskv_provider_add_database() failed to add database \"name_map\" (ret = %d)\n", ret);
ret = sdskv_provider_add_database(sdskv_prov, "seg_map", KVDB_MAP, &seg_map_compare, &seg_map_id);
ASSERT(ret == 0, "sdskv_provider_add_database() failed to add database \"seg_map\" (ret = %d)\n", ret);
ret = sdskv_provider_add_database(sdskv_prov, "omap_map", KVDB_MAP, &omap_map_compare, &omap_map_id);
ASSERT(ret == 0, "sdskv_provider_add_database() failed to add database \"omap_map\" (ret = %d)\n", ret);
}
static int oid_map_compare(const void* k1, size_t sk1, const void* k2, size_t sk2)
{
oid_t x = *((oid_t*)k1);
oid_t y = *((oid_t*)k2);
if(x == y) return 0;
if(x < y) return -1;
return 1;
}
static int name_map_compare(const void* k1, size_t sk1, const void* k2, size_t sk2)
{
const char* n1 = (const char*)k1;
const char* n2 = (const char*)k2;
return strcmp(n1,n2);
}
static int seg_map_compare(const void* k1, size_t sk1, const void* k2, size_t sk2)
{
const segment_key_t* seg1 = (const segment_key_t*)k1;
const segment_key_t* seg2 = (const segment_key_t*)k2;
if(seg1->oid < seg2->oid) return -1;
if(seg1->oid > seg2->oid) return 1;
if(seg1->timestamp > seg2->timestamp) return -1;
if(seg1->timestamp < seg2->timestamp) return 1;
return 0;
}
static int omap_map_compare(const void* k1, size_t sk1, const void* k2, size_t sk2)
{
const omap_key_t* ok1 = (const omap_key_t*)k1;
const omap_key_t* ok2 = (const omap_key_t*)k2;
if(ok1->oid < ok2->oid) return -1;
if(ok1->oid > ok2->oid) return 1;
return strcmp(ok1->key, ok2->key);
}
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
#include <sdskv-server.h> #include <sdskv-server.h>
#include "mobject-server.h" #include "mobject-server.h"
#include "src/server/core/key-types.h"
#define ASSERT(__cond, __msg, ...) { if(!(__cond)) { fprintf(stderr, "[%s:%d] " __msg, __FILE__, __LINE__, __VA_ARGS__); exit(-1); } } #define ASSERT(__cond, __msg, ...) { if(!(__cond)) { fprintf(stderr, "[%s:%d] " __msg, __FILE__, __LINE__, __VA_ARGS__); exit(-1); } }
...@@ -41,12 +40,6 @@ static void finalize_ssg_cb(void* data); ...@@ -41,12 +40,6 @@ static void finalize_ssg_cb(void* data);
static void finalize_bake_client_cb(void* data); static void finalize_bake_client_cb(void* data);
static void finalize_sdskv_client_cb(void* data); static void finalize_sdskv_client_cb(void* data);
/* comparison functions for SDSKV */
static int oid_map_compare(const void*, size_t, const void*, size_t);
static int name_map_compare(const void*, size_t, const void*, size_t);
static int seg_map_compare(const void*, size_t, const void*, size_t);
static int omap_map_compare(const void*, size_t, const void*, size_t);
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
char *listen_addr; char *listen_addr;
...@@ -78,18 +71,6 @@ int main(int argc, char *argv[]) ...@@ -78,18 +71,6 @@ int main(int argc, char *argv[])
ret = ssg_init(mid); ret = ssg_init(mid);
ASSERT(ret == 0, "ssg_init() failed (ret = %d)\n", ret); ASSERT(ret == 0, "ssg_init() failed (ret = %d)\n", ret);
#if 0
// XXX group name and file should be defined in a config file
ssg_group_id_t gid = ssg_group_create_mpi("mobject-providers", MPI_COMM_WORLD, NULL, NULL);
ASSERT(gid != SSG_GROUP_ID_NULL, "%s", "ssg_group_create_mpi() failed");
ret = ssg_group_id_store("mobject.ssg", gid);
ASSERT(ret == 0, "ssg_group_id_store() failed (ret = %d)\n", ret);
margo_push_finalize_callback(mid, &finalize_ssg_cb, (void*)&gid);
/* Get self address */
ssg_member_id_t self_id = ssg_get_group_self_id(gid);
hg_addr_t self_addr = ssg_get_addr(gid, self_id);
#endif
hg_addr_t self_addr; hg_addr_t self_addr;
margo_addr_self(mid, &self_addr); margo_addr_self(mid, &self_addr);
...@@ -123,18 +104,10 @@ int main(int argc, char *argv[]) ...@@ -123,18 +104,10 @@ int main(int argc, char *argv[])
/* SDSKV provider initialization */ /* SDSKV provider initialization */
uint8_t sdskv_mplex_id = 1; uint8_t sdskv_mplex_id = 1;
sdskv_provider_t sdskv_prov; sdskv_provider_t sdskv_prov;
sdskv_database_id_t oid_map_id, name_map_id, seg_map_id, omap_map_id;
ret = sdskv_provider_register(mid, sdskv_mplex_id, SDSKV_ABT_POOL_DEFAULT, &sdskv_prov); ret = sdskv_provider_register(mid, sdskv_mplex_id, SDSKV_ABT_POOL_DEFAULT, &sdskv_prov);
ASSERT(ret == 0, "sdskv_provider_register() failed (ret = %d)\n", ret); ASSERT(ret == 0, "sdskv_provider_register() failed (ret = %d)\n", ret);
ret = sdskv_provider_add_database(sdskv_prov, "oid_map", KVDB_MAP, &oid_map_compare, &oid_map_id); ret = mobject_sdskv_provider_setup(sdskv_prov);
ASSERT(ret == 0, "sdskv_provider_add_database() failed to add database \"oid_map\" (ret = %d)\n", ret);
ret = sdskv_provider_add_database(sdskv_prov, "name_map", KVDB_MAP, &name_map_compare, &name_map_id);
ASSERT(ret == 0, "sdskv_provider_add_database() failed to add database \"name_map\" (ret = %d)\n", ret);
ret = sdskv_provider_add_database(sdskv_prov, "seg_map", KVDB_MAP, &seg_map_compare, &seg_map_id);
ASSERT(ret == 0, "sdskv_provider_add_database() failed to add database \"seg_map\" (ret = %d)\n", ret);
ret = sdskv_provider_add_database(sdskv_prov, "omap_map", KVDB_MAP, &omap_map_compare, &omap_map_id);
ASSERT(ret == 0, "sdskv_provider_add_database() failed to add database \"omap_map\" (ret = %d)\n", ret);
/* SDSKV provider handle initialization from self addr */ /* SDSKV provider handle initialization from self addr */
sdskv_client_data sdskv_clt_data; sdskv_client_data sdskv_clt_data;
...@@ -186,39 +159,3 @@ static void finalize_sdskv_client_cb(void* data) ...@@ -186,39 +159,3 @@ static void finalize_sdskv_client_cb(void* data)
sdskv_provider_handle_release(clt_data->provider_handle); sdskv_provider_handle_release(clt_data->provider_handle);
sdskv_client_finalize(clt_data->client); sdskv_client_finalize(clt_data->client);
} }
static int oid_map_compare(const void* k1, size_t sk1, const void* k2, size_t sk2)
{
oid_t x = *((oid_t*)k1);
oid_t y = *((oid_t*)k2);
if(x == y) return 0;
if(x < y) return -1;
return 1;
}
static int name_map_compare(const void* k1, size_t sk1, const void* k2, size_t sk2)
{
const char* n1 = (const char*)k1;
const char* n2 = (const char*)k2;
return strcmp(n1,n2);
}
static int seg_map_compare(const void* k1, size_t sk1, const void* k2, size_t sk2)
{
const segment_key_t* seg1 = (const segment_key_t*)k1;
const segment_key_t* seg2 = (const segment_key_t*)k2;
if(seg1->oid < seg2->oid) return -1;
if(seg1->oid > seg2->oid) return 1;
if(seg1->timestamp > seg2->timestamp) return -1;
if(seg1->timestamp < seg2->timestamp) return 1;
return 0;
}
static int omap_map_compare(const void* k1, size_t sk1, const void* k2, size_t sk2)
{
const omap_key_t* ok1 = (const omap_key_t*)k1;
const omap_key_t* ok2 = (const omap_key_t*)k2;
if(ok1->oid < ok2->oid) return -1;
if(ok1->oid > ok2->oid) return 1;
return strcmp(ok1->key, ok2->key);
}
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