Commit 66ede0bb authored by Matthieu Dorier's avatar Matthieu Dorier
Browse files

fixed C++ interface and benchmark

parent a616251c
/*
* (C) 2019 The University of Chicago
*
*
* See COPYRIGHT in top-level directory.
*/
#ifndef __BAKE_SERVER_HPP
......@@ -23,11 +23,8 @@ namespace bake {
* @param pool_size Pool size.
* @param pool_mode Mode.
*/
inline void makepool(
const std::string& pool_name,
size_t pool_size,
mode_t pool_mode) {
int ret = bake_makepool(pool_name.c_str(), pool_size, pool_mode);
inline void create_raw_target(const std::string& path, size_t size) {
int ret = bake_create_raw_target(path.c_str(), size);
_CHECK_RET(ret);
}
......@@ -39,14 +36,12 @@ class provider {
margo_instance_id m_mid = MARGO_INSTANCE_NULL;
bake_provider_t m_provider = NULL;
provider(
margo_instance_id mid,
uint16_t provider_id = 0,
ABT_pool pool = ABT_POOL_NULL)
provider(margo_instance_id mid,
uint16_t provider_id,
const bake_provider_init_info* args)
: m_mid(mid) {
int ret = bake_provider_register(mid, provider_id, pool, &m_provider);
int ret = bake_provider_register(mid, provider_id, args, &m_provider);
_CHECK_RET(ret);
}
static void finalize_callback(void* args) {
......@@ -62,13 +57,36 @@ class provider {
* @param mid Margo instance id.
* @param provider_id Provider id.
* @param pool Argobots pool.
* @param config JSON config.
* @param abtid ABT-IO instance.
*
* @return Pointer to newly created provider.
*/
static provider* create(margo_instance_id mid,
uint16_t provider_id = 0,
ABT_pool pool = BAKE_ABT_POOL_DEFAULT) {
auto p = new provider(mid, provider_id, pool);
ABT_pool pool = ABT_POOL_NULL,
const std::string& config = "",
abt_io_instance_id abtio = ABT_IO_INSTANCE_NULL) {
bake_provider_init_info args;
args.json_config = config.c_str();
args.rpc_pool = pool;
args.aid = abtio;
return create(mid, provider_id, &args);
}
/**
* @brief Factory method to create an instance of provider.
*
* @param mid Margo instance id.
* @param provider_id Provider id.
* @param args bake_provider_init_info structure.
*
* @return Pointer to newly created provider.
*/
static provider* create(margo_instance_id mid,
uint16_t provider_id,
const bake_provider_init_info* args = nullptr) {
auto p = new provider(mid, provider_id, args);
margo_provider_push_finalize_callback(mid, p, &finalize_callback, p);
return p;
}
......@@ -98,7 +116,7 @@ class provider {
*/
~provider() {
margo_provider_pop_finalize_callback(m_mid, this);
bake_provider_destroy(m_provider);
bake_provider_deregister(m_provider);
}
/**
......@@ -109,9 +127,9 @@ class provider {
*
* @return a target object.
*/
target add_storage_target(const std::string& target_name) {
target attach_target(const std::string& target_name) {
target t;
int ret = bake_provider_add_storage_target(
int ret = bake_provider_attach_target(
m_provider,
target_name.c_str(),
&(t.m_tid));
......@@ -119,6 +137,26 @@ class provider {
return t;
}
/**
* @brief Create a storage target and attach it to the provider.
*
* @param target_name Path to the target.
* @param size Target size.
*
* @return a target object.
*/
target create_target(const std::string& target_name, size_t size) {
target t;
int ret = bake_provider_create_target(
m_provider,
target_name.c_str(),
size,
&(t.m_tid));
_CHECK_RET(ret);
return t;
}
/**
* @brief Removes the storage target from the provider.
* This does not removes the storage target from the device, it
......@@ -126,16 +164,16 @@ class provider {
*
* @param t target to remove.
*/
void remove_storage_target(const target& t) {
int ret = bake_provider_remove_storage_target(m_provider, t.m_tid);
void detach_target(const target& t) {
int ret = bake_provider_detach_target(m_provider, t.m_tid);
_CHECK_RET(ret);
}
/**
* @brief Removes all the storage targets managed by the provider.
*/
void remove_all_storage_targets() {
int ret = bake_provider_remove_all_storage_targets(m_provider);
void detach_all_targets() {
int ret = bake_provider_detach_all_targets(m_provider);
_CHECK_RET(ret);
}
......@@ -144,9 +182,9 @@ class provider {
*
* @return number of storage targets.
*/
uint64_t count_storage_targets() const {
uint64_t count_targets() const {
uint64_t count;
int ret = bake_provider_count_storage_targets(m_provider, &count);
int ret = bake_provider_count_targets(m_provider, &count);
_CHECK_RET(ret);
return count;
}
......@@ -156,11 +194,11 @@ class provider {
*
* @return Vector of targets.
*/
std::vector<target> list_storage_targets() const {
uint64_t count = count_storage_targets();
std::vector<target> list_targets() const {
uint64_t count = count_targets();
std::vector<target> result(count);
std::vector<bake_target_id_t> tgts(count);
int ret = bake_provider_list_storage_targets(m_provider, tgts.data());
int ret = bake_provider_list_targets(m_provider, tgts.data());
_CHECK_RET(ret);
for(unsigned i=0; i < count; i++) {
result[i].m_tid = tgts[i];
......@@ -168,9 +206,12 @@ class provider {
return result;
}
void set_config(const std::string& key, const std::string& value) {
int ret = bake_provider_set_conf(m_provider, key.c_str(), value.c_str());
_CHECK_RET(ret);
std::string get_config() const {
char* cfg = bake_provider_get_config(m_provider);
if(!cfg) return std::string();
auto str_cfg = std::string(cfg);
free(cfg);
return str_cfg;
}
};
......
/*
* (C) 2019 The University of Chicago
*
*
* See COPYRIGHT in top-level directory.
*/
#ifndef __BAKE_HPP
......@@ -28,7 +28,12 @@ const char* const bake_error_messages[] = {
"Access out of bound",
"REMI error",
"Operation not supported",
"Forbidden operation"
"Forbidden operation",
"Unknown backend type",
"Backend I/O error",
"Entry does not exist",
"Entry already exists",
"Not enough memory"
};
class client;
......
......@@ -568,7 +568,6 @@ static void run_server(MPI_Comm comm, Json::Value& config) {
auto& server_config = config["server"];
bool use_progress_thread = server_config["use-progress-thread"].asBool();
int rpc_thread_count = server_config["rpc-thread-count"].asInt();
auto& provider_config = server_config["provider-config"];
mid = margo_init(protocol.c_str(), MARGO_SERVER_MODE, use_progress_thread, rpc_thread_count);
margo_enable_remote_shutdown(mid);
// serialize server address
......@@ -586,12 +585,7 @@ static void run_server(MPI_Comm comm, Json::Value& config) {
// initialize database
auto& target_config = server_config["target"];
std::string tgt_path = target_config["path"].asString();
provider->add_storage_target(tgt_path);
for(auto it = provider_config.begin(); it != provider_config.end(); it++) {
std::string key = it.key().asString();
std::string value = provider_config[key].asString();
provider->set_config(key.c_str(), value.c_str());
}
provider->attach_target(tgt_path);
// notify clients that the database is ready
MPI_Barrier(MPI_COMM_WORLD);
// wait for finalize
......
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