diff --git a/src/core/store.c b/src/core/store.c
index 16d389c1ab5b535da6b8562256384470fd21e6da..3936020d54ccd04b6cc3a9b47d6ed0f25b9627b0 100644 (file)
--- a/src/core/store.c
+++ b/src/core/store.c
static int
host_init(sdb_object_t *obj, va_list ap)
{
- sdb_host_t *sobj = HOST(obj);
+ host_t *sobj = HOST(obj);
int ret;
/* this will consume the first argument (type) of ap */
static void
host_destroy(sdb_object_t *obj)
{
- sdb_host_t *sobj = HOST(obj);
+ host_t *sobj = HOST(obj);
assert(obj);
store_obj_destroy(obj);
static int
service_init(sdb_object_t *obj, va_list ap)
{
- sdb_service_t *sobj = SVC(obj);
+ service_t *sobj = SVC(obj);
int ret;
/* this will consume the first argument (type) of ap */
static void
service_destroy(sdb_object_t *obj)
{
- sdb_service_t *sobj = SVC(obj);
+ service_t *sobj = SVC(obj);
assert(obj);
store_obj_destroy(obj);
};
static sdb_type_t host_type = {
- /* size = */ sizeof(sdb_host_t),
+ /* size = */ sizeof(host_t),
/* init = */ host_init,
/* destroy = */ host_destroy
};
static sdb_type_t service_type = {
- /* size = */ sizeof(sdb_service_t),
+ /* size = */ sizeof(service_t),
/* init = */ service_init,
/* destroy = */ service_destroy
};
};
static sdb_type_t attribute_type = {
- /* size = */ sizeof(sdb_attribute_t),
+ /* size = */ sizeof(attr_t),
/* init = */ attr_init,
/* destroy = */ attr_destroy
};
* private helper functions
*/
-static sdb_host_t *
-lookup_host(sdb_store_t *st, const char *name, bool canonicalize)
-{
- sdb_host_t *host;
- char *cname;
-
- assert(name);
- if (! canonicalize)
- return HOST(sdb_avltree_lookup(st->hosts, name));
-
- cname = strdup(name);
- cname = sdb_plugin_cname(cname);
- if (! cname) {
- sdb_log(SDB_LOG_ERR, "store: strdup failed");
- return NULL;
- }
-
- host = HOST(sdb_avltree_lookup(st->hosts, cname));
- free(cname);
- return host;
-} /* lookup_host */
-
static int
record_backend(sdb_store_obj_t *obj)
{
/* The store's host_lock has to be acquired before calling this function. */
static sdb_avltree_t *
-get_host_children(sdb_host_t *host, int type)
+get_host_children(host_t *host, int type)
{
if ((type != SDB_SERVICE) && (type != SDB_METRIC)
&& (type != SDB_ATTRIBUTE))
{
sdb_store_t *st = SDB_STORE(user_data);
- sdb_host_t *host;
+ host_t *host;
sdb_avltree_t *attrs;
int status = 0;
return -1;
pthread_rwlock_wrlock(&st->host_lock);
- host = lookup_host(st, hostname, /* canonicalize = */ 0);
+ host = HOST(sdb_avltree_lookup(st->hosts, hostname));
attrs = get_host_children(host, SDB_ATTRIBUTE);
if (! attrs) {
sdb_log(SDB_LOG_ERR, "store: Failed to store attribute '%s' - "
{
sdb_store_t *st = SDB_STORE(user_data);
- sdb_host_t *host;
- sdb_service_t *svc;
+ host_t *host;
+ service_t *svc;
sdb_avltree_t *services;
int status = 0;
return -1;
pthread_rwlock_wrlock(&st->host_lock);
- host = lookup_host(st, hostname, /* canonicalize = */ 0);
+ host = HOST(sdb_avltree_lookup(st->hosts, hostname));
services = get_host_children(host, SDB_SERVICE);
sdb_object_deref(SDB_OBJ(host));
if (! services) {
{
sdb_store_t *st = SDB_STORE(user_data);
- sdb_host_t *host;
+ host_t *host;
sdb_avltree_t *services;
- sdb_data_t d;
int status = 0;
return -1;
pthread_rwlock_wrlock(&st->host_lock);
- host = lookup_host(st, hostname, /* canonicalize = */ 0);
+ host = HOST(sdb_avltree_lookup(st->hosts, hostname));
services = get_host_children(host, SDB_SERVICE);
if (! services) {
sdb_log(SDB_LOG_ERR, "store: Failed to store service '%s' - "
sdb_object_deref(SDB_OBJ(host));
pthread_rwlock_unlock(&st->host_lock);
-
- if (status)
- return status;
-
- /* record the hostname as an attribute */
- d.type = SDB_TYPE_STRING;
- d.data.string = SDB_OBJ(host)->name;
- if (store_service_attr(hostname, name, "hostname", &d, last_update, user_data))
- status = -1;
return status;
} /* store_service */
sdb_store_t *st = SDB_STORE(user_data);
sdb_avltree_t *metrics;
- sdb_host_t *host;
+ host_t *host;
sdb_metric_t *m;
int status = 0;
return -1;
pthread_rwlock_wrlock(&st->host_lock);
- host = lookup_host(st, hostname, /* canonicalize = */ 0);
+ host = HOST(sdb_avltree_lookup(st->hosts, hostname));
metrics = get_host_children(host, SDB_METRIC);
sdb_object_deref(SDB_OBJ(host));
if (! metrics) {
sdb_store_t *st = SDB_STORE(user_data);
sdb_store_obj_t *obj = NULL;
- sdb_host_t *host;
+ host_t *host;
sdb_metric_t *metric;
- sdb_data_t d;
sdb_avltree_t *metrics;
}
pthread_rwlock_wrlock(&st->host_lock);
- host = lookup_host(st, hostname, /* canonicalize = */ 0);
+ host = HOST(sdb_avltree_lookup(st->hosts, hostname));
metrics = get_host_children(host, SDB_METRIC);
if (! metrics) {
sdb_log(SDB_LOG_ERR, "store: Failed to store metric '%s' - "
if (store_metric_store(metric, store))
status = -1;
pthread_rwlock_unlock(&st->host_lock);
-
- /* record the hostname as an attribute */
- d.type = SDB_TYPE_STRING;
- d.data.string = SDB_OBJ(host)->name;
- if (store_metric_attr(hostname, name, "hostname", &d, last_update, user_data))
- status = -1;
return status;
} /* store_metric */
sdb_store_obj_t *
sdb_store_get_host(sdb_store_t *store, const char *name)
{
- sdb_host_t *host;
+ host_t *host;
if ((! store) || (! name))
return NULL;
- host = lookup_host(store, name, /* canonicalize = */ 0);
+ host = HOST(sdb_avltree_lookup(store->hosts, name));
if (! host)
return NULL;
sdb_timeseries_opts_t *opts, sdb_strbuf_t *buf)
{
sdb_avltree_t *metrics;
- sdb_host_t *host;
+ host_t *host;
sdb_metric_t *m;
sdb_timeseries_t *ts;
return -1;
pthread_rwlock_rdlock(&store->host_lock);
- host = lookup_host(store, hostname, /* canonicalize = */ 1);
+ host = HOST(sdb_avltree_lookup(store->hosts, hostname));
metrics = get_host_children(host, SDB_METRIC);
sdb_object_deref(SDB_OBJ(host));
if (! metrics) {