As per the earlier RFC, move the DB framework to orcm, thus removing it from the OMPI code repo
This commit was SVN r31586.
Этот коммит содержится в:
родитель
e20dae536c
Коммит
567ed25938
@ -1,33 +0,0 @@
|
||||
#
|
||||
# Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
|
||||
# Copyright (c) 2014 Intel, Inc. All rights reserved.
|
||||
# $COPYRIGHT$
|
||||
#
|
||||
# Additional copyrights may follow
|
||||
#
|
||||
# $HEADER$
|
||||
#
|
||||
|
||||
AM_CPPFLAGS = $(LTDLINCL)
|
||||
|
||||
# main library setup
|
||||
noinst_LTLIBRARIES = libmca_db.la
|
||||
libmca_db_la_SOURCES =
|
||||
|
||||
# pkgdata setup
|
||||
dist_ompidata_DATA =
|
||||
|
||||
# local files
|
||||
headers = db.h
|
||||
libmca_db_la_SOURCES += $(headers)
|
||||
|
||||
# Conditionally install the header files
|
||||
if WANT_INSTALL_HEADERS
|
||||
ortedir = $(ompiincludedir)/$(subdir)
|
||||
nobase_orte_HEADERS = $(headers)
|
||||
endif
|
||||
|
||||
include base/Makefile.am
|
||||
|
||||
distclean-local:
|
||||
rm -f base/static-components.h
|
@ -1,18 +0,0 @@
|
||||
#
|
||||
# Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
|
||||
# Copyright (c) 2012-2013 Los Alamos National Security, Inc. All rights reserved.
|
||||
# Copyright (c) 2014 Intel, Inc. All rights reserved.
|
||||
# $COPYRIGHT$
|
||||
#
|
||||
# Additional copyrights may follow
|
||||
#
|
||||
# $HEADER$
|
||||
#
|
||||
|
||||
headers += \
|
||||
base/base.h
|
||||
|
||||
libmca_db_la_SOURCES += \
|
||||
base/db_base_frame.c \
|
||||
base/db_base_select.c \
|
||||
base/db_base_stubs.c
|
@ -1,101 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
|
||||
* Copyright (c) 2012-2013 Los Alamos National Security, Inc. All rights reserved.
|
||||
* Copyright (c) 2013-2014 Intel, Inc. All rights reserved.
|
||||
* $COPYRIGHT$
|
||||
*
|
||||
* Additional copyrights may follow
|
||||
*
|
||||
* $HEADER$
|
||||
*/
|
||||
/** @file:
|
||||
*/
|
||||
|
||||
#ifndef MCA_DB_BASE_H
|
||||
#define MCA_DB_BASE_H
|
||||
|
||||
#include "orte_config.h"
|
||||
#include "orte/types.h"
|
||||
|
||||
#include "opal/mca/mca.h"
|
||||
#include "opal/mca/base/mca_base_framework.h"
|
||||
#include "opal/mca/event/event.h"
|
||||
#include "opal/class/opal_list.h"
|
||||
#include "opal/class/opal_pointer_array.h"
|
||||
#include "opal/dss/dss.h"
|
||||
|
||||
#include "orte/mca/db/db.h"
|
||||
|
||||
BEGIN_C_DECLS
|
||||
|
||||
ORTE_DECLSPEC extern mca_base_framework_t orte_db_base_framework;
|
||||
|
||||
/**
|
||||
* Select db modules for the specified handle
|
||||
*/
|
||||
ORTE_DECLSPEC int orte_db_base_select(void);
|
||||
|
||||
typedef struct {
|
||||
opal_list_t actives;
|
||||
opal_pointer_array_t handles;
|
||||
opal_event_base_t *ev_base;
|
||||
} orte_db_base_t;
|
||||
|
||||
typedef struct {
|
||||
opal_list_item_t super;
|
||||
orte_db_base_component_t *component;
|
||||
} orte_db_base_active_component_t;
|
||||
OBJ_CLASS_DECLARATION(orte_db_base_active_component_t);
|
||||
|
||||
typedef struct {
|
||||
opal_object_t super;
|
||||
opal_event_t ev;
|
||||
int dbhandle;
|
||||
orte_db_callback_fn_t cbfunc;
|
||||
void *cbdata;
|
||||
opal_list_t *properties;
|
||||
char *primary_key;
|
||||
char *key;
|
||||
opal_list_t *kvs;
|
||||
} orte_db_request_t;
|
||||
OBJ_CLASS_DECLARATION(orte_db_request_t);
|
||||
|
||||
typedef struct {
|
||||
opal_object_t super;
|
||||
orte_db_base_component_t *component;
|
||||
orte_db_base_module_t *module;
|
||||
} orte_db_handle_t;
|
||||
OBJ_CLASS_DECLARATION(orte_db_handle_t);
|
||||
|
||||
ORTE_DECLSPEC extern orte_db_base_t orte_db_base;
|
||||
|
||||
ORTE_DECLSPEC void orte_db_base_open(char *name,
|
||||
opal_list_t *properties,
|
||||
orte_db_callback_fn_t cbfunc,
|
||||
void *cbdata);
|
||||
ORTE_DECLSPEC void orte_db_base_close(int dbhandle,
|
||||
orte_db_callback_fn_t cbfunc,
|
||||
void *cbdata);
|
||||
ORTE_DECLSPEC void orte_db_base_store(int dbhandle,
|
||||
const char *primary_key,
|
||||
opal_list_t *kvs,
|
||||
orte_db_callback_fn_t cbfunc,
|
||||
void *cbdata);
|
||||
ORTE_DECLSPEC void orte_db_base_commit(int dbhandle,
|
||||
orte_db_callback_fn_t cbfunc,
|
||||
void *cbdata);
|
||||
ORTE_DECLSPEC void orte_db_base_fetch(int dbhandle,
|
||||
const char *primary_key,
|
||||
const char *key,
|
||||
opal_list_t *kvs,
|
||||
orte_db_callback_fn_t cbfunc,
|
||||
void *cbdata);
|
||||
ORTE_DECLSPEC void orte_db_base_remove_data(int dbhandle,
|
||||
const char *primary_key,
|
||||
const char *key,
|
||||
orte_db_callback_fn_t cbfunc,
|
||||
void *cbdata);
|
||||
|
||||
END_C_DECLS
|
||||
|
||||
#endif
|
@ -1,126 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
|
||||
* Copyright (c) 2012-2013 Los Alamos National Security, Inc. All rights reserved.
|
||||
* Copyright (c) 2014 Intel, Inc. All rights reserved.
|
||||
* $COPYRIGHT$
|
||||
*
|
||||
* Additional copyrights may follow
|
||||
*
|
||||
* $HEADER$
|
||||
*/
|
||||
|
||||
|
||||
#include "orte_config.h"
|
||||
#include "orte/constants.h"
|
||||
|
||||
#include "opal/mca/mca.h"
|
||||
#include "opal/util/output.h"
|
||||
#include "opal/mca/base/base.h"
|
||||
#include "opal/dss/dss_types.h"
|
||||
|
||||
#include "orte/runtime/orte_globals.h"
|
||||
|
||||
#include "orte/mca/db/base/base.h"
|
||||
|
||||
|
||||
/*
|
||||
* The following file was created by configure. It contains extern
|
||||
* dbments and the definition of an array of pointers to each
|
||||
* module's public mca_base_module_t struct.
|
||||
*/
|
||||
|
||||
#include "orte/mca/db/base/static-components.h"
|
||||
|
||||
orte_db_API_module_t orte_db = {
|
||||
orte_db_base_open,
|
||||
orte_db_base_close,
|
||||
orte_db_base_store,
|
||||
orte_db_base_commit,
|
||||
orte_db_base_fetch,
|
||||
orte_db_base_remove_data
|
||||
};
|
||||
orte_db_base_t orte_db_base;
|
||||
|
||||
static bool orte_db_base_create_evbase;
|
||||
|
||||
static int orte_db_base_register(mca_base_register_flag_t flags)
|
||||
{
|
||||
orte_db_base_create_evbase = false;
|
||||
mca_base_var_register("orte", "db", "base", "create_evbase",
|
||||
"Create a separate event base for processing db operations",
|
||||
MCA_BASE_VAR_TYPE_BOOL, NULL, 0, 0,
|
||||
OPAL_INFO_LVL_9,
|
||||
MCA_BASE_VAR_SCOPE_READONLY,
|
||||
&orte_db_base_create_evbase);
|
||||
return OPAL_SUCCESS;
|
||||
}
|
||||
|
||||
static int orte_db_base_frame_close(void)
|
||||
{
|
||||
orte_db_base_component_t *component;
|
||||
int i;
|
||||
orte_db_handle_t *hdl;
|
||||
|
||||
/* cleanup the globals */
|
||||
for (i=0; i < orte_db_base.handles.size; i++) {
|
||||
if (NULL != (hdl = (orte_db_handle_t*)opal_pointer_array_get_item(&orte_db_base.handles, i))) {
|
||||
OBJ_RELEASE(hdl);
|
||||
}
|
||||
}
|
||||
OBJ_DESTRUCT(&orte_db_base.handles);
|
||||
|
||||
/* cycle across all the active db components and let them cleanup - order
|
||||
* doesn't matter in this case
|
||||
*/
|
||||
while (NULL != (component = (orte_db_base_component_t*)opal_list_remove_first(&orte_db_base.actives))) {
|
||||
if (NULL != component->finalize) {
|
||||
component->finalize();
|
||||
}
|
||||
}
|
||||
OBJ_DESTRUCT(&orte_db_base.actives);
|
||||
|
||||
return mca_base_framework_components_close(&orte_db_base_framework, NULL);
|
||||
}
|
||||
|
||||
static int orte_db_base_frame_open(mca_base_open_flag_t flags)
|
||||
{
|
||||
OBJ_CONSTRUCT(&orte_db_base.actives, opal_list_t);
|
||||
OBJ_CONSTRUCT(&orte_db_base.handles, opal_pointer_array_t);
|
||||
opal_pointer_array_init(&orte_db_base.handles, 3, INT_MAX, 1);
|
||||
|
||||
if (orte_db_base_create_evbase) {
|
||||
/* create our own event base */
|
||||
/* spin off a progress thread for it */
|
||||
} else {
|
||||
/* tie us to the orte_event_base */
|
||||
orte_db_base.ev_base = orte_event_base;
|
||||
}
|
||||
|
||||
/* Open up all available components */
|
||||
return mca_base_framework_components_open(&orte_db_base_framework, flags);
|
||||
}
|
||||
|
||||
MCA_BASE_FRAMEWORK_DECLARE(orte, db, "ORTE Database Framework",
|
||||
orte_db_base_register,
|
||||
orte_db_base_frame_open,
|
||||
orte_db_base_frame_close,
|
||||
mca_db_base_static_components, 0);
|
||||
|
||||
static void req_con(orte_db_request_t *p)
|
||||
{
|
||||
p->properties = NULL;
|
||||
p->primary_key = NULL;
|
||||
p->key = NULL;
|
||||
p->kvs = NULL;
|
||||
}
|
||||
OBJ_CLASS_INSTANCE(orte_db_request_t,
|
||||
opal_object_t,
|
||||
req_con, NULL);
|
||||
|
||||
OBJ_CLASS_INSTANCE(orte_db_handle_t,
|
||||
opal_object_t,
|
||||
NULL, NULL);
|
||||
|
||||
OBJ_CLASS_INSTANCE(orte_db_base_active_component_t,
|
||||
opal_list_item_t,
|
||||
NULL, NULL);
|
@ -1,103 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
|
||||
* Copyright (c) 2012-2013 Los Alamos National Security, Inc. All rights reserved.
|
||||
* Copyright (c) 2013 Intel, Inc. All rights reserved.
|
||||
* $COPYRIGHT$
|
||||
*
|
||||
* Additional copyrights may follow
|
||||
*
|
||||
* $HEADER$
|
||||
*/
|
||||
|
||||
#include "orte_config.h"
|
||||
#include "orte/constants.h"
|
||||
|
||||
#include "opal/class/opal_list.h"
|
||||
#include "opal/mca/mca.h"
|
||||
#include "opal/mca/base/base.h"
|
||||
#include "opal/mca/base/mca_base_component_repository.h"
|
||||
#include "opal/util/output.h"
|
||||
|
||||
#include "orte/mca/db/base/base.h"
|
||||
|
||||
static bool selected = false;
|
||||
|
||||
int orte_db_base_select(void)
|
||||
{
|
||||
mca_base_component_list_item_t *cli;
|
||||
orte_db_base_component_t *component;
|
||||
orte_db_base_active_component_t *active, *ncomponent;
|
||||
bool inserted;
|
||||
|
||||
if (selected) {
|
||||
/* ensure we don't do this twice */
|
||||
return OPAL_SUCCESS;
|
||||
}
|
||||
selected = true;
|
||||
|
||||
/* Query all available components and ask if they have a module */
|
||||
OPAL_LIST_FOREACH(cli, &orte_db_base_framework.framework_components, mca_base_component_list_item_t) {
|
||||
component = (orte_db_base_component_t*)cli->cli_component;
|
||||
|
||||
opal_output_verbose(5, orte_db_base_framework.framework_output,
|
||||
"mca:db:select: checking available component %s",
|
||||
component->base_version.mca_component_name);
|
||||
|
||||
/* If there's no query function, skip it */
|
||||
if (NULL == component->available) {
|
||||
opal_output_verbose(5, orte_db_base_framework.framework_output,
|
||||
"mca:db:select: Skipping component [%s]. It does not implement a query function",
|
||||
component->base_version.mca_component_name );
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Query the component */
|
||||
opal_output_verbose(5, orte_db_base_framework.framework_output,
|
||||
"mca:db:select: Querying component [%s]",
|
||||
component->base_version.mca_component_name);
|
||||
|
||||
/* If the component is not available, then skip it as
|
||||
* it has no available interfaces
|
||||
*/
|
||||
if (!component->available()) {
|
||||
opal_output_verbose(5, orte_db_base_framework.framework_output,
|
||||
"mca:db:select: Skipping component [%s] - not available",
|
||||
component->base_version.mca_component_name );
|
||||
continue;
|
||||
}
|
||||
|
||||
/* maintain priority order */
|
||||
inserted = false;
|
||||
ncomponent = OBJ_NEW(orte_db_base_active_component_t);
|
||||
ncomponent->component = component;
|
||||
OPAL_LIST_FOREACH(active, &orte_db_base.actives, orte_db_base_active_component_t) {
|
||||
if (component->priority > active->component->priority) {
|
||||
opal_list_insert_pos(&orte_db_base.actives,
|
||||
&active->super, &ncomponent->super);
|
||||
inserted = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!inserted) {
|
||||
/* must be lowest priority - add to end */
|
||||
opal_list_append(&orte_db_base.actives, &ncomponent->super);
|
||||
}
|
||||
}
|
||||
|
||||
/* if no components are available, that is an error */
|
||||
if (0 == opal_list_get_size(&orte_db_base.actives)) {
|
||||
return ORTE_ERR_NOT_FOUND;
|
||||
}
|
||||
|
||||
if (4 < opal_output_get_verbosity(orte_db_base_framework.framework_output)) {
|
||||
opal_output(0, "Final db priorities");
|
||||
/* show the prioritized list */
|
||||
OPAL_LIST_FOREACH(active, &orte_db_base.actives, orte_db_base_active_component_t) {
|
||||
opal_output(0, "\tComponent: %s Store Priority: %d",
|
||||
active->component->base_version.mca_component_name,
|
||||
active->component->priority);
|
||||
}
|
||||
}
|
||||
|
||||
return OPAL_SUCCESS;;
|
||||
}
|
@ -1,354 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2012-2013 Los Alamos National Security, Inc. All rights reserved.
|
||||
* Copyright (c) 2013-2014 Intel Inc. All rights reserved
|
||||
* $COPYRIGHT$
|
||||
*
|
||||
* Additional copyrights may follow
|
||||
*
|
||||
* $HEADER$
|
||||
*/
|
||||
|
||||
|
||||
#include "orte_config.h"
|
||||
#include "orte/constants.h"
|
||||
|
||||
#include "opal_stdint.h"
|
||||
#include "opal/mca/mca.h"
|
||||
#include "opal/util/error.h"
|
||||
#include "opal/util/output.h"
|
||||
#include "opal/mca/base/base.h"
|
||||
#include "opal/dss/dss_types.h"
|
||||
|
||||
#include "orte/mca/db/base/base.h"
|
||||
|
||||
|
||||
static void process_open(int fd, short args, void *cbdata)
|
||||
{
|
||||
orte_db_request_t *req = (orte_db_request_t*)cbdata;
|
||||
orte_db_handle_t *hdl;
|
||||
orte_db_base_module_t *mod;
|
||||
orte_db_base_active_component_t *active;
|
||||
orte_db_base_component_t *component;
|
||||
int i, index;
|
||||
char **cmps = NULL;
|
||||
opal_value_t *kv;
|
||||
bool found;
|
||||
|
||||
/* see if the caller provided the magic "components" property */
|
||||
if (NULL != req->properties) {
|
||||
OPAL_LIST_FOREACH(kv, req->properties, opal_value_t) {
|
||||
if (0 == strcmp(kv->key, "components")) {
|
||||
cmps = opal_argv_split(kv->data.string, ',');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* cycle thru the available components until one saids
|
||||
* it can create a handle for these properties
|
||||
*/
|
||||
OPAL_LIST_FOREACH(active, &orte_db_base.actives, orte_db_base_active_component_t) {
|
||||
component = active->component;
|
||||
found = true;
|
||||
if (NULL != cmps) {
|
||||
found = false;
|
||||
for (i=0; NULL != cmps[i]; i++) {
|
||||
if (0 == strcmp(cmps[i], component->base_version.mca_component_name)) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (found) {
|
||||
/* let this component try */
|
||||
if (NULL != (mod = component->create_handle(req->properties))) {
|
||||
/* create the handle */
|
||||
hdl = OBJ_NEW(orte_db_handle_t);
|
||||
hdl->component = component;
|
||||
hdl->module = mod;
|
||||
index = opal_pointer_array_add(&orte_db_base.handles, hdl);
|
||||
if (NULL != req->cbfunc) {
|
||||
req->cbfunc(index, OPAL_SUCCESS, NULL, req->cbdata);
|
||||
}
|
||||
OBJ_RELEASE(req);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* if we get here, we were unable to create the handle */
|
||||
if (NULL != req->cbfunc) {
|
||||
req->cbfunc(-1, ORTE_ERROR, NULL, req->cbdata);
|
||||
}
|
||||
OBJ_RELEASE(req);
|
||||
}
|
||||
|
||||
void orte_db_base_open(char *name,
|
||||
opal_list_t *properties,
|
||||
orte_db_callback_fn_t cbfunc,
|
||||
void *cbdata)
|
||||
{
|
||||
orte_db_request_t *req;
|
||||
|
||||
/* push this request into our event_base
|
||||
* for processing to ensure nobody else is
|
||||
* using that dbhandle
|
||||
*/
|
||||
req = OBJ_NEW(orte_db_request_t);
|
||||
/* transfer the name in the primary key */
|
||||
req->primary_key = name;
|
||||
req->properties = properties;
|
||||
req->cbfunc = cbfunc;
|
||||
req->cbdata = cbdata;
|
||||
opal_event_set(orte_db_base.ev_base, &req->ev, -1,
|
||||
OPAL_EV_WRITE,
|
||||
process_open, req);
|
||||
opal_event_set_priority(&req->ev, OPAL_EV_SYS_HI_PRI);
|
||||
opal_event_active(&req->ev, OPAL_EV_WRITE, 1);
|
||||
}
|
||||
|
||||
static void process_close(int fd, short args, void *cbdata)
|
||||
{
|
||||
orte_db_request_t *req = (orte_db_request_t*)cbdata;
|
||||
orte_db_handle_t *hdl;
|
||||
int rc=ORTE_SUCCESS;
|
||||
|
||||
/* get the handle object */
|
||||
if (NULL == (hdl = (orte_db_handle_t*)opal_pointer_array_get_item(&orte_db_base.handles, req->dbhandle))) {
|
||||
rc = ORTE_ERR_NOT_FOUND;
|
||||
goto found;
|
||||
}
|
||||
if (NULL == hdl->module) {
|
||||
rc = ORTE_ERR_NOT_FOUND;
|
||||
goto found;
|
||||
}
|
||||
if (NULL != hdl->module->finalize) {
|
||||
hdl->module->finalize((struct orte_db_base_module_t*)hdl->module);
|
||||
}
|
||||
|
||||
found:
|
||||
if (NULL != req->cbfunc) {
|
||||
req->cbfunc(req->dbhandle, rc, NULL, req->cbdata);
|
||||
}
|
||||
/* release the handle */
|
||||
opal_pointer_array_set_item(&orte_db_base.handles, req->dbhandle, NULL);
|
||||
OBJ_RELEASE(hdl);
|
||||
OBJ_RELEASE(req);
|
||||
}
|
||||
|
||||
void orte_db_base_close(int dbhandle,
|
||||
orte_db_callback_fn_t cbfunc,
|
||||
void *cbdata)
|
||||
{
|
||||
orte_db_request_t *req;
|
||||
|
||||
/* push this request into our event_base
|
||||
* for processing to ensure nobody else is
|
||||
* using that dbhandle
|
||||
*/
|
||||
req = OBJ_NEW(orte_db_request_t);
|
||||
req->dbhandle = dbhandle;
|
||||
req->cbfunc = cbfunc;
|
||||
req->cbdata = cbdata;
|
||||
opal_event_set(orte_db_base.ev_base, &req->ev, -1,
|
||||
OPAL_EV_WRITE,
|
||||
process_close, req);
|
||||
opal_event_set_priority(&req->ev, OPAL_EV_SYS_HI_PRI);
|
||||
opal_event_active(&req->ev, OPAL_EV_WRITE, 1);
|
||||
}
|
||||
|
||||
|
||||
static void process_store(int fd, short args, void *cbdata)
|
||||
{
|
||||
orte_db_request_t *req = (orte_db_request_t*)cbdata;
|
||||
orte_db_handle_t *hdl;
|
||||
int rc=ORTE_SUCCESS;
|
||||
|
||||
/* get the handle object */
|
||||
if (NULL == (hdl = (orte_db_handle_t*)opal_pointer_array_get_item(&orte_db_base.handles, req->dbhandle))) {
|
||||
rc = ORTE_ERR_NOT_FOUND;
|
||||
goto found;
|
||||
}
|
||||
if (NULL == hdl->module) {
|
||||
rc = ORTE_ERR_NOT_FOUND;
|
||||
goto found;
|
||||
}
|
||||
if (NULL != hdl->module->store) {
|
||||
rc = hdl->module->store((struct orte_db_base_module_t*)hdl->module, req->primary_key, req->kvs);
|
||||
}
|
||||
|
||||
found:
|
||||
if (NULL != req->cbfunc) {
|
||||
req->cbfunc(req->dbhandle, rc, req->kvs, req->cbdata);
|
||||
}
|
||||
OBJ_RELEASE(req);
|
||||
}
|
||||
|
||||
void orte_db_base_store(int dbhandle,
|
||||
const char *primary_key,
|
||||
opal_list_t *kvs,
|
||||
orte_db_callback_fn_t cbfunc,
|
||||
void *cbdata)
|
||||
{
|
||||
orte_db_request_t *req;
|
||||
|
||||
/* push this request into our event_base
|
||||
* for processing to ensure nobody else is
|
||||
* using that dbhandle
|
||||
*/
|
||||
req = OBJ_NEW(orte_db_request_t);
|
||||
req->dbhandle = dbhandle;
|
||||
req->primary_key = (char*)primary_key;
|
||||
req->kvs = kvs;
|
||||
req->cbfunc = cbfunc;
|
||||
req->cbdata = cbdata;
|
||||
opal_event_set(orte_db_base.ev_base, &req->ev, -1,
|
||||
OPAL_EV_WRITE,
|
||||
process_store, req);
|
||||
opal_event_set_priority(&req->ev, OPAL_EV_SYS_HI_PRI);
|
||||
opal_event_active(&req->ev, OPAL_EV_WRITE, 1);
|
||||
}
|
||||
|
||||
static void process_commit(int fd, short args, void *cbdata)
|
||||
{
|
||||
orte_db_request_t *req = (orte_db_request_t*)cbdata;
|
||||
orte_db_handle_t *hdl;
|
||||
int rc=ORTE_SUCCESS;
|
||||
|
||||
/* get the handle object */
|
||||
if (NULL == (hdl = (orte_db_handle_t*)opal_pointer_array_get_item(&orte_db_base.handles, req->dbhandle))) {
|
||||
rc = ORTE_ERR_NOT_FOUND;
|
||||
goto found;
|
||||
}
|
||||
if (NULL == hdl->module) {
|
||||
rc = ORTE_ERR_NOT_FOUND;
|
||||
goto found;
|
||||
}
|
||||
if (NULL != hdl->module->commit) {
|
||||
hdl->module->commit((struct orte_db_base_module_t*)hdl->module);
|
||||
}
|
||||
|
||||
found:
|
||||
if (NULL != req->cbfunc) {
|
||||
req->cbfunc(req->dbhandle, rc, NULL, req->cbdata);
|
||||
}
|
||||
OBJ_RELEASE(req);
|
||||
}
|
||||
|
||||
void orte_db_base_commit(int dbhandle,
|
||||
orte_db_callback_fn_t cbfunc,
|
||||
void *cbdata)
|
||||
{
|
||||
orte_db_request_t *req;
|
||||
|
||||
/* push this request into our event_base
|
||||
* for processing to ensure nobody else is
|
||||
* using that dbhandle
|
||||
*/
|
||||
req = OBJ_NEW(orte_db_request_t);
|
||||
req->dbhandle = dbhandle;
|
||||
req->cbfunc = cbfunc;
|
||||
req->cbdata = cbdata;
|
||||
opal_event_set(orte_db_base.ev_base, &req->ev, -1,
|
||||
OPAL_EV_WRITE,
|
||||
process_commit, req);
|
||||
opal_event_set_priority(&req->ev, OPAL_EV_SYS_HI_PRI);
|
||||
opal_event_active(&req->ev, OPAL_EV_WRITE, 1);
|
||||
}
|
||||
|
||||
static void process_fetch(int fd, short args, void *cbdata)
|
||||
{
|
||||
orte_db_request_t *req = (orte_db_request_t*)cbdata;
|
||||
orte_db_handle_t *hdl;
|
||||
int rc;
|
||||
|
||||
/* get the handle object */
|
||||
if (NULL == (hdl = (orte_db_handle_t*)opal_pointer_array_get_item(&orte_db_base.handles, req->dbhandle))) {
|
||||
rc = ORTE_ERR_NOT_FOUND;
|
||||
goto found;
|
||||
}
|
||||
if (NULL == hdl->module) {
|
||||
rc = ORTE_ERR_NOT_FOUND;
|
||||
goto found;
|
||||
}
|
||||
rc = hdl->module->fetch((struct orte_db_base_module_t*)hdl->module, req->primary_key, req->key, req->kvs);
|
||||
found:
|
||||
if (NULL != req->cbfunc) {
|
||||
req->cbfunc(req->dbhandle, rc, req->kvs, req->cbdata);
|
||||
}
|
||||
OBJ_RELEASE(req);
|
||||
}
|
||||
|
||||
void orte_db_base_fetch(int dbhandle,
|
||||
const char *primary_key,
|
||||
const char *key,
|
||||
opal_list_t *kvs,
|
||||
orte_db_callback_fn_t cbfunc,
|
||||
void *cbdata)
|
||||
{
|
||||
orte_db_request_t *req;
|
||||
|
||||
/* push this request into our event_base
|
||||
* for processing to ensure nobody else is
|
||||
* using that dbhandle
|
||||
*/
|
||||
req = OBJ_NEW(orte_db_request_t);
|
||||
req->dbhandle = dbhandle;
|
||||
req->primary_key = (char*)primary_key;
|
||||
req->key = (char*)key;
|
||||
req->kvs = kvs;
|
||||
req->cbfunc = cbfunc;
|
||||
req->cbdata = cbdata;
|
||||
opal_event_set(orte_db_base.ev_base, &req->ev, -1,
|
||||
OPAL_EV_WRITE,
|
||||
process_fetch, req);
|
||||
opal_event_set_priority(&req->ev, OPAL_EV_SYS_HI_PRI);
|
||||
opal_event_active(&req->ev, OPAL_EV_WRITE, 1);
|
||||
}
|
||||
|
||||
static void process_remove(int fd, short args, void *cbdata)
|
||||
{
|
||||
orte_db_request_t *req = (orte_db_request_t*)cbdata;
|
||||
orte_db_handle_t *hdl;
|
||||
int rc;
|
||||
|
||||
/* get the handle object */
|
||||
if (NULL == (hdl = (orte_db_handle_t*)opal_pointer_array_get_item(&orte_db_base.handles, req->dbhandle))) {
|
||||
rc = ORTE_ERR_NOT_FOUND;
|
||||
goto found;
|
||||
}
|
||||
if (NULL == hdl->module) {
|
||||
rc = ORTE_ERR_NOT_FOUND;
|
||||
goto found;
|
||||
}
|
||||
rc = hdl->module->remove((struct orte_db_base_module_t*)hdl->module, req->primary_key, req->key);
|
||||
found:
|
||||
if (NULL != req->cbfunc) {
|
||||
req->cbfunc(req->dbhandle, rc, NULL, req->cbdata);
|
||||
}
|
||||
OBJ_RELEASE(req);
|
||||
}
|
||||
|
||||
void orte_db_base_remove_data(int dbhandle,
|
||||
const char *primary_key,
|
||||
const char *key,
|
||||
orte_db_callback_fn_t cbfunc,
|
||||
void *cbdata)
|
||||
{
|
||||
orte_db_request_t *req;
|
||||
|
||||
/* push this request into our event_base
|
||||
* for processing to ensure nobody else is
|
||||
* using that dbhandle
|
||||
*/
|
||||
req = OBJ_NEW(orte_db_request_t);
|
||||
req->dbhandle = dbhandle;
|
||||
req->primary_key = (char*)primary_key;
|
||||
req->key = (char*)key;
|
||||
req->cbfunc = cbfunc;
|
||||
req->cbdata = cbdata;
|
||||
opal_event_set(orte_db_base.ev_base, &req->ev, -1,
|
||||
OPAL_EV_WRITE,
|
||||
process_remove, req);
|
||||
opal_event_set_priority(&req->ev, OPAL_EV_SYS_HI_PRI);
|
||||
opal_event_active(&req->ev, OPAL_EV_WRITE, 1);
|
||||
}
|
210
orte/mca/db/db.h
210
orte/mca/db/db.h
@ -1,210 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
|
||||
* Copyright (c) 2012-2013 Los Alamos National Security, Inc. All rights reserved.
|
||||
* Copyright (c) 2013-2014 Intel, Inc. All rights reserved.
|
||||
* $COPYRIGHT$
|
||||
*
|
||||
* Additional copyrights may follow
|
||||
*
|
||||
* $HEADER$
|
||||
*/
|
||||
/** @file:
|
||||
*
|
||||
* The Database Framework
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef ORTE_DB_H
|
||||
#define ORTE_DB_H
|
||||
|
||||
#include "orte_config.h"
|
||||
#include "orte/types.h"
|
||||
|
||||
#include "opal/mca/mca.h"
|
||||
#include "opal/mca/event/event.h"
|
||||
#include "opal/dss/dss_types.h"
|
||||
|
||||
/**
|
||||
* DATABASE DESIGN
|
||||
*
|
||||
* DB APIs are non-blocking and executed by pushing the request onto the ORTE
|
||||
* event base. Upon completion, the provided cbfunc will be called to return
|
||||
* the status resulting from the operation (a NULL cbfunc is permitted). The
|
||||
* cbfunc is responsible for releasing the returned list
|
||||
*/
|
||||
|
||||
BEGIN_C_DECLS
|
||||
|
||||
/* forward declare */
|
||||
struct orte_db_base_module_t;
|
||||
|
||||
/* callback function for async requests */
|
||||
typedef void (*orte_db_callback_fn_t)(int dbhandle, int status,
|
||||
opal_list_t *kvs, void *cbdata);
|
||||
|
||||
/*
|
||||
* Initialize the module
|
||||
*/
|
||||
typedef int (*orte_db_base_module_init_fn_t)(struct orte_db_base_module_t *imod);
|
||||
|
||||
/*
|
||||
* Finalize the module
|
||||
*/
|
||||
typedef void (*orte_db_base_module_finalize_fn_t)(struct orte_db_base_module_t *imod);
|
||||
|
||||
/*
|
||||
* Open a database
|
||||
*
|
||||
* Open a database for access (read, write, etc.). The request
|
||||
* can contain a user-specified name for this database that
|
||||
* has nothing to do with the backend database - it is solely
|
||||
* for use as a debug tool to help identify the database. The
|
||||
* request can also optionally provide a list of opal_value_t
|
||||
* properties - this is where one might specify the name of
|
||||
* the backend database, a URI for contacting it, the name of
|
||||
* a particular table for request, etc. Thus, it is important
|
||||
* to note that the returned "handle" is associated solely with
|
||||
* the defined request - i.e., if the properties specify a database
|
||||
* and table, then the handle will be specific to that combination.
|
||||
*
|
||||
* NOTE: one special "property" allows you to specify the
|
||||
* name(s) of the component(s) you want considered for this
|
||||
* handle - i.e., the equivalent of specifying the MCA param
|
||||
* "db=list" - using the reserved property name "components".
|
||||
* The components will be queried in the order specified. The ^
|
||||
* character is also supported, with the remaining components
|
||||
* considered in priority order
|
||||
*
|
||||
* Just like the standard POSIX file open, the call will return
|
||||
* a unique "handle" that must be provided with any subsequent
|
||||
* call to store or fetch data from this database.
|
||||
*/
|
||||
typedef void (*orte_db_base_API_open_fn_t)(char *name,
|
||||
opal_list_t *properties,
|
||||
orte_db_callback_fn_t cbfunc,
|
||||
void *cbdata);
|
||||
|
||||
/*
|
||||
* Close a database handle
|
||||
*
|
||||
* Close the specified database handle. This may or may not invoke
|
||||
* termination of a connection to a remote database or release of
|
||||
* memory storage, depending on the precise implementation of the
|
||||
* active database components. A -1 handle indicates that ALL open
|
||||
* database handles are to be closed.
|
||||
*/
|
||||
typedef void (*orte_db_base_API_close_fn_t)(int dbhandle,
|
||||
orte_db_callback_fn_t cbfunc,
|
||||
void *cbdata);
|
||||
|
||||
/*
|
||||
* Store one or more data elements against the primary key - overwrites any data
|
||||
* of matching key that is already present. The data is copied into the database
|
||||
* and therefore does not need to be preserved by the caller.
|
||||
*/
|
||||
typedef void (*orte_db_base_API_store_fn_t)(int dbhandle,
|
||||
const char *primary_key,
|
||||
opal_list_t *kvs,
|
||||
orte_db_callback_fn_t cbfunc,
|
||||
void *cbdata);
|
||||
typedef int (*orte_db_base_module_store_fn_t)(struct orte_db_base_module_t *imod,
|
||||
const char *primary_key,
|
||||
opal_list_t *kvs);
|
||||
|
||||
/*
|
||||
* Commit data to the database - action depends on implementation within
|
||||
* each active component
|
||||
*/
|
||||
typedef void (*orte_db_base_API_commit_fn_t)(int dbhandle,
|
||||
orte_db_callback_fn_t cbfunc,
|
||||
void *cbdata);
|
||||
typedef void (*orte_db_base_module_commit_fn_t)(struct orte_db_base_module_t *imod);
|
||||
|
||||
/*
|
||||
* Retrieve data
|
||||
*
|
||||
* Retrieve data for the given primary key associated with the specified key. Wildcards
|
||||
* are supported here as well. Caller is responsible for releasing the returned list
|
||||
* of opal_keyval_t objects.
|
||||
*/
|
||||
typedef void (*orte_db_base_API_fetch_fn_t)(int dbhandle,
|
||||
const char *primary_key,
|
||||
const char *key,
|
||||
opal_list_t *kvs,
|
||||
orte_db_callback_fn_t cbfunc,
|
||||
void *cbdata);
|
||||
typedef int (*orte_db_base_module_fetch_fn_t)(struct orte_db_base_module_t *imod,
|
||||
const char *primary_key,
|
||||
const char *key,
|
||||
opal_list_t *kvs);
|
||||
/*
|
||||
* Delete data
|
||||
*
|
||||
* Delete the data for the given primary key that is associated with the specified key.
|
||||
* If a NULL key is provided, all data for the given primary key will be deleted.
|
||||
*/
|
||||
typedef void (*orte_db_base_API_remove_fn_t)(int dbhandle,
|
||||
const char *primary_key,
|
||||
const char *key,
|
||||
orte_db_callback_fn_t cbfunc,
|
||||
void *cbdata);
|
||||
typedef int (*orte_db_base_module_remove_fn_t)(struct orte_db_base_module_t *imod,
|
||||
const char *primary_key,
|
||||
const char *key);
|
||||
|
||||
/*
|
||||
* the standard module data structure
|
||||
*/
|
||||
typedef struct {
|
||||
orte_db_base_module_init_fn_t init;
|
||||
orte_db_base_module_finalize_fn_t finalize;
|
||||
orte_db_base_module_store_fn_t store;
|
||||
orte_db_base_module_commit_fn_t commit;
|
||||
orte_db_base_module_fetch_fn_t fetch;
|
||||
orte_db_base_module_remove_fn_t remove;
|
||||
} orte_db_base_module_t;
|
||||
|
||||
typedef struct {
|
||||
orte_db_base_API_open_fn_t open;
|
||||
orte_db_base_API_close_fn_t close;
|
||||
orte_db_base_API_store_fn_t store;
|
||||
orte_db_base_API_commit_fn_t commit;
|
||||
orte_db_base_API_fetch_fn_t fetch;
|
||||
orte_db_base_API_remove_fn_t remove;
|
||||
} orte_db_API_module_t;
|
||||
|
||||
|
||||
/* function to determine if this component is available for use.
|
||||
* Note that we do not use the standard component open
|
||||
* function as we do not want/need return of a module.
|
||||
*/
|
||||
typedef bool (*mca_db_base_component_avail_fn_t)(void);
|
||||
|
||||
/* create and return a database module */
|
||||
typedef orte_db_base_module_t* (*mca_db_base_component_create_hdl_fn_t)(opal_list_t *props);
|
||||
|
||||
/* provide a chance for the component to finalize */
|
||||
typedef void (*mca_db_base_component_finalize_fn_t)(void);
|
||||
|
||||
typedef struct {
|
||||
mca_base_component_t base_version;
|
||||
mca_base_component_data_t base_data;
|
||||
int priority;
|
||||
mca_db_base_component_avail_fn_t available;
|
||||
mca_db_base_component_create_hdl_fn_t create_handle;
|
||||
mca_db_base_component_finalize_fn_t finalize;
|
||||
} orte_db_base_component_t;
|
||||
|
||||
/*
|
||||
* Macro for use in components that are of type db
|
||||
*/
|
||||
#define ORTE_DB_BASE_VERSION_2_0_0 \
|
||||
MCA_BASE_VERSION_2_0_0, \
|
||||
"db", 2, 0, 0
|
||||
|
||||
/* Global structure for accessing DB functions */
|
||||
ORTE_DECLSPEC extern orte_db_API_module_t orte_db; /* holds API function pointers */
|
||||
|
||||
END_C_DECLS
|
||||
|
||||
#endif
|
@ -1,34 +0,0 @@
|
||||
#
|
||||
# Copyright (c) 2013-2014 Intel, Inc. All rights reserved.
|
||||
# $COPYRIGHT$
|
||||
#
|
||||
# Additional copyrights may follow
|
||||
#
|
||||
# $HEADER$
|
||||
#
|
||||
|
||||
sources = \
|
||||
db_postgres.h \
|
||||
db_postgres_component.c \
|
||||
db_postgres.c
|
||||
|
||||
# Make the output library in this directory, and name it either
|
||||
# mca_<type>_<name>.la (for DSO builds) or libmca_<type>_<name>.la
|
||||
# (for static builds).
|
||||
|
||||
if MCA_BUILD_orte_db_postgres_DSO
|
||||
component_noinst =
|
||||
component_install = mca_db_postgres.la
|
||||
else
|
||||
component_noinst = libmca_db_postgres.la
|
||||
component_install =
|
||||
endif
|
||||
|
||||
mcacomponentdir = $(ompilibdir)
|
||||
mcacomponent_LTLIBRARIES = $(component_install)
|
||||
mca_db_postgres_la_SOURCES = $(sources)
|
||||
mca_db_postgres_la_LDFLAGS = -module -avoid-version
|
||||
|
||||
noinst_LTLIBRARIES = $(component_noinst)
|
||||
libmca_db_postgres_la_SOURCES =$(sources)
|
||||
libmca_db_postgres_la_LDFLAGS = -module -avoid-version
|
@ -1,44 +0,0 @@
|
||||
dnl -*- shell-script -*-
|
||||
dnl
|
||||
dnl Copyright (c) 2012-2013 Los Alamos National Security, Inc. All rights reserved.
|
||||
dnl Copyright (c) 2013-2014 Intel, Inc. All rights reserved.
|
||||
dnl $COPYRIGHT$
|
||||
dnl
|
||||
dnl Additional copyrights may follow
|
||||
dnl
|
||||
dnl $HEADER$
|
||||
dnl
|
||||
|
||||
# MCA_db_postgres_CONFIG([action-if-found], [action-if-not-found])
|
||||
# -----------------------------------------------------------
|
||||
AC_DEFUN([MCA_orte_db_postgres_CONFIG], [
|
||||
AC_CONFIG_FILES([orte/mca/db/postgres/Makefile])
|
||||
|
||||
AC_REQUIRE([OPAL_CHECK_POSTGRES])
|
||||
|
||||
# do not build if support not requested
|
||||
AS_IF([test "$orte_check_postgres_happy" == "yes"],
|
||||
[orte_db_postgres_check_save_CPPFLAGS=$CPPFLAGS
|
||||
orte_db_postgres_check_save_LDFLAGS=$LDFLAGS
|
||||
orte_db_postgres_check_save_LIBS=$LIBS
|
||||
OPAL_CHECK_PACKAGE([db_postgres],
|
||||
[libpq-fe.h],
|
||||
[pq],
|
||||
[PQconnectdb],
|
||||
[],
|
||||
[$orte_postgres_incdir],
|
||||
[],
|
||||
[$1],
|
||||
[AC_MSG_WARN([Postgres database support requested])
|
||||
AC_MSG_WARN([but required library or header not found])
|
||||
AC_MSG_ERROR([Cannot continue])
|
||||
$2])
|
||||
CPPFLAGS=$orte_db_postgres_check_save_CPPFLAGS
|
||||
LDFLAGS=$orte_db_postgres_check_save_LDFLAGS
|
||||
LIBS=$orte_db_postgres_check_save_LIBS],
|
||||
[$2])
|
||||
|
||||
AC_SUBST(db_postgres_CPPFLAGS)
|
||||
AC_SUBST(db_postgres_LDFLAGS)
|
||||
AC_SUBST(db_postgres_LIBS)
|
||||
])dnl
|
@ -1,254 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2012-2013 Los Alamos National Security, Inc. All rights reserved.
|
||||
* Copyright (c) 2013-2014 Intel, Inc. All rights reserved.
|
||||
* $COPYRIGHT$
|
||||
*
|
||||
* Additional copyrights may follow
|
||||
*
|
||||
* $HEADER$
|
||||
*
|
||||
*/
|
||||
|
||||
#include "orte_config.h"
|
||||
#include "orte/constants.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#ifdef HAVE_LIMITS_H
|
||||
#include <limits.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#ifdef HAVE_FCNTL_H
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "libpq-fe.h"
|
||||
|
||||
#include "opal_stdint.h"
|
||||
#include "opal/util/argv.h"
|
||||
#include "opal/util/error.h"
|
||||
|
||||
#include "orte/mca/db/base/base.h"
|
||||
#include "db_postgres.h"
|
||||
|
||||
#define ORTE_PG_MAX_LINE_LENGTH 4096
|
||||
|
||||
static int init(struct orte_db_base_module_t *imod);
|
||||
static void finalize(struct orte_db_base_module_t *imod);
|
||||
static int store(struct orte_db_base_module_t *imod,
|
||||
const char *primary_key,
|
||||
opal_list_t *kvs);
|
||||
|
||||
mca_db_postgres_module_t mca_db_postgres_module = {
|
||||
{
|
||||
init,
|
||||
finalize,
|
||||
store,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
},
|
||||
};
|
||||
|
||||
static int init(struct orte_db_base_module_t *imod)
|
||||
{
|
||||
mca_db_postgres_module_t *mod = (mca_db_postgres_module_t*)imod;
|
||||
char **login=NULL;
|
||||
char **connection=NULL;
|
||||
|
||||
/* break the user info into its login parts */
|
||||
login = opal_argv_split(mod->user, ':');
|
||||
if (2 != opal_argv_count(login)) {
|
||||
opal_output(0, "db:postgres: User info is invalid: %s",
|
||||
mod->user);
|
||||
opal_argv_free(login);
|
||||
return ORTE_ERR_BAD_PARAM;
|
||||
}
|
||||
/* break the uri */
|
||||
connection = opal_argv_split(mod->pguri, ':');
|
||||
if (2 != opal_argv_count(connection)) {
|
||||
opal_argv_free(login);
|
||||
opal_argv_free(connection);
|
||||
opal_output(0, "db:postgres: Connection info is invalid: %s",
|
||||
mod->pguri);
|
||||
return ORTE_ERR_BAD_PARAM;
|
||||
}
|
||||
|
||||
conn = PQsetdbLogin(connection[0], connection[1],
|
||||
mod->pgoptions,
|
||||
mod->pgtty,
|
||||
mod->dbname,
|
||||
login[0], login[1]);
|
||||
opal_argv_free(login);
|
||||
opal_argv_free(connection);
|
||||
|
||||
if (PQstatus(conn) != CONNECTION_OK) {
|
||||
conn = NULL;
|
||||
opal_output(0, "***********************************************\n");
|
||||
opal_output(0, "db:postgres: Connection failed:\n\tURI: %s\n\tOPTIONS: %s\n\tTTY: %s\n\tDBNAME: %s\n\tUSER: %s",
|
||||
mod->pguri,
|
||||
(NULL == mod->pgoptions) ? "NULL" : mod->pgoptions,
|
||||
(NULL == mod->pgtty) ? "NULL" : mod->pgtty,
|
||||
mod->dbname,
|
||||
mod->user);
|
||||
opal_output(0, "\n***********************************************");
|
||||
exit(ORTE_ERR_CONNECTION_FAILED);
|
||||
return ORTE_ERR_CONNECTION_FAILED;
|
||||
}
|
||||
opal_output_verbose(5, orte_db_base_framework.framework_output,
|
||||
"db:postgres: Connection established to %s",
|
||||
mod->dbname);
|
||||
|
||||
return ORTE_SUCCESS;
|
||||
}
|
||||
|
||||
static void finalize(struct orte_db_base_module_t *imod)
|
||||
{
|
||||
mca_db_postgres_module_t *mod = (mca_db_postgres_module_t*)imod;
|
||||
if (NULL != mod->dbname) {
|
||||
free(mod->dbname);
|
||||
}
|
||||
if (NULL != mod->table) {
|
||||
free(mod->table);
|
||||
}
|
||||
if (NULL != mod->user) {
|
||||
free(mod->user);
|
||||
}
|
||||
if (NULL != mod->pguri) {
|
||||
free(mod->pguri);
|
||||
}
|
||||
if (NULL != mod->pgoptions) {
|
||||
free(mod->pgoptions);
|
||||
}
|
||||
if (NULL != mod->pgtty) {
|
||||
free(mod->pgtty);
|
||||
}
|
||||
if (NULL != mod->conn) {
|
||||
PQfinish(mod->conn);
|
||||
}
|
||||
}
|
||||
|
||||
static int store(struct orte_db_base_module_t *imod,
|
||||
const char *primary_key,
|
||||
opal_list_t *kvs)
|
||||
{
|
||||
mca_db_postgres_module_t *mod = (mca_db_postgres_module_t*)imod;
|
||||
char *query, *vstr;
|
||||
PGresult *res;
|
||||
char **cmdargs=NULL;
|
||||
time_t nowtime;
|
||||
struct tm *nowtm;
|
||||
char tbuf[1024], buf[64];
|
||||
int i;
|
||||
opal_value_t *kv;
|
||||
|
||||
/* cycle through the provided values and construct
|
||||
* an insert command for them - note that the values
|
||||
* MUST be in column-order for the database!
|
||||
*/
|
||||
OPAL_LIST_FOREACH(kv, kvs, opal_value_t) {
|
||||
switch (kv->type) {
|
||||
case OPAL_STRING:
|
||||
snprintf(tbuf, sizeof(tbuf), "%s", kv->data.string);
|
||||
opal_argv_append_nosize(&cmdargs, tbuf);
|
||||
break;
|
||||
case OPAL_SIZE:
|
||||
snprintf(tbuf, sizeof(tbuf), "%" PRIsize_t "", kv->data.size);
|
||||
opal_argv_append_nosize(&cmdargs, tbuf);
|
||||
break;
|
||||
case OPAL_INT:
|
||||
snprintf(tbuf, sizeof(tbuf), "%d", kv->data.integer);
|
||||
opal_argv_append_nosize(&cmdargs, tbuf);
|
||||
break;
|
||||
case OPAL_INT8:
|
||||
snprintf(tbuf, sizeof(tbuf), "%" PRIi8 "", kv->data.int8);
|
||||
opal_argv_append_nosize(&cmdargs, tbuf);
|
||||
break;
|
||||
case OPAL_INT16:
|
||||
snprintf(tbuf, sizeof(tbuf), "%" PRIi16 "", kv->data.int16);
|
||||
opal_argv_append_nosize(&cmdargs, tbuf);
|
||||
break;
|
||||
case OPAL_INT32:
|
||||
snprintf(tbuf, sizeof(tbuf), "%" PRIi32 "", kv->data.int32);
|
||||
opal_argv_append_nosize(&cmdargs, tbuf);
|
||||
break;
|
||||
case OPAL_INT64:
|
||||
snprintf(tbuf, sizeof(tbuf), "%" PRIi64 "", kv->data.int64);
|
||||
opal_argv_append_nosize(&cmdargs, tbuf);
|
||||
break;
|
||||
case OPAL_UINT:
|
||||
snprintf(tbuf, sizeof(tbuf), "%u", kv->data.uint);
|
||||
opal_argv_append_nosize(&cmdargs, tbuf);
|
||||
break;
|
||||
case OPAL_UINT8:
|
||||
snprintf(tbuf, sizeof(tbuf), "%" PRIu8 "", kv->data.uint8);
|
||||
opal_argv_append_nosize(&cmdargs, tbuf);
|
||||
break;
|
||||
case OPAL_UINT16:
|
||||
snprintf(tbuf, sizeof(tbuf), "%" PRIu16 "", kv->data.uint16);
|
||||
opal_argv_append_nosize(&cmdargs, tbuf);
|
||||
break;
|
||||
case OPAL_UINT32:
|
||||
snprintf(tbuf, sizeof(tbuf), "%" PRIu32 "", kv->data.uint32);
|
||||
opal_argv_append_nosize(&cmdargs, tbuf);
|
||||
break;
|
||||
case OPAL_UINT64:
|
||||
snprintf(tbuf, sizeof(tbuf), "%" PRIu64 "", kv->data.uint64);
|
||||
opal_argv_append_nosize(&cmdargs, tbuf);
|
||||
break;
|
||||
case OPAL_PID:
|
||||
snprintf(tbuf, sizeof(tbuf), "%lu", (unsigned long)kv->data.pid);
|
||||
opal_argv_append_nosize(&cmdargs, tbuf);
|
||||
break;
|
||||
case OPAL_FLOAT:
|
||||
snprintf(tbuf, sizeof(tbuf), "%f", kv->data.fval);
|
||||
opal_argv_append_nosize(&cmdargs, tbuf);
|
||||
break;
|
||||
case OPAL_TIMEVAL:
|
||||
/* we only care about seconds */
|
||||
nowtime = kv->data.tv.tv_sec;
|
||||
(void)localtime_r(&nowtime, &nowtm);
|
||||
strftime(tbuf, sizeof(tbuf), "%Y-%m-%d %H:%M:%S", &nowtm);
|
||||
opal_argv_append_nosize(&cmdargs, tbuf);
|
||||
break;
|
||||
default:
|
||||
snprintf(tbuf, sizeof(tbuf), "Unsupported type: %s",
|
||||
opal_dss.lookup_data_type(kv->type));
|
||||
opal_argv_append_nosize(&cmdargs, tbuf);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* assemble the value string */
|
||||
vstr = opal_argv_join(cmdargs, ',');
|
||||
opal_argv_free(cmdargs);
|
||||
|
||||
/* create the query */
|
||||
asprintf(&query, "INSERT INTO %s values (%s)", mod->table, vstr);
|
||||
free(vstr);
|
||||
|
||||
opal_output_verbose(2, orte_db_base_framework.framework_output,
|
||||
"Executing query %s", query);
|
||||
|
||||
/* execute it */
|
||||
res = PQexec(conn, query);
|
||||
free(query);
|
||||
|
||||
if ((!res) || (PQresultStatus(res) != PGRES_COMMAND_OK)) {
|
||||
opal_output(0, "***********************************************\n");
|
||||
opal_output(0, "POSTGRES INSERT COMMAND FAILED - UNABLE TO LOG");
|
||||
opal_output(0, "DATA. ABORTING");
|
||||
opal_output(0, "\n***********************************************");
|
||||
PQclear(res);
|
||||
return ORTE_ERROR;
|
||||
}
|
||||
|
||||
opal_output_verbose(2, orte_db_base_framework.framework_output,
|
||||
"Query succeeded");
|
||||
|
||||
PQclear(res);
|
||||
return OPAL_SUCCESS;
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2012-2013 Los Alamos National Security, Inc. All rights reserved.
|
||||
* Copyright (c) 2013-2014 Intel, Inc. All rights reserved.
|
||||
* $COPYRIGHT$
|
||||
*
|
||||
* Additional copyrights may follow
|
||||
*
|
||||
* $HEADER$
|
||||
*/
|
||||
|
||||
#ifndef ORTE_DB_POSTGRES_H
|
||||
#define ORTE_DB_POSTGRES_H
|
||||
|
||||
#include "libpq-fe.h"
|
||||
|
||||
#include "orte/mca/db/db.h"
|
||||
|
||||
BEGIN_C_DECLS
|
||||
|
||||
ORTE_MODULE_DECLSPEC extern orte_db_base_component_t mca_db_postgres_component;
|
||||
|
||||
typedef struct {
|
||||
orte_db_base_module_t api;
|
||||
int num_worker_threads;
|
||||
char *dbname;
|
||||
char *table;
|
||||
char *user;
|
||||
char *pguri;
|
||||
char *pgoptions;
|
||||
char *pgtty;
|
||||
PGconn *conn;
|
||||
} mca_db_postgres_module_t;
|
||||
ORTE_MODULE_DECLSPEC extern mca_db_postgres_module_t mca_db_postgres_module;
|
||||
|
||||
END_C_DECLS
|
||||
|
||||
#endif /* ORTE_DB_POSTGRES_H */
|
@ -1,213 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2014 Intel, Inc. All rights reserved.
|
||||
* $COPYRIGHT$
|
||||
*
|
||||
* Additional copyrights may follow
|
||||
*
|
||||
* $HEADER$
|
||||
*
|
||||
* These symbols are in a file by themselves to provide nice linker
|
||||
* semantics. Since linkers generally pull in symbols by object
|
||||
* files, keeping these symbols as the only symbols in this file
|
||||
* prevents utility programs such as "ompi_info" from having to import
|
||||
* entire components just to query their version and parameters.
|
||||
*/
|
||||
|
||||
#include "orte_config.h"
|
||||
#include "orte/constants.h"
|
||||
|
||||
#include "opal/mca/base/base.h"
|
||||
#include "opal/mca/base/mca_base_var.h"
|
||||
|
||||
#include "orte/mca/errmgr/errmgr.h"
|
||||
#include "orte/mca/db/db.h"
|
||||
#include "orte/mca/db/base/base.h"
|
||||
#include "db_postgres.h"
|
||||
|
||||
static int component_register(void);
|
||||
static bool component_avail(void);
|
||||
static orte_db_base_module_t *component_create(opal_list_t *props);
|
||||
|
||||
/*
|
||||
* Instantiate the public struct with all of our public information
|
||||
* and pointers to our public functions in it
|
||||
*/
|
||||
orte_db_base_component_t mca_db_postgres_component = {
|
||||
{
|
||||
ORTE_DB_BASE_VERSION_2_0_0,
|
||||
|
||||
/* Component name and version */
|
||||
"postgres",
|
||||
ORTE_MAJOR_VERSION,
|
||||
ORTE_MINOR_VERSION,
|
||||
ORTE_RELEASE_VERSION,
|
||||
|
||||
/* Component open and close functions */
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
component_register
|
||||
},
|
||||
{
|
||||
/* The component is checkpoint ready */
|
||||
MCA_BASE_METADATA_PARAM_CHECKPOINT
|
||||
},
|
||||
75,
|
||||
component_avail,
|
||||
component_create,
|
||||
NULL
|
||||
};
|
||||
|
||||
static int num_worker_threads;
|
||||
static char *dbname;
|
||||
static char *table;
|
||||
static char *user;
|
||||
static char *pguri;
|
||||
static char *pgoptions;
|
||||
static char *pgtty;
|
||||
|
||||
static int component_register(void) {
|
||||
mca_base_component_t *c = &mca_db_postgres_component.base_version;
|
||||
|
||||
/* retrieve the name of the database to be used */
|
||||
dbname = NULL;
|
||||
(void) mca_base_component_var_register (c, "database", "Name of database",
|
||||
MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0,
|
||||
OPAL_INFO_LVL_9,
|
||||
MCA_BASE_VAR_SCOPE_READONLY,
|
||||
&dbname);
|
||||
|
||||
/* retrieve the name of the table to be used */
|
||||
table = NULL;
|
||||
(void) mca_base_component_var_register (c, "table", "Name of table",
|
||||
MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0,
|
||||
OPAL_INFO_LVL_9,
|
||||
MCA_BASE_VAR_SCOPE_READONLY,
|
||||
&table);
|
||||
|
||||
/* retrieve the name of the user to be used */
|
||||
user = NULL;
|
||||
(void) mca_base_component_var_register (c, "user", "Name of database user:password",
|
||||
MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0,
|
||||
OPAL_INFO_LVL_9,
|
||||
MCA_BASE_VAR_SCOPE_READONLY,
|
||||
&user);
|
||||
|
||||
/* retrieve the server:port */
|
||||
pguri = NULL;
|
||||
(void) mca_base_component_var_register (c, "uri", "Contact info for Postgres server as ip:port",
|
||||
MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0,
|
||||
OPAL_INFO_LVL_9,
|
||||
MCA_BASE_VAR_SCOPE_READONLY,
|
||||
&pguri);
|
||||
|
||||
/* retrieve any options to be used */
|
||||
pgoptions = NULL;
|
||||
(void) mca_base_component_var_register (c, "options", "Options to pass to the database",
|
||||
MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0,
|
||||
OPAL_INFO_LVL_9,
|
||||
MCA_BASE_VAR_SCOPE_READONLY,
|
||||
&pgoptions);
|
||||
|
||||
/* retrieve the tty argument */
|
||||
pgtty = NULL;
|
||||
(void) mca_base_component_var_register (c, "tty", "TTY option for database",
|
||||
MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0,
|
||||
OPAL_INFO_LVL_9,
|
||||
MCA_BASE_VAR_SCOPE_READONLY,
|
||||
&pgtty);
|
||||
|
||||
/* retrieve the number of worker threads to be used */
|
||||
num_worker_threads = -1;
|
||||
(void) mca_base_component_var_register (c, "num_worker_threads",
|
||||
"Number of worker threads to be used",
|
||||
MCA_BASE_VAR_TYPE_INT, NULL, 0, 0,
|
||||
OPAL_INFO_LVL_9,
|
||||
MCA_BASE_VAR_SCOPE_READONLY,
|
||||
&num_worker_threads);
|
||||
|
||||
return OPAL_SUCCESS;
|
||||
}
|
||||
|
||||
static bool component_avail(void)
|
||||
{
|
||||
/* always available */
|
||||
return true;
|
||||
}
|
||||
|
||||
static orte_db_base_module_t *component_create(opal_list_t *props)
|
||||
{
|
||||
mca_db_postgres_module_t *mod;
|
||||
opal_value_t *kv;
|
||||
|
||||
mod = (mca_db_postgres_module_t*)malloc(sizeof(mca_db_postgres_module_t));
|
||||
if (NULL == mod) {
|
||||
ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE);
|
||||
return NULL;
|
||||
}
|
||||
memset(mod, 0, sizeof(mca_db_postgres_module_t));
|
||||
mod->num_worker_threads = -1;
|
||||
|
||||
/* copy the APIs across */
|
||||
memcpy(mod, &mca_db_postgres_module.api, sizeof(orte_db_base_module_t));
|
||||
|
||||
/* if the props include db info, then use it */
|
||||
OPAL_LIST_FOREACH(kv, props, opal_value_t) {
|
||||
if (0 == strcmp(kv->key, "database")) {
|
||||
mod->dbname = strdup(kv->data.string);
|
||||
} else if (0 == strcmp(kv->key, "table")) {
|
||||
mod->table = strdup(kv->data.string);
|
||||
} else if (0 == strcmp(kv->key, "user")) {
|
||||
mod->user = strdup(kv->data.string);
|
||||
} else if (0 == strcmp(kv->key, "uri")) {
|
||||
mod->pguri = strdup(kv->data.string);
|
||||
} else if (0 == strcmp(kv->key, "options")) {
|
||||
mod->pgoptions = strdup(kv->data.string);
|
||||
} else if (0 == strcmp(kv->key, "tty")) {
|
||||
mod->pgtty = strdup(kv->data.string);
|
||||
} else if (0 == strcmp(kv->key, "num_worker_threads")) {
|
||||
mod->num_worker_threads = kv->data.integer;
|
||||
}
|
||||
}
|
||||
if (NULL == mod->dbname) {
|
||||
if (NULL == dbname) {
|
||||
/* nothing was provided - opt out */
|
||||
free(mod);
|
||||
return NULL;
|
||||
}
|
||||
mod->dbname = strdup(dbname);
|
||||
}
|
||||
if (NULL == mod->table) {
|
||||
if (NULL == table) {
|
||||
/* nothing was provided - opt out */
|
||||
free(mod);
|
||||
return NULL;
|
||||
}
|
||||
mod->table = strdup(table);
|
||||
}
|
||||
/* all other entries are optional */
|
||||
if (NULL == mod->user && NULL != user) {
|
||||
mod->user = strdup(user);
|
||||
}
|
||||
if (NULL == mod->pguri && NULL != pguri) {
|
||||
mod->pguri = strdup(pguri);
|
||||
}
|
||||
if (NULL == mod->pgoptions && NULL != pgoptions) {
|
||||
mod->pgoptions = strdup(pgoptions);
|
||||
}
|
||||
if (NULL == mod->pgtty && NULL != pgtty) {
|
||||
mod->pgtty = strdup(pgtty);
|
||||
}
|
||||
if (0 > mod->num_worker_threads && 0 < num_worker_threads) {
|
||||
mod->num_worker_threads = num_worker_threads;
|
||||
}
|
||||
|
||||
/* let the module init */
|
||||
if (ORTE_SUCCESS != mod->api.init((struct orte_db_base_module_t*)mod)) {
|
||||
mod->api.finalize((struct orte_db_base_module_t*)mod);
|
||||
free(mod);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return (orte_db_base_module_t*)mod;
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
#
|
||||
# Copyright (c) 2012-2013 Los Alamos National Security, Inc. All rights reserved.
|
||||
# $COPYRIGHT$
|
||||
#
|
||||
# Additional copyrights may follow
|
||||
#
|
||||
# $HEADER$
|
||||
#
|
||||
|
||||
sources = \
|
||||
db_print.h \
|
||||
db_print_component.c \
|
||||
db_print.c
|
||||
|
||||
# Make the output library in this directory, and name it either
|
||||
# mca_<type>_<name>.la (for DSO builds) or libmca_<type>_<name>.la
|
||||
# (for static builds).
|
||||
|
||||
if MCA_BUILD_orte_db_print_DSO
|
||||
component_noinst =
|
||||
component_install = mca_db_print.la
|
||||
else
|
||||
component_noinst = libmca_db_print.la
|
||||
component_install =
|
||||
endif
|
||||
|
||||
mcacomponentdir = $(ompilibdir)
|
||||
mcacomponent_LTLIBRARIES = $(component_install)
|
||||
mca_db_print_la_CPPFLAGS = $(db_print_CPPFLAGS)
|
||||
mca_db_print_la_SOURCES = $(sources)
|
||||
mca_db_print_la_LDFLAGS = -module -avoid-version $(db_print_LDFLAGS)
|
||||
mca_db_print_la_LIBADD = $(db_print_LIBS)
|
||||
|
||||
noinst_LTLIBRARIES = $(component_noinst)
|
||||
libmca_db_print_la_CPPFLAGS = $(db_print_CPPFLAGS)
|
||||
libmca_db_print_la_SOURCES =$(sources)
|
||||
libmca_db_print_la_LDFLAGS = -module -avoid-version $(db_print_LDFLAGS)
|
||||
libmca_db_print_la_LIBADD = $(db_print_LIBS)
|
@ -1,175 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2012-2013 Los Alamos National Security, Inc. All rights reserved.
|
||||
* Copyright (c) 2014 Intel, Inc. All rights reserved.
|
||||
* $COPYRIGHT$
|
||||
*
|
||||
* Additional copyrights may follow
|
||||
*
|
||||
* $HEADER$
|
||||
*
|
||||
*/
|
||||
|
||||
#include "orte_config.h"
|
||||
#include "orte/constants.h"
|
||||
|
||||
#include <time.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#ifdef HAVE_LIMITS_H
|
||||
#include <limits.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#ifdef HAVE_FCNTL_H
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "opal/class/opal_pointer_array.h"
|
||||
#include "opal/util/argv.h"
|
||||
#include "opal/util/output.h"
|
||||
#include "opal_stdint.h"
|
||||
|
||||
#include "orte/mca/db/base/base.h"
|
||||
#include "db_print.h"
|
||||
|
||||
static int init(struct orte_db_base_module_t *imod);
|
||||
static void finalize(struct orte_db_base_module_t *imod);
|
||||
static int store(struct orte_db_base_module_t *imod,
|
||||
const char *primary_key,
|
||||
opal_list_t *kvs);
|
||||
|
||||
mca_db_print_module_t mca_db_print_module = {
|
||||
{
|
||||
init,
|
||||
finalize,
|
||||
store,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
},
|
||||
};
|
||||
|
||||
static int init(struct orte_db_base_module_t *imod)
|
||||
{
|
||||
mca_db_print_module_t *mod = (mca_db_print_module_t*)imod;
|
||||
|
||||
if (0 == strcmp(mod->file, "-")) {
|
||||
mod->fp = stdout;
|
||||
} else if (0 == strcmp(mod->file, "+")) {
|
||||
mod->fp = stderr;
|
||||
} else if (NULL == (mod->fp = fopen(mod->file, "w"))) {
|
||||
opal_output(0, "ERROR: cannot open log file %s", mod->file);
|
||||
return ORTE_ERROR;
|
||||
}
|
||||
|
||||
return ORTE_SUCCESS;
|
||||
}
|
||||
|
||||
static void finalize(struct orte_db_base_module_t *imod)
|
||||
{
|
||||
mca_db_print_module_t *mod = (mca_db_print_module_t*)imod;
|
||||
|
||||
if (NULL != mod->fp &&
|
||||
stdout != mod->fp &&
|
||||
stderr != mod->fp) {
|
||||
fclose(mod->fp);
|
||||
}
|
||||
}
|
||||
|
||||
static int store(struct orte_db_base_module_t *imod,
|
||||
const char *primary_key,
|
||||
opal_list_t *kvs)
|
||||
{
|
||||
mca_db_print_module_t *mod = (mca_db_print_module_t*)imod;
|
||||
char **cmdargs=NULL, *vstr;
|
||||
time_t nowtime;
|
||||
struct tm nowtm;
|
||||
char tbuf[1024];
|
||||
opal_value_t *kv;
|
||||
|
||||
/* cycle through the provided values and print them */
|
||||
OPAL_LIST_FOREACH(kv, kvs, opal_value_t) {
|
||||
switch (kv->type) {
|
||||
case OPAL_STRING:
|
||||
snprintf(tbuf, sizeof(tbuf), "%s", kv->data.string);
|
||||
opal_argv_append_nosize(&cmdargs, tbuf);
|
||||
break;
|
||||
case OPAL_SIZE:
|
||||
snprintf(tbuf, sizeof(tbuf), "%" PRIsize_t "", kv->data.size);
|
||||
opal_argv_append_nosize(&cmdargs, tbuf);
|
||||
break;
|
||||
case OPAL_INT:
|
||||
snprintf(tbuf, sizeof(tbuf), "%d", kv->data.integer);
|
||||
opal_argv_append_nosize(&cmdargs, tbuf);
|
||||
break;
|
||||
case OPAL_INT8:
|
||||
snprintf(tbuf, sizeof(tbuf), "%" PRIi8 "", kv->data.int8);
|
||||
opal_argv_append_nosize(&cmdargs, tbuf);
|
||||
break;
|
||||
case OPAL_INT16:
|
||||
snprintf(tbuf, sizeof(tbuf), "%" PRIi16 "", kv->data.int16);
|
||||
opal_argv_append_nosize(&cmdargs, tbuf);
|
||||
break;
|
||||
case OPAL_INT32:
|
||||
snprintf(tbuf, sizeof(tbuf), "%" PRIi32 "", kv->data.int32);
|
||||
opal_argv_append_nosize(&cmdargs, tbuf);
|
||||
break;
|
||||
case OPAL_INT64:
|
||||
snprintf(tbuf, sizeof(tbuf), "%" PRIi64 "", kv->data.int64);
|
||||
opal_argv_append_nosize(&cmdargs, tbuf);
|
||||
break;
|
||||
case OPAL_UINT:
|
||||
snprintf(tbuf, sizeof(tbuf), "%u", kv->data.uint);
|
||||
opal_argv_append_nosize(&cmdargs, tbuf);
|
||||
break;
|
||||
case OPAL_UINT8:
|
||||
snprintf(tbuf, sizeof(tbuf), "%" PRIu8 "", kv->data.uint8);
|
||||
opal_argv_append_nosize(&cmdargs, tbuf);
|
||||
break;
|
||||
case OPAL_UINT16:
|
||||
snprintf(tbuf, sizeof(tbuf), "%" PRIu16 "", kv->data.uint16);
|
||||
opal_argv_append_nosize(&cmdargs, tbuf);
|
||||
break;
|
||||
case OPAL_UINT32:
|
||||
snprintf(tbuf, sizeof(tbuf), "%" PRIu32 "", kv->data.uint32);
|
||||
opal_argv_append_nosize(&cmdargs, tbuf);
|
||||
break;
|
||||
case OPAL_UINT64:
|
||||
snprintf(tbuf, sizeof(tbuf), "%" PRIu64 "", kv->data.uint64);
|
||||
opal_argv_append_nosize(&cmdargs, tbuf);
|
||||
break;
|
||||
case OPAL_PID:
|
||||
snprintf(tbuf, sizeof(tbuf), "%lu", (unsigned long)kv->data.pid);
|
||||
opal_argv_append_nosize(&cmdargs, tbuf);
|
||||
break;
|
||||
case OPAL_FLOAT:
|
||||
snprintf(tbuf, sizeof(tbuf), "%f", kv->data.fval);
|
||||
opal_argv_append_nosize(&cmdargs, tbuf);
|
||||
break;
|
||||
case OPAL_TIMEVAL:
|
||||
/* we only care about seconds */
|
||||
nowtime = kv->data.tv.tv_sec;
|
||||
(void)localtime_r(&nowtime, &nowtm);
|
||||
strftime(tbuf, sizeof(tbuf), "%Y-%m-%d %H:%M:%S", &nowtm);
|
||||
opal_argv_append_nosize(&cmdargs, tbuf);
|
||||
break;
|
||||
default:
|
||||
snprintf(tbuf, sizeof(tbuf), "Unsupported type: %s",
|
||||
opal_dss.lookup_data_type(kv->type));
|
||||
opal_argv_append_nosize(&cmdargs, tbuf);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* assemble the value string */
|
||||
vstr = opal_argv_join(cmdargs, ',');
|
||||
|
||||
/* print it */
|
||||
fprintf(mod->fp, "%s\n", vstr);
|
||||
free(vstr);
|
||||
opal_argv_free(cmdargs);
|
||||
|
||||
return OPAL_SUCCESS;
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2012-2013 Los Alamos National Security, Inc. All rights reserved.
|
||||
* Copyright (c) 2014 Intel, Inc. All rights reserved.
|
||||
* $COPYRIGHT$
|
||||
*
|
||||
* Additional copyrights may follow
|
||||
*
|
||||
* $HEADER$
|
||||
*/
|
||||
|
||||
#ifndef ORTE_DB_PRINT_H
|
||||
#define ORTE_DB_PRINT_H
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "opal/class/opal_pointer_array.h"
|
||||
|
||||
#include "orte/mca/db/db.h"
|
||||
|
||||
BEGIN_C_DECLS
|
||||
|
||||
ORTE_MODULE_DECLSPEC extern orte_db_base_component_t mca_db_print_component;
|
||||
|
||||
typedef struct {
|
||||
orte_db_base_module_t api;
|
||||
char *file;
|
||||
FILE *fp;
|
||||
} mca_db_print_module_t;
|
||||
ORTE_MODULE_DECLSPEC extern mca_db_print_module_t mca_db_print_module;
|
||||
|
||||
END_C_DECLS
|
||||
|
||||
#endif /* ORTE_DB_PRINT_H */
|
@ -1,122 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2012-2013 Los Alamos National Security, Inc. All rights reserved.
|
||||
* Copyright (c) 2013-2014 Intel, Inc. All rights reserved.
|
||||
* $COPYRIGHT$
|
||||
*
|
||||
* Additional copyrights may follow
|
||||
*
|
||||
* $HEADER$
|
||||
*/
|
||||
|
||||
#include "orte_config.h"
|
||||
#include "orte/constants.h"
|
||||
|
||||
#include "opal/mca/base/base.h"
|
||||
|
||||
#include "orte/mca/errmgr/errmgr.h"
|
||||
|
||||
#include "orte/mca/db/db.h"
|
||||
#include "orte/mca/db/base/base.h"
|
||||
#include "db_print.h"
|
||||
|
||||
static int component_register(void);
|
||||
static bool component_avail(void);
|
||||
static orte_db_base_module_t *component_create(opal_list_t *props);
|
||||
|
||||
/*
|
||||
* Instantiate the public struct with all of our public information
|
||||
* and pointers to our public functions in it
|
||||
*/
|
||||
orte_db_base_component_t mca_db_print_component = {
|
||||
{
|
||||
ORTE_DB_BASE_VERSION_2_0_0,
|
||||
|
||||
/* Component name and version */
|
||||
"print",
|
||||
ORTE_MAJOR_VERSION,
|
||||
ORTE_MINOR_VERSION,
|
||||
ORTE_RELEASE_VERSION,
|
||||
|
||||
/* Component open and close functions */
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
component_register
|
||||
},
|
||||
{
|
||||
/* The component is checkpoint ready */
|
||||
MCA_BASE_METADATA_PARAM_CHECKPOINT
|
||||
},
|
||||
5,
|
||||
component_avail,
|
||||
component_create,
|
||||
NULL
|
||||
};
|
||||
|
||||
static char *filename;
|
||||
|
||||
static int component_register(void)
|
||||
{
|
||||
filename = NULL;
|
||||
(void) mca_base_component_var_register (&mca_db_print_component.base_version,
|
||||
"file", "Print to the indicated file (- => stdout, + => stderr)",
|
||||
MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0,
|
||||
OPAL_INFO_LVL_9,
|
||||
MCA_BASE_VAR_SCOPE_READONLY,
|
||||
&filename);
|
||||
|
||||
return ORTE_SUCCESS;
|
||||
}
|
||||
|
||||
static bool component_avail(void)
|
||||
{
|
||||
/* always available */
|
||||
return true;
|
||||
}
|
||||
|
||||
static orte_db_base_module_t *component_create(opal_list_t *props)
|
||||
{
|
||||
mca_db_print_module_t *mod;
|
||||
opal_value_t *kv;
|
||||
bool found;
|
||||
char *file;
|
||||
|
||||
/* if the props include a filename, then use it */
|
||||
found = false;
|
||||
if (NULL != props) {
|
||||
OPAL_LIST_FOREACH(kv, props, opal_value_t) {
|
||||
if (0 == strcmp(kv->key, "printfile")) {
|
||||
file = kv->data.string;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
/* otherwise, fall back to the default */
|
||||
if (NULL != filename) {
|
||||
file = filename;
|
||||
} else {
|
||||
/* nothing for us to do */
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
mod = (mca_db_print_module_t*)malloc(sizeof(mca_db_print_module_t));
|
||||
if (NULL == mod) {
|
||||
ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE);
|
||||
return NULL;
|
||||
}
|
||||
/* copy the APIs across */
|
||||
memcpy(mod, &mca_db_print_module.api, sizeof(orte_db_base_module_t));
|
||||
|
||||
/* set the globals */
|
||||
mod->file = strdup(file);
|
||||
mod->fp = NULL;
|
||||
|
||||
/* let the module init */
|
||||
if (ORTE_SUCCESS != mod->api.init((struct orte_db_base_module_t*)mod)) {
|
||||
free(mod);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return (orte_db_base_module_t*)mod;
|
||||
}
|
||||
|
@ -1,40 +0,0 @@
|
||||
#
|
||||
# Copyright (c) 2012 Los Alamos National Security, Inc. All rights reserved.
|
||||
# $COPYRIGHT$
|
||||
#
|
||||
# Additional copyrights may follow
|
||||
#
|
||||
# $HEADER$
|
||||
#
|
||||
|
||||
dist_ompidata_DATA = help-db-sqlite.txt
|
||||
|
||||
sources = \
|
||||
db_sqlite.h \
|
||||
db_sqlite_component.c \
|
||||
db_sqlite.c
|
||||
|
||||
# Make the output library in this directory, and name it either
|
||||
# mca_<type>_<name>.la (for DSO builds) or libmca_<type>_<name>.la
|
||||
# (for static builds).
|
||||
|
||||
if MCA_BUILD_orte_db_sqlite_DSO
|
||||
component_noinst =
|
||||
component_install = mca_db_sqlite.la
|
||||
else
|
||||
component_noinst = libmca_db_sqlite.la
|
||||
component_install =
|
||||
endif
|
||||
|
||||
mcacomponentdir = $(ompilibdir)
|
||||
mcacomponent_LTLIBRARIES = $(component_install)
|
||||
mca_db_sqlite_la_CPPFLAGS = $(db_sqlite_CPPFLAGS)
|
||||
mca_db_sqlite_la_SOURCES = $(sources)
|
||||
mca_db_sqlite_la_LDFLAGS = -module -avoid-version $(db_sqlite_LDFLAGS)
|
||||
mca_db_sqlite_la_LIBADD = $(db_sqlite_LIBS)
|
||||
|
||||
noinst_LTLIBRARIES = $(component_noinst)
|
||||
libmca_db_sqlite_la_CPPFLAGS = $(db_sqlite_CPPFLAGS)
|
||||
libmca_db_sqlite_la_SOURCES =$(sources)
|
||||
libmca_db_sqlite_la_LDFLAGS = -module -avoid-version $(db_sqlite_LDFLAGS)
|
||||
libmca_db_sqlite_la_LIBADD = $(db_sqlite_LIBS)
|
@ -1,40 +0,0 @@
|
||||
dnl -*- shell-script -*-
|
||||
dnl
|
||||
dnl Copyright (c) 2012-2013 Los Alamos National Security, Inc. All rights reserved.
|
||||
dnl Copyright (c) 2013-2014 Intel, Inc. All rights reserved.
|
||||
dnl $COPYRIGHT$
|
||||
dnl
|
||||
dnl Additional copyrights may follow
|
||||
dnl
|
||||
dnl $HEADER$
|
||||
dnl
|
||||
|
||||
# MCA_db_sqlite_CONFIG([action-if-found], [action-if-not-found])
|
||||
# -----------------------------------------------------------
|
||||
AC_DEFUN([MCA_orte_db_sqlite_CONFIG], [
|
||||
AC_CONFIG_FILES([orte/mca/db/sqlite/Makefile])
|
||||
|
||||
AC_ARG_WITH([sqlite3],
|
||||
[AC_HELP_STRING([--with-sqlite3],
|
||||
[Build sqlite3 support (default: no)])],
|
||||
[], with_sqlite3=no)
|
||||
|
||||
# do not build if rte is disabled or support not requested
|
||||
AS_IF([test "$with_sqlite3" != "no"],
|
||||
[AS_IF([test ! -z "$with_sqlite3" -a "$with_sqlite3" != "yes"],
|
||||
[orte_check_sqlite3_dir="$with_sqlite3"])
|
||||
OPAL_CHECK_PACKAGE([db_sqlite],
|
||||
[sqlite3.h],
|
||||
[sqlite3],
|
||||
[sqlite3_open],
|
||||
[],
|
||||
[$orte_check_sqlite3_dir],
|
||||
[],
|
||||
[$1],
|
||||
[$2])],
|
||||
[$2])
|
||||
|
||||
AC_SUBST(db_sqlite_CPPFLAGS)
|
||||
AC_SUBST(db_sqlite_LDFLAGS)
|
||||
AC_SUBST(db_sqlite_LIBS)
|
||||
])dnl
|
@ -1,175 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2012-2013 Los Alamos National Security, Inc. All rights reserved.
|
||||
* Copyright (c) 2014 Intel, Inc. All rights reserved.
|
||||
* $COPYRIGHT$
|
||||
*
|
||||
* Additional copyrights may follow
|
||||
*
|
||||
* $HEADER$
|
||||
*
|
||||
*/
|
||||
|
||||
#include "orte_config.h"
|
||||
#include "orte/constants.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#ifdef HAVE_LIMITS_H
|
||||
#include <limits.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#ifdef HAVE_FCNTL_H
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <sqlite3.h>
|
||||
|
||||
#include "opal/dss/dss_types.h"
|
||||
#include "opal/util/argv.h"
|
||||
#include "opal/util/basename.h"
|
||||
#include "opal/util/os_dirpath.h"
|
||||
#include "opal/util/os_path.h"
|
||||
#include "opal/util/output.h"
|
||||
#include "opal/util/malloc.h"
|
||||
#include "opal/util/basename.h"
|
||||
#include "opal/mca/pstat/base/base.h"
|
||||
|
||||
#include "orte/util/show_help.h"
|
||||
|
||||
#include "orte/mca/db/base/base.h"
|
||||
#include "db_sqlite.h"
|
||||
|
||||
static int init(struct orte_db_base_module_t *imod);
|
||||
static void finalize(struct orte_db_base_module_t *imod);
|
||||
static int store(struct orte_db_base_module_t *imod,
|
||||
const char *primary_key,
|
||||
opal_list_t *kvs);
|
||||
|
||||
mca_db_sqlite_module_t mca_db_sqlite_module = {
|
||||
{
|
||||
init,
|
||||
finalize,
|
||||
store,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
},
|
||||
};
|
||||
|
||||
static int init(struct orte_db_base_module_t *imod)
|
||||
{
|
||||
mca_db_sqlite_module_t *mod = (mca_db_sqlite_module_t*)imod;
|
||||
int i;
|
||||
|
||||
|
||||
/* get the required number of database handles */
|
||||
mod->dbhandles = (sqlite3**)malloc(mod->nthreads * sizeof(sqlite3*));
|
||||
|
||||
/* open the database - this will create the database file if
|
||||
* it doesn't already exist
|
||||
*/
|
||||
for (i=0; i < mod->nthreads; i++) {
|
||||
if (SQLITE_OK != sqlite3_open(mod->dbfile, &mod->dbhandles[i])) {
|
||||
orte_show_help("help-db-sqlite.txt", "cannot-create-sqlite", true, mod->dbfile);
|
||||
return ORTE_ERR_FILE_OPEN_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
return ORTE_SUCCESS;
|
||||
}
|
||||
|
||||
static void finalize(struct orte_db_base_module_t *imod)
|
||||
{
|
||||
mca_db_sqlite_module_t *mod = (mca_db_sqlite_module_t*)imod;
|
||||
int i;
|
||||
|
||||
/* if we are normally terminating, remove the recovery file */
|
||||
if (NULL != mod->dbhandles) {
|
||||
for (i=0; i < mod->nthreads; i++) {
|
||||
if (SQLITE_OK != sqlite3_close(mod->dbhandles[i])) {
|
||||
opal_output(0, "sqlite failed to close");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int store(struct orte_db_base_module_t *imod,
|
||||
const char *primary_key,
|
||||
opal_list_t *kvs)
|
||||
{
|
||||
int i, rc;
|
||||
char *sql, **cmd = NULL, *tmp;
|
||||
sqlite3_stmt *stmt;
|
||||
opal_value_t *kv;
|
||||
|
||||
mca_db_sqlite_module_t *mod = (mca_db_sqlite_module_t*)imod;
|
||||
|
||||
/* setup the insert statement */
|
||||
for (i=0; i < (int)opal_list_get_size(kvs); i++) {
|
||||
opal_argv_append_nosize(&cmd, "?");
|
||||
}
|
||||
tmp = opal_argv_join(cmd, ',');
|
||||
asprintf(&sql, "INSERT INTO %s VALUES (%s)", mod->dbfile, tmp);
|
||||
free(tmp);
|
||||
opal_argv_free(cmd);
|
||||
/* use the next worker thread */
|
||||
ORTE_SQLITE_CMD(prepare_v2(mod->dbhandles[mod->active], sql, strlen(sql)+1, &stmt, NULL), mod->dbhandles[mod->active], &rc);
|
||||
if (SQLITE_OK != rc) {
|
||||
return ORTE_ERROR;
|
||||
}
|
||||
|
||||
/* cycle through the provided values and construct
|
||||
* an insert command for them - note that the values
|
||||
* MUST be in column-order for the database!
|
||||
*/
|
||||
OPAL_LIST_FOREACH(kv, kvs, opal_value_t) {
|
||||
switch (kv->type) {
|
||||
case OPAL_STRING:
|
||||
ORTE_SQLITE_CMD(bind_text(stmt, i, kv->data.string, strlen(kv->data.string), NULL),
|
||||
mod->dbhandles[mod->active], &rc);
|
||||
break;
|
||||
case OPAL_INT32:
|
||||
ORTE_SQLITE_CMD(bind_int(stmt, i, kv->data.int32), mod->dbhandles[mod->active], &rc);
|
||||
break;
|
||||
case OPAL_INT16:
|
||||
ORTE_SQLITE_CMD(bind_int(stmt, i, kv->data.int16), mod->dbhandles[mod->active], &rc);
|
||||
break;
|
||||
case OPAL_PID:
|
||||
ORTE_SQLITE_CMD(bind_int64(stmt, i, kv->data.pid), mod->dbhandles[mod->active], &rc);
|
||||
break;
|
||||
case OPAL_INT64:
|
||||
ORTE_SQLITE_CMD(bind_int64(stmt, i, kv->data.int64), mod->dbhandles[mod->active], &rc);
|
||||
break;
|
||||
case OPAL_FLOAT:
|
||||
ORTE_SQLITE_CMD(bind_double(stmt, i, kv->data.fval), mod->dbhandles[mod->active], &rc);
|
||||
break;
|
||||
case OPAL_TIMEVAL:
|
||||
asprintf(&tmp, "%d.%06d", (int)kv->data.tv.tv_sec, (int)kv->data.tv.tv_usec);
|
||||
ORTE_SQLITE_CMD(bind_text(stmt, i, tmp, strlen(tmp), NULL),
|
||||
mod->dbhandles[mod->active], &rc);
|
||||
free(tmp);
|
||||
break;
|
||||
}
|
||||
if (SQLITE_OK != rc) {
|
||||
return ORTE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
ORTE_SQLITE_OP(step(stmt), DONE, mod->dbhandles[mod->active], &rc);
|
||||
if (SQLITE_OK != rc) {
|
||||
return ORTE_ERROR;
|
||||
}
|
||||
opal_output_verbose(2, orte_db_base_framework.framework_output,
|
||||
"INSERTED ROW %d", (int)sqlite3_last_insert_rowid(mod->dbhandles[mod->active]));
|
||||
|
||||
/* cycle to the next worker thread */
|
||||
mod->active++;
|
||||
if (mod->nthreads < mod->active) {
|
||||
mod->active = 0;
|
||||
}
|
||||
|
||||
return ORTE_SUCCESS;
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2012-2013 Los Alamos National Security, Inc. All rights reserved.
|
||||
* Copyright (c) 2014 Intel, Inc. All rights reserved.
|
||||
* $COPYRIGHT$
|
||||
*
|
||||
* Additional copyrights may follow
|
||||
*
|
||||
* $HEADER$
|
||||
*/
|
||||
|
||||
#ifndef ORTE_DB_SQLITE_H
|
||||
#define ORTE_DB_SQLITE_H
|
||||
|
||||
#include <sqlite3.h>
|
||||
|
||||
#include "orte/mca/db/db.h"
|
||||
|
||||
BEGIN_C_DECLS
|
||||
|
||||
ORTE_MODULE_DECLSPEC extern orte_db_base_component_t mca_db_sqlite_component;
|
||||
typedef struct {
|
||||
orte_db_base_module_t api;
|
||||
char *dbfile;
|
||||
sqlite3 **dbhandles;
|
||||
int nthreads;
|
||||
int active;
|
||||
} mca_db_sqlite_module_t;
|
||||
ORTE_MODULE_DECLSPEC extern mca_db_sqlite_module_t mca_db_sqlite_module;
|
||||
|
||||
|
||||
|
||||
/* Macros for manipulating sqlite */
|
||||
#define ORTE_SQLITE_CMD(f, db, r) \
|
||||
{ \
|
||||
*(r) = sqlite3_ ## f; \
|
||||
if (*(r) != SQLITE_OK) { \
|
||||
opal_output(0, "%s failed with status %d: %s", \
|
||||
#f, *(r), sqlite3_errmsg(db)); \
|
||||
} \
|
||||
} \
|
||||
|
||||
#define ORTE_SQLITE_OP(f, x, db, r) \
|
||||
{ \
|
||||
*(r) = sqlite3_ ## f; \
|
||||
if (*(r) != SQLITE_ ## x) { \
|
||||
opal_output(0, "%s failed with status %d: %s", \
|
||||
#f, *(r), sqlite3_errmsg(db)); \
|
||||
} \
|
||||
} \
|
||||
|
||||
END_C_DECLS
|
||||
|
||||
#endif /* ORTE_DB_SQLITE_H */
|
@ -1,157 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2012-2013 Los Alamos National Security, Inc. All rights reserved.
|
||||
* Copyright (c) 2013-2014 Intel, Inc. All rights reserved.
|
||||
* $COPYRIGHT$
|
||||
*
|
||||
* Additional copyrights may follow
|
||||
*
|
||||
* $HEADER$
|
||||
*
|
||||
* These symbols are in a file by themselves to provide nice linker
|
||||
* semantics. Since linkers generally pull in symbols by object
|
||||
* files, keeping these symbols as the only symbols in this file
|
||||
* prevents utility programs such as "ompi_info" from having to import
|
||||
* entire components just to query their version and parameters.
|
||||
*/
|
||||
|
||||
#include "orte_config.h"
|
||||
#include "orte/constants.h"
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <sqlite3.h>
|
||||
|
||||
#include "opal/mca/base/base.h"
|
||||
|
||||
#include "orte/mca/errmgr/errmgr.h"
|
||||
#include "orte/util/show_help.h"
|
||||
|
||||
#include "orte/mca/db/db.h"
|
||||
#include "orte/mca/db/base/base.h"
|
||||
#include "db_sqlite.h"
|
||||
|
||||
static int component_register(void);
|
||||
static bool component_avail(void);
|
||||
static orte_db_base_module_t *component_create(opal_list_t *props);
|
||||
|
||||
/*
|
||||
* Instantiate the public struct with all of our public information
|
||||
* and pointers to our public functions in it
|
||||
*/
|
||||
orte_db_base_component_t mca_db_sqlite_component = {
|
||||
{
|
||||
ORTE_DB_BASE_VERSION_2_0_0,
|
||||
|
||||
/* Component name and version */
|
||||
"sqlite",
|
||||
ORTE_MAJOR_VERSION,
|
||||
ORTE_MINOR_VERSION,
|
||||
ORTE_RELEASE_VERSION,
|
||||
|
||||
/* Component open and close functions */
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
component_register
|
||||
},
|
||||
{
|
||||
/* The component is checkpoint ready */
|
||||
MCA_BASE_METADATA_PARAM_CHECKPOINT
|
||||
},
|
||||
75,
|
||||
component_avail,
|
||||
component_create,
|
||||
NULL
|
||||
};
|
||||
|
||||
static char *db_file;
|
||||
static int num_worker_threads;
|
||||
static int thread_safe;
|
||||
|
||||
static int component_register(void)
|
||||
{
|
||||
mca_base_component_t *c = &mca_db_sqlite_component.base_version;
|
||||
|
||||
/* retrieve the name of the file to be used */
|
||||
db_file = NULL;
|
||||
(void) mca_base_component_var_register (c, "database", "Name of file to be used for database",
|
||||
MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0,
|
||||
OPAL_INFO_LVL_9,
|
||||
MCA_BASE_VAR_SCOPE_READONLY,
|
||||
&db_file);
|
||||
|
||||
/* retrieve the number of worker threads to be used, if sqlite3 is thread-safe */
|
||||
num_worker_threads = -1;
|
||||
(void) mca_base_component_var_register (c, "num_worker_threads", "Number of worker threads to be used",
|
||||
MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0,
|
||||
OPAL_INFO_LVL_9,
|
||||
MCA_BASE_VAR_SCOPE_READONLY,
|
||||
&num_worker_threads);
|
||||
|
||||
return OPAL_SUCCESS;
|
||||
}
|
||||
|
||||
static bool component_avail(void)
|
||||
{
|
||||
/* initialize sqlite3 */
|
||||
if (SQLITE_OK != sqlite3_initialize()) {
|
||||
return false;
|
||||
}
|
||||
/* check if sqlite was built thread-safe - if not, we won't
|
||||
* use worker threads for thruput
|
||||
*/
|
||||
thread_safe = sqlite3_threadsafe();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static orte_db_base_module_t *component_create(opal_list_t *props)
|
||||
{
|
||||
mca_db_sqlite_module_t *mod;
|
||||
opal_value_t *kv;
|
||||
|
||||
mod = (mca_db_sqlite_module_t*)malloc(sizeof(mca_db_sqlite_module_t));
|
||||
if (NULL == mod) {
|
||||
ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE);
|
||||
return NULL;
|
||||
}
|
||||
memset(mod, 0, sizeof(mca_db_sqlite_module_t));
|
||||
mod->nthreads = -1;
|
||||
|
||||
/* copy the APIs across */
|
||||
memcpy(mod, &mca_db_sqlite_module.api, sizeof(orte_db_base_module_t));
|
||||
|
||||
/* if the props include db info, then use it */
|
||||
OPAL_LIST_FOREACH(kv, props, opal_value_t) {
|
||||
if (0 == strcmp(kv->key, "database")) {
|
||||
mod->dbfile = strdup(kv->data.string);
|
||||
} else if (0 == strcmp(kv->key, "num_worker_threads")) {
|
||||
mod->nthreads = kv->data.integer;
|
||||
}
|
||||
}
|
||||
if (NULL == mod->dbfile) {
|
||||
if (NULL == db_file) {
|
||||
/* nothing was provided - opt out */
|
||||
free(mod);
|
||||
return NULL;
|
||||
}
|
||||
mod->dbfile = strdup(db_file);
|
||||
}
|
||||
if (0 != thread_safe) {
|
||||
mod->nthreads = 1;
|
||||
} else {
|
||||
if (0 > mod->nthreads && 0 < num_worker_threads) {
|
||||
mod->nthreads = num_worker_threads;
|
||||
} else {
|
||||
mod->nthreads = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* let the module init */
|
||||
if (ORTE_SUCCESS != mod->api.init((struct orte_db_base_module_t*)mod)) {
|
||||
mod->api.finalize((struct orte_db_base_module_t*)mod);
|
||||
free(mod);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return (orte_db_base_module_t*)mod;
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
-*- text -*-
|
||||
#
|
||||
# Copyright (c) 2012 Los Alamos National Security, Inc. All rights reserved.
|
||||
# $COPYRIGHT$
|
||||
#
|
||||
# Additional copyrights may follow
|
||||
#
|
||||
# $HEADER$
|
||||
#
|
||||
[file-not-found]
|
||||
WARNING: Could not find specified database file
|
||||
|
||||
File: %s
|
||||
|
||||
Data logging into sqlite3 has been disabled.
|
Загрузка…
x
Ссылка в новой задаче
Block a user