summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: e98b8be)
raw | patch | inline | side by side (parent: e98b8be)
author | Sebastian Harl <sh@tokkee.org> | |
Wed, 7 Oct 2015 20:25:29 +0000 (22:25 +0200) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Wed, 7 Oct 2015 20:25:29 +0000 (22:25 +0200) |
15 files changed:
index e8514879c1e8ba43ad5af1ec89791a09452357e0..2f9d96cd068b989f908ad94b88c071bbf19f3924 100644 (file)
--- a/src/core/store-private.h
+++ b/src/core/store-private.h
*/
/*
- * private data structures used by the store module
+ * private data structures used by the memstore module
*/
#ifndef SDB_CORE_STORE_PRIVATE_H
* core types
*/
-struct sdb_store_obj {
+struct sdb_memstore_obj {
sdb_object_t super;
#define _name super.name
sdb_time_t interval; /* moving average */
char **backends;
size_t backends_num;
- sdb_store_obj_t *parent;
+ sdb_memstore_obj_t *parent;
};
-#define STORE_OBJ(obj) ((sdb_store_obj_t *)(obj))
-#define STORE_CONST_OBJ(obj) ((const sdb_store_obj_t *)(obj))
+#define STORE_OBJ(obj) ((sdb_memstore_obj_t *)(obj))
+#define STORE_CONST_OBJ(obj) ((const sdb_memstore_obj_t *)(obj))
typedef struct {
- sdb_store_obj_t super;
+ sdb_memstore_obj_t super;
sdb_data_t value;
} attr_t;
#define CONST_ATTR(obj) ((const attr_t *)(obj))
typedef struct {
- sdb_store_obj_t super;
+ sdb_memstore_obj_t super;
sdb_avltree_t *attributes;
} service_t;
#define CONST_SVC(obj) ((const service_t *)(obj))
typedef struct {
- sdb_store_obj_t super;
+ sdb_memstore_obj_t super;
sdb_avltree_t *attributes;
struct {
char *type;
char *id;
} store;
-} sdb_metric_t;
-#define METRIC(obj) ((sdb_metric_t *)(obj))
+} metric_t;
+#define METRIC(obj) ((metric_t *)(obj))
typedef struct {
- sdb_store_obj_t super;
+ sdb_memstore_obj_t super;
sdb_avltree_t *services;
sdb_avltree_t *metrics;
* querying
*/
-struct sdb_store_query {
+struct sdb_memstore_query {
sdb_object_t super;
sdb_ast_node_t *ast;
- sdb_store_matcher_t *matcher;
- sdb_store_matcher_t *filter;
+ sdb_memstore_matcher_t *matcher;
+ sdb_memstore_matcher_t *filter;
};
-#define QUERY(m) ((sdb_store_query_t *)(m))
+#define QUERY(m) ((sdb_memstore_query_t *)(m))
/*
* expressions
/* >0: operator id */
};
-struct sdb_store_expr {
+struct sdb_memstore_expr {
sdb_object_t super;
int type; /* see above */
int data_type;
- sdb_store_expr_t *left;
- sdb_store_expr_t *right;
+ sdb_memstore_expr_t *left;
+ sdb_memstore_expr_t *right;
sdb_data_t data;
};
: "UNKNOWN")
/* matcher base type */
-struct sdb_store_matcher {
+struct sdb_memstore_matcher {
sdb_object_t super;
/* type of the matcher */
int type;
};
-#define M(m) ((sdb_store_matcher_t *)(m))
+#define M(m) ((sdb_memstore_matcher_t *)(m))
/* infix operator matcher */
typedef struct {
- sdb_store_matcher_t super;
+ sdb_memstore_matcher_t super;
/* left and right hand operands */
- sdb_store_matcher_t *left;
- sdb_store_matcher_t *right;
+ sdb_memstore_matcher_t *left;
+ sdb_memstore_matcher_t *right;
} op_matcher_t;
#define OP_M(m) ((op_matcher_t *)(m))
/* unary operator matcher */
typedef struct {
- sdb_store_matcher_t super;
+ sdb_memstore_matcher_t super;
/* operand */
- sdb_store_matcher_t *op;
+ sdb_memstore_matcher_t *op;
} uop_matcher_t;
#define UOP_M(m) ((uop_matcher_t *)(m))
/* iter matcher */
typedef struct {
- sdb_store_matcher_t super;
- sdb_store_expr_t *iter;
- sdb_store_matcher_t *m;
+ sdb_memstore_matcher_t super;
+ sdb_memstore_expr_t *iter;
+ sdb_memstore_matcher_t *m;
} iter_matcher_t;
#define ITER_M(m) ((iter_matcher_t *)(m))
/* compare operator matcher */
typedef struct {
- sdb_store_matcher_t super;
+ sdb_memstore_matcher_t super;
/* left and right hand expressions */
- sdb_store_expr_t *left;
- sdb_store_expr_t *right;
+ sdb_memstore_expr_t *left;
+ sdb_memstore_expr_t *right;
} cmp_matcher_t;
#define CMP_M(m) ((cmp_matcher_t *)(m))
typedef struct {
- sdb_store_matcher_t super;
- sdb_store_expr_t *expr;
+ sdb_memstore_matcher_t super;
+ sdb_memstore_expr_t *expr;
} unary_matcher_t;
#define UNARY_M(m) ((unary_matcher_t *)(m))
diff --git a/src/core/store.c b/src/core/store.c
index fa72955886bfa04778daa110bc02515b909919b1..7fc11e178373c4fe6637e159da754c97e4e43c8d 100644 (file)
--- a/src/core/store.c
+++ b/src/core/store.c
* private types
*/
-struct sdb_store {
+struct sdb_memstore {
sdb_object_t super;
/* hosts are the top-level entries and
/* internal representation of a to-be-stored object */
typedef struct {
- sdb_store_obj_t *parent;
+ sdb_memstore_obj_t *parent;
sdb_avltree_t *parent_tree;
int type;
const char *name;
store_init(sdb_object_t *obj, va_list __attribute__((unused)) ap)
{
int err;
- if (! (SDB_STORE(obj)->hosts = sdb_avltree_create()))
+ if (! (SDB_MEMSTORE(obj)->hosts = sdb_avltree_create()))
return -1;
- if ((err = pthread_rwlock_init(&SDB_STORE(obj)->host_lock,
+ if ((err = pthread_rwlock_init(&SDB_MEMSTORE(obj)->host_lock,
/* attr = */ NULL))) {
char errbuf[128];
sdb_log(SDB_LOG_ERR, "store: Failed to initialize lock: %s",
store_destroy(sdb_object_t *obj)
{
int err;
- if ((err = pthread_rwlock_destroy(&SDB_STORE(obj)->host_lock))) {
+ if ((err = pthread_rwlock_destroy(&SDB_MEMSTORE(obj)->host_lock))) {
char errbuf[128];
sdb_log(SDB_LOG_ERR, "store: Failed to destroy lock: %s",
sdb_strerror(err, errbuf, sizeof(errbuf)));
return;
}
- sdb_avltree_destroy(SDB_STORE(obj)->hosts);
- SDB_STORE(obj)->hosts = NULL;
+ sdb_avltree_destroy(SDB_MEMSTORE(obj)->hosts);
+ SDB_MEMSTORE(obj)->hosts = NULL;
} /* store_destroy */
static int
store_obj_init(sdb_object_t *obj, va_list ap)
{
- sdb_store_obj_t *sobj = STORE_OBJ(obj);
+ sdb_memstore_obj_t *sobj = STORE_OBJ(obj);
sobj->type = va_arg(ap, int);
static void
store_obj_destroy(sdb_object_t *obj)
{
- sdb_store_obj_t *sobj = STORE_OBJ(obj);
+ sdb_memstore_obj_t *sobj = STORE_OBJ(obj);
size_t i;
for (i = 0; i < sobj->backends_num; ++i)
static int
metric_init(sdb_object_t *obj, va_list ap)
{
- sdb_metric_t *sobj = METRIC(obj);
+ metric_t *sobj = METRIC(obj);
int ret;
/* this will consume the first argument (type) of ap */
static void
metric_destroy(sdb_object_t *obj)
{
- sdb_metric_t *sobj = METRIC(obj);
+ metric_t *sobj = METRIC(obj);
assert(obj);
store_obj_destroy(obj);
} /* attr_destroy */
static sdb_type_t store_type = {
- /* size = */ sizeof(sdb_store_t),
+ /* size = */ sizeof(sdb_memstore_t),
/* init = */ store_init,
/* destroy = */ store_destroy,
};
};
static sdb_type_t metric_type = {
- /* size = */ sizeof(sdb_metric_t),
+ /* size = */ sizeof(metric_t),
/* init = */ metric_init,
/* destroy = */ metric_destroy
};
*/
static int
-record_backends(sdb_store_obj_t *obj,
+record_backends(sdb_memstore_obj_t *obj,
const char * const *backends, size_t backends_num)
{
char **tmp;
} /* record_backends */
static int
-store_obj(store_obj_t *obj, sdb_store_obj_t **updated_obj)
+store_obj(store_obj_t *obj, sdb_memstore_obj_t **updated_obj)
{
- sdb_store_obj_t *old, *new;
+ sdb_memstore_obj_t *old, *new;
int status = 0;
assert(obj->parent_tree);
} /* store_obj */
static int
-store_metric_store(sdb_metric_t *metric, sdb_store_metric_t *m)
+store_metric_store(metric_t *metric, sdb_store_metric_t *m)
{
char *type = metric->store.type;
char *id = metric->store.id;
static int
store_attribute(sdb_store_attribute_t *attr, sdb_object_t *user_data)
{
- sdb_store_t *st = SDB_STORE(user_data);
+ sdb_memstore_t *st = SDB_MEMSTORE(user_data);
store_obj_t obj = STORE_OBJ_INIT;
- sdb_store_obj_t *new = NULL;
+ sdb_memstore_obj_t *new = NULL;
const char *hostname;
host_t *host;
static int
store_host(sdb_store_host_t *host, sdb_object_t *user_data)
{
- sdb_store_t *st = SDB_STORE(user_data);
+ sdb_memstore_t *st = SDB_MEMSTORE(user_data);
store_obj_t obj = { NULL, st->hosts, SDB_HOST, NULL, 0, NULL, 0 };
int status = 0;
static int
store_service(sdb_store_service_t *service, sdb_object_t *user_data)
{
- sdb_store_t *st = SDB_STORE(user_data);
+ sdb_memstore_t *st = SDB_MEMSTORE(user_data);
store_obj_t obj = STORE_OBJ_INIT;
host_t *host;
static int
store_metric(sdb_store_metric_t *metric, sdb_object_t *user_data)
{
- sdb_store_t *st = SDB_STORE(user_data);
+ sdb_memstore_t *st = SDB_MEMSTORE(user_data);
store_obj_t obj = STORE_OBJ_INIT;
- sdb_store_obj_t *new = NULL;
+ sdb_memstore_obj_t *new = NULL;
host_t *host;
int status = 0;
return status;
} /* store_metric */
-sdb_store_writer_t sdb_store_writer = {
+sdb_store_writer_t sdb_memstore_writer = {
store_host, store_service, store_metric, store_attribute,
};
sdb_strbuf_t __attribute__((unused)) *errbuf,
sdb_object_t __attribute__((unused)) *user_data)
{
- return SDB_OBJ(sdb_store_query_prepare(ast));
+ return SDB_OBJ(sdb_memstore_query_prepare(ast));
} /* prepare_query */
static int
sdb_store_writer_t *w, sdb_object_t *wd, sdb_strbuf_t *errbuf,
sdb_object_t *user_data)
{
- return sdb_store_query_execute(SDB_STORE(user_data),
+ return sdb_memstore_query_execute(SDB_MEMSTORE(user_data),
QUERY(q), w, wd, errbuf);
} /* execute_query */
-sdb_store_reader_t sdb_store_reader = {
+sdb_store_reader_t sdb_memstore_reader = {
prepare_query, execute_query,
};
* public API
*/
-sdb_store_t *
-sdb_store_create(void)
+sdb_memstore_t *
+sdb_memstore_create(void)
{
- return SDB_STORE(sdb_object_create("store", store_type));
-} /* sdb_store_create */
+ return SDB_MEMSTORE(sdb_object_create("store", store_type));
+} /* sdb_memstore_create */
int
-sdb_store_host(sdb_store_t *store, const char *name, sdb_time_t last_update)
+sdb_memstore_host(sdb_memstore_t *store, const char *name, sdb_time_t last_update)
{
sdb_store_host_t host = {
name, last_update, 0, NULL, 0,
};
return store_host(&host, SDB_OBJ(store));
-} /* sdb_store_host */
+} /* sdb_memstore_host */
int
-sdb_store_service(sdb_store_t *store, const char *hostname, const char *name,
+sdb_memstore_service(sdb_memstore_t *store, const char *hostname, const char *name,
sdb_time_t last_update)
{
sdb_store_service_t service = {
hostname, name, last_update, 0, NULL, 0,
};
return store_service(&service, SDB_OBJ(store));
-} /* sdb_store_service */
+} /* sdb_memstore_service */
int
-sdb_store_metric(sdb_store_t *store, const char *hostname, const char *name,
+sdb_memstore_metric(sdb_memstore_t *store, const char *hostname, const char *name,
sdb_metric_store_t *metric_store, sdb_time_t last_update)
{
sdb_store_metric_t metric = {
metric.store.id = metric_store->id;
}
return store_metric(&metric, SDB_OBJ(store));
-} /* sdb_store_metric */
+} /* sdb_memstore_metric */
int
-sdb_store_attribute(sdb_store_t *store, const char *hostname,
+sdb_memstore_attribute(sdb_memstore_t *store, const char *hostname,
const char *key, const sdb_data_t *value, sdb_time_t last_update)
{
sdb_store_attribute_t attr = {
attr.value = *value;
}
return store_attribute(&attr, SDB_OBJ(store));
-} /* sdb_store_attribute */
+} /* sdb_memstore_attribute */
int
-sdb_store_service_attr(sdb_store_t *store, const char *hostname,
+sdb_memstore_service_attr(sdb_memstore_t *store, const char *hostname,
const char *service, const char *key, const sdb_data_t *value,
sdb_time_t last_update)
{
attr.value = *value;
}
return store_attribute(&attr, SDB_OBJ(store));
-} /* sdb_store_service_attr */
+} /* sdb_memstore_service_attr */
int
-sdb_store_metric_attr(sdb_store_t *store, const char *hostname,
+sdb_memstore_metric_attr(sdb_memstore_t *store, const char *hostname,
const char *metric, const char *key, const sdb_data_t *value,
sdb_time_t last_update)
{
attr.value = *value;
}
return store_attribute(&attr, SDB_OBJ(store));
-} /* sdb_store_metric_attr */
+} /* sdb_memstore_metric_attr */
-sdb_store_obj_t *
-sdb_store_get_host(sdb_store_t *store, const char *name)
+sdb_memstore_obj_t *
+sdb_memstore_get_host(sdb_memstore_t *store, const char *name)
{
host_t *host;
return NULL;
return STORE_OBJ(host);
-} /* sdb_store_get_host */
+} /* sdb_memstore_get_host */
-sdb_store_obj_t *
-sdb_store_get_child(sdb_store_obj_t *host, int type, const char *name)
+sdb_memstore_obj_t *
+sdb_memstore_get_child(sdb_memstore_obj_t *host, int type, const char *name)
{
sdb_avltree_t *children;
if (! children)
return NULL;
return STORE_OBJ(sdb_avltree_lookup(children, name));
-} /* sdb_store_get_child */
+} /* sdb_memstore_get_child */
int
-sdb_store_get_field(sdb_store_obj_t *obj, int field, sdb_data_t *res)
+sdb_memstore_get_field(sdb_memstore_obj_t *obj, int field, sdb_data_t *res)
{
sdb_data_t tmp;
else
sdb_data_free_datum(&tmp);
return 0;
-} /* sdb_store_get_field */
+} /* sdb_memstore_get_field */
int
-sdb_store_get_attr(sdb_store_obj_t *obj, const char *name, sdb_data_t *res,
- sdb_store_matcher_t *filter)
+sdb_memstore_get_attr(sdb_memstore_obj_t *obj, const char *name, sdb_data_t *res,
+ sdb_memstore_matcher_t *filter)
{
sdb_avltree_t *tree = NULL;
- sdb_store_obj_t *attr;
+ sdb_memstore_obj_t *attr;
if ((! obj) || (! name))
return -1;
attr = STORE_OBJ(sdb_avltree_lookup(tree, name));
if (! attr)
return -1;
- if (filter && (! sdb_store_matcher_matches(filter, attr, NULL))) {
+ if (filter && (! sdb_memstore_matcher_matches(filter, attr, NULL))) {
sdb_object_deref(SDB_OBJ(attr));
return -1;
}
sdb_data_copy(res, &ATTR(attr)->value);
sdb_object_deref(SDB_OBJ(attr));
return 0;
-} /* sdb_store_get_attr */
+} /* sdb_memstore_get_attr */
int
-sdb_store_scan(sdb_store_t *store, int type,
- sdb_store_matcher_t *m, sdb_store_matcher_t *filter,
- sdb_store_lookup_cb cb, void *user_data)
+sdb_memstore_scan(sdb_memstore_t *store, int type,
+ sdb_memstore_matcher_t *m, sdb_memstore_matcher_t *filter,
+ sdb_memstore_lookup_cb cb, void *user_data)
{
sdb_avltree_iter_t *host_iter = NULL;
int status = 0;
/* has_next returns false if the iterator is NULL */
while (sdb_avltree_iter_has_next(host_iter)) {
- sdb_store_obj_t *host;
+ sdb_memstore_obj_t *host;
sdb_avltree_iter_t *iter = NULL;
host = STORE_OBJ(sdb_avltree_iter_get_next(host_iter));
assert(host);
- if (! sdb_store_matcher_matches(filter, host, NULL))
+ if (! sdb_memstore_matcher_matches(filter, host, NULL))
continue;
if (type == SDB_SERVICE)
if (iter) {
while (sdb_avltree_iter_has_next(iter)) {
- sdb_store_obj_t *obj;
+ sdb_memstore_obj_t *obj;
obj = STORE_OBJ(sdb_avltree_iter_get_next(iter));
assert(obj);
- if (sdb_store_matcher_matches(m, obj, filter)) {
+ if (sdb_memstore_matcher_matches(m, obj, filter)) {
if (cb(obj, filter, user_data)) {
sdb_log(SDB_LOG_ERR, "store: Callback returned "
"an error while scanning");
}
}
}
- else if (sdb_store_matcher_matches(m, host, filter)) {
+ else if (sdb_memstore_matcher_matches(m, host, filter)) {
if (cb(host, filter, user_data)) {
sdb_log(SDB_LOG_ERR, "store: Callback returned "
"an error while scanning");
sdb_avltree_iter_destroy(host_iter);
pthread_rwlock_unlock(&store->host_lock);
return status;
-} /* sdb_store_scan */
+} /* sdb_memstore_scan */
/* vim: set tw=78 sw=4 ts=4 noexpandtab : */
diff --git a/src/core/store_exec.c b/src/core/store_exec.c
index d4e308806bac8ece40c9a12a20885df768c2dffe..9b4ea0767828a0bfd45d6bd18ee73bb7415e0b56 100644 (file)
--- a/src/core/store_exec.c
+++ b/src/core/store_exec.c
*/
typedef struct {
- sdb_store_obj_t *current_host;
+ sdb_memstore_obj_t *current_host;
sdb_store_writer_t *w;
sdb_object_t *wd;
} iter_t;
static int
-maybe_emit_host(iter_t *iter, sdb_store_obj_t *obj)
+maybe_emit_host(iter_t *iter, sdb_memstore_obj_t *obj)
{
if ((obj->type == SDB_HOST) || (obj->type == SDB_ATTRIBUTE))
return 0;
if (iter->current_host == obj->parent)
return 0;
iter->current_host = obj->parent;
- return sdb_store_emit(obj->parent, iter->w, iter->wd);
+ return sdb_memstore_emit(obj->parent, iter->w, iter->wd);
} /* maybe_emit_host */
static int
-list_tojson(sdb_store_obj_t *obj,
- sdb_store_matcher_t __attribute__((unused)) *filter,
+list_tojson(sdb_memstore_obj_t *obj,
+ sdb_memstore_matcher_t __attribute__((unused)) *filter,
void *user_data)
{
iter_t *iter = user_data;
maybe_emit_host(iter, obj);
- return sdb_store_emit(obj, iter->w, iter->wd);
+ return sdb_memstore_emit(obj, iter->w, iter->wd);
} /* list_tojson */
static int
-lookup_tojson(sdb_store_obj_t *obj, sdb_store_matcher_t *filter,
+lookup_tojson(sdb_memstore_obj_t *obj, sdb_memstore_matcher_t *filter,
void *user_data)
{
iter_t *iter = user_data;
maybe_emit_host(iter, obj);
- return sdb_store_emit_full(obj, filter, iter->w, iter->wd);
+ return sdb_memstore_emit_full(obj, filter, iter->w, iter->wd);
} /* lookup_tojson */
/*
*/
static int
-exec_fetch(sdb_store_t *store,
+exec_fetch(sdb_memstore_t *store,
sdb_store_writer_t *w, sdb_object_t *wd, sdb_strbuf_t *errbuf,
int type, const char *hostname, const char *name,
- sdb_store_matcher_t *filter)
+ sdb_memstore_matcher_t *filter)
{
- sdb_store_obj_t *host;
- sdb_store_obj_t *obj;
+ sdb_memstore_obj_t *host;
+ sdb_memstore_obj_t *obj;
int status = 0;
if (type == SDB_HOST)
hostname = name;
- host = sdb_store_get_host(store, hostname);
+ host = sdb_memstore_get_host(store, hostname);
if ((! host)
- || (filter && (! sdb_store_matcher_matches(filter, host, NULL)))) {
+ || (filter && (! sdb_memstore_matcher_matches(filter, host, NULL)))) {
sdb_strbuf_sprintf(errbuf, "Failed to fetch %s %s: "
"host %s not found", SDB_STORE_TYPE_TO_NAME(type),
name, hostname);
obj = host;
}
else {
- obj = sdb_store_get_child(host, type, name);
+ obj = sdb_memstore_get_child(host, type, name);
if ((! obj)
- || (filter && (! sdb_store_matcher_matches(filter, obj, NULL)))) {
+ || (filter && (! sdb_memstore_matcher_matches(filter, obj, NULL)))) {
sdb_strbuf_sprintf(errbuf, "Failed to fetch %s %s.%s: "
"%s not found", SDB_STORE_TYPE_TO_NAME(type),
hostname, name, name);
host = NULL;
if (type != SDB_HOST)
- status = sdb_store_emit(obj->parent, w, wd);
- if (status || sdb_store_emit_full(obj, filter, w, wd)) {
+ status = sdb_memstore_emit(obj->parent, w, wd);
+ if (status || sdb_memstore_emit_full(obj, filter, w, wd)) {
sdb_log(SDB_LOG_ERR, "frontend: Failed to serialize "
"%s %s.%s to JSON", SDB_STORE_TYPE_TO_NAME(type),
hostname, name);
} /* exec_fetch */
static int
-exec_list(sdb_store_t *store,
+exec_list(sdb_memstore_t *store,
sdb_store_writer_t *w, sdb_object_t *wd, sdb_strbuf_t *errbuf,
- int type, sdb_store_matcher_t *filter)
+ int type, sdb_memstore_matcher_t *filter)
{
iter_t iter = { NULL, w, wd };
- if (sdb_store_scan(store, type, /* m = */ NULL, filter, list_tojson, &iter)) {
+ if (sdb_memstore_scan(store, type, /* m = */ NULL, filter, list_tojson, &iter)) {
sdb_log(SDB_LOG_ERR, "frontend: Failed to serialize "
"store to JSON");
sdb_strbuf_sprintf(errbuf, "Out of memory");
} /* exec_list */
static int
-exec_lookup(sdb_store_t *store,
+exec_lookup(sdb_memstore_t *store,
sdb_store_writer_t *w, sdb_object_t *wd, sdb_strbuf_t *errbuf,
- int type, sdb_store_matcher_t *m, sdb_store_matcher_t *filter)
+ int type, sdb_memstore_matcher_t *m, sdb_memstore_matcher_t *filter)
{
iter_t iter = { NULL, w, wd };
- if (sdb_store_scan(store, type, m, filter, lookup_tojson, &iter)) {
+ if (sdb_memstore_scan(store, type, m, filter, lookup_tojson, &iter)) {
sdb_log(SDB_LOG_ERR, "frontend: Failed to lookup %ss",
SDB_STORE_TYPE_TO_NAME(type));
sdb_strbuf_sprintf(errbuf, "Failed to lookup %ss",
*/
int
-sdb_store_query_execute(sdb_store_t *store, sdb_store_query_t *q,
+sdb_memstore_query_execute(sdb_memstore_t *store, sdb_memstore_query_t *q,
sdb_store_writer_t *w, sdb_object_t *wd, sdb_strbuf_t *errbuf)
{
sdb_ast_node_t *ast;
}
return 0;
-} /* sdb_store_query_execute */
+} /* sdb_memstore_query_execute */
/* vim: set tw=78 sw=4 ts=4 noexpandtab : */
diff --git a/src/core/store_expr.c b/src/core/store_expr.c
index 6405002cfda3187177dc9b49dae9ce2bc8e82322..c96b3396876940e487353b9bc7169c17e0bf3f82 100644 (file)
--- a/src/core/store_expr.c
+++ b/src/core/store_expr.c
*/
/* iterate through either a list of child nodes or arrays */
-struct sdb_store_expr_iter {
- sdb_store_obj_t *obj;
- sdb_store_expr_t *expr;
+struct sdb_memstore_expr_iter {
+ sdb_memstore_obj_t *obj;
+ sdb_memstore_expr_t *expr;
sdb_avltree_iter_t *tree;
size_t array_idx;
bool free_array;
- sdb_store_matcher_t *filter;
+ sdb_memstore_matcher_t *filter;
};
/*
expr_init(sdb_object_t *obj, va_list ap)
{
int type = va_arg(ap, int);
- sdb_store_expr_t *left = va_arg(ap, sdb_store_expr_t *);
- sdb_store_expr_t *right = va_arg(ap, sdb_store_expr_t *);
+ sdb_memstore_expr_t *left = va_arg(ap, sdb_memstore_expr_t *);
+ sdb_memstore_expr_t *right = va_arg(ap, sdb_memstore_expr_t *);
const sdb_data_t *value = va_arg(ap, const sdb_data_t *);
- sdb_store_expr_t *expr = SDB_STORE_EXPR(obj);
+ sdb_memstore_expr_t *expr = SDB_MEMSTORE_EXPR(obj);
if (type <= 0) {
if (! value)
static void
expr_destroy(sdb_object_t *obj)
{
- sdb_store_expr_t *expr = SDB_STORE_EXPR(obj);
+ sdb_memstore_expr_t *expr = SDB_MEMSTORE_EXPR(obj);
sdb_object_deref(SDB_OBJ(expr->left));
sdb_object_deref(SDB_OBJ(expr->right));
} /* expr_destroy */
static sdb_type_t expr_type = {
- /* size = */ sizeof(sdb_store_expr_t),
+ /* size = */ sizeof(sdb_memstore_expr_t),
/* init = */ expr_init,
/* destroy = */ expr_destroy,
};
* public API
*/
-sdb_store_expr_t *
-sdb_store_expr_create(int op, sdb_store_expr_t *left, sdb_store_expr_t *right)
+sdb_memstore_expr_t *
+sdb_memstore_expr_create(int op, sdb_memstore_expr_t *left, sdb_memstore_expr_t *right)
{
sdb_data_t value = SDB_DATA_INIT;
- sdb_store_expr_t *e;
+ sdb_memstore_expr_t *e;
if ((op < 0) || (SDB_DATA_CONCAT < op) || (! left) || (! right))
return NULL;
if (left->type || right->type) {
- e = SDB_STORE_EXPR(sdb_object_create("store-expr", expr_type,
+ e = SDB_MEMSTORE_EXPR(sdb_object_create("store-expr", expr_type,
op, left, right, NULL));
e->data_type = sdb_data_expr_type(op, left->type, right->type);
return e;
@@ -142,76 +142,76 @@ sdb_store_expr_create(int op, sdb_store_expr_t *left, sdb_store_expr_t *right)
if (sdb_data_expr_eval(op, &left->data, &right->data, &value))
return NULL;
- e = SDB_STORE_EXPR(sdb_object_create("store-constvalue", expr_type,
+ e = SDB_MEMSTORE_EXPR(sdb_object_create("store-constvalue", expr_type,
0, NULL, NULL, &value));
e->data_type = value.type;
return e;
-} /* sdb_store_expr_create */
+} /* sdb_memstore_expr_create */
-sdb_store_expr_t *
-sdb_store_expr_typed(int typ, sdb_store_expr_t *expr)
+sdb_memstore_expr_t *
+sdb_memstore_expr_typed(int typ, sdb_memstore_expr_t *expr)
{
sdb_data_t value = { SDB_TYPE_INTEGER, { .integer = typ } };
- sdb_store_expr_t *e;
+ sdb_memstore_expr_t *e;
if ((typ < SDB_HOST) || (SDB_ATTRIBUTE < typ))
return NULL;
- e = SDB_STORE_EXPR(sdb_object_create("store-typedexpr", expr_type,
+ e = SDB_MEMSTORE_EXPR(sdb_object_create("store-typedexpr", expr_type,
TYPED_EXPR, expr, NULL, &value));
e->data_type = expr->data_type;
return e;
-} /* sdb_store_expr_typed */
+} /* sdb_memstore_expr_typed */
-sdb_store_expr_t *
-sdb_store_expr_fieldvalue(int field)
+sdb_memstore_expr_t *
+sdb_memstore_expr_fieldvalue(int field)
{
sdb_data_t value = { SDB_TYPE_INTEGER, { .integer = field } };
- sdb_store_expr_t *e;
+ sdb_memstore_expr_t *e;
if ((field < SDB_FIELD_NAME) || (SDB_FIELD_TIMESERIES < field))
return NULL;
- e = SDB_STORE_EXPR(sdb_object_create("store-fieldvalue", expr_type,
+ e = SDB_MEMSTORE_EXPR(sdb_object_create("store-fieldvalue", expr_type,
FIELD_VALUE, NULL, NULL, &value));
e->data_type = SDB_FIELD_TYPE(field);
return e;
-} /* sdb_store_expr_fieldvalue */
+} /* sdb_memstore_expr_fieldvalue */
-sdb_store_expr_t *
-sdb_store_expr_attrvalue(const char *name)
+sdb_memstore_expr_t *
+sdb_memstore_expr_attrvalue(const char *name)
{
sdb_data_t value = { SDB_TYPE_STRING, { .string = NULL} };
- sdb_store_expr_t *expr;
+ sdb_memstore_expr_t *expr;
value.data.string = strdup(name);
if (! value.data.string)
return NULL;
- expr = SDB_STORE_EXPR(sdb_object_create("store-attrvalue", expr_type,
+ expr = SDB_MEMSTORE_EXPR(sdb_object_create("store-attrvalue", expr_type,
ATTR_VALUE, NULL, NULL, &value));
if (! expr)
free(value.data.string);
expr->data_type = -1;
return expr;
-} /* sdb_store_expr_attrvalue */
+} /* sdb_memstore_expr_attrvalue */
-sdb_store_expr_t *
-sdb_store_expr_constvalue(const sdb_data_t *value)
+sdb_memstore_expr_t *
+sdb_memstore_expr_constvalue(const sdb_data_t *value)
{
sdb_data_t data = SDB_DATA_INIT;
- sdb_store_expr_t *e;
+ sdb_memstore_expr_t *e;
if (sdb_data_copy(&data, value))
return NULL;
- e = SDB_STORE_EXPR(sdb_object_create("store-constvalue", expr_type,
+ e = SDB_MEMSTORE_EXPR(sdb_object_create("store-constvalue", expr_type,
0, NULL, NULL, &data));
e->data_type = data.type;
return e;
-} /* sdb_store_expr_constvalue */
+} /* sdb_memstore_expr_constvalue */
int
-sdb_store_expr_eval(sdb_store_expr_t *expr, sdb_store_obj_t *obj,
- sdb_data_t *res, sdb_store_matcher_t *filter)
+sdb_memstore_expr_eval(sdb_memstore_expr_t *expr, sdb_memstore_obj_t *obj,
+ sdb_data_t *res, sdb_memstore_matcher_t *filter)
{
sdb_data_t v1 = SDB_DATA_INIT, v2 = SDB_DATA_INIT;
int status = 0;
if ((! expr) || (! res))
return -1;
- if (filter && obj && (! sdb_store_matcher_matches(filter, obj, NULL)))
+ if (filter && obj && (! sdb_memstore_matcher_matches(filter, obj, NULL)))
obj = NULL; /* this object does not exist */
if (! expr->type)
return sdb_data_copy(res, &expr->data);
else if (expr->type == FIELD_VALUE)
- return sdb_store_get_field(obj, (int)expr->data.data.integer, res);
+ return sdb_memstore_get_field(obj, (int)expr->data.data.integer, res);
else if (expr->type == ATTR_VALUE) {
- status = sdb_store_get_attr(obj, expr->data.data.string, res, filter);
+ status = sdb_memstore_get_attr(obj, expr->data.data.string, res, filter);
if ((status < 0) && obj) {
/* attribute does not exist => NULL */
status = 0;
return -1;
obj = obj->parent;
}
- return sdb_store_expr_eval(expr->left, obj, res, filter);
+ return sdb_memstore_expr_eval(expr->left, obj, res, filter);
}
- if (sdb_store_expr_eval(expr->left, obj, &v1, filter))
+ if (sdb_memstore_expr_eval(expr->left, obj, &v1, filter))
return -1;
- if (sdb_store_expr_eval(expr->right, obj, &v2, filter)) {
+ if (sdb_memstore_expr_eval(expr->right, obj, &v2, filter)) {
sdb_data_free_datum(&v1);
return -1;
}
sdb_data_free_datum(&v1);
sdb_data_free_datum(&v2);
return status;
-} /* sdb_store_expr_eval */
+} /* sdb_memstore_expr_eval */
-sdb_store_expr_iter_t *
-sdb_store_expr_iter(sdb_store_expr_t *expr, sdb_store_obj_t *obj,
- sdb_store_matcher_t *filter)
+sdb_memstore_expr_iter_t *
+sdb_memstore_expr_iter(sdb_memstore_expr_t *expr, sdb_memstore_obj_t *obj,
+ sdb_memstore_matcher_t *filter)
{
- sdb_store_expr_iter_t *iter;
+ sdb_memstore_expr_iter_t *iter;
sdb_avltree_iter_t *tree = NULL;
sdb_data_t array = SDB_DATA_INIT;
bool free_array = 0;
}
else {
sdb_data_t value = SDB_DATA_INIT;
- if (sdb_store_expr_eval(expr, obj, &value, filter))
+ if (sdb_memstore_expr_eval(expr, obj, &value, filter))
return NULL;
if (! (value.type & SDB_TYPE_ARRAY)) {
sdb_data_free_datum(&value);
iter->free_array = free_array;
iter->filter = filter;
return iter;
-} /* sdb_store_expr_iter */
+} /* sdb_memstore_expr_iter */
void
-sdb_store_expr_iter_destroy(sdb_store_expr_iter_t *iter)
+sdb_memstore_expr_iter_destroy(sdb_memstore_expr_iter_t *iter)
{
sdb_data_t null = SDB_DATA_INIT;
sdb_object_deref(SDB_OBJ(iter->expr));
sdb_object_deref(SDB_OBJ(iter->filter));
free(iter);
-} /* sdb_store_expr_iter_destroy */
+} /* sdb_memstore_expr_iter_destroy */
bool
-sdb_store_expr_iter_has_next(sdb_store_expr_iter_t *iter)
+sdb_memstore_expr_iter_has_next(sdb_memstore_expr_iter_t *iter)
{
if (! iter)
return 0;
/* this function may be called before get_next,
* so we'll have to apply filters here as well */
if (iter->filter) {
- sdb_store_obj_t *child;
+ sdb_memstore_obj_t *child;
while ((child = STORE_OBJ(sdb_avltree_iter_peek_next(iter->tree)))) {
- if (sdb_store_matcher_matches(iter->filter, child, NULL))
+ if (sdb_memstore_matcher_matches(iter->filter, child, NULL))
break;
(void)sdb_avltree_iter_get_next(iter->tree);
}
}
return iter->array_idx < iter->array.data.array.length;
-} /* sdb_store_expr_iter_has_next */
+} /* sdb_memstore_expr_iter_has_next */
sdb_data_t
-sdb_store_expr_iter_get_next(sdb_store_expr_iter_t *iter)
+sdb_memstore_expr_iter_get_next(sdb_memstore_expr_iter_t *iter)
{
sdb_data_t null = SDB_DATA_INIT;
sdb_data_t ret = SDB_DATA_INIT;
return null;
if (iter->tree) {
- sdb_store_obj_t *child;
+ sdb_memstore_obj_t *child;
while (42) {
child = STORE_OBJ(sdb_avltree_iter_get_next(iter->tree));
if (! child)
break;
if (iter->filter
- && (! sdb_store_matcher_matches(iter->filter, child, NULL)))
+ && (! sdb_memstore_matcher_matches(iter->filter, child, NULL)))
continue;
- if (sdb_store_expr_eval(iter->expr, child, &ret, iter->filter))
+ if (sdb_memstore_expr_eval(iter->expr, child, &ret, iter->filter))
return null;
break;
}
/* Skip over any filtered objects */
if (iter->filter) {
while ((child = STORE_OBJ(sdb_avltree_iter_peek_next(iter->tree)))) {
- if (sdb_store_matcher_matches(iter->filter, child, NULL))
+ if (sdb_memstore_matcher_matches(iter->filter, child, NULL))
break;
(void)sdb_avltree_iter_get_next(iter->tree);
}
return null;
ret = tmp;
return ret;
-} /* sdb_store_expr_iter_get_next */
+} /* sdb_memstore_expr_iter_get_next */
/* vim: set tw=78 sw=4 ts=4 noexpandtab : */
diff --git a/src/core/store_json.c b/src/core/store_json.c
index 961e54c0606ae84206d1199758506ad4ff212cbf..b39ff210a2aedfaf0d8b0064bad354234d8109bc 100644 (file)
--- a/src/core/store_json.c
+++ b/src/core/store_json.c
/* TODO: Move sdb_store_emit* somewhere else. */
int
-sdb_store_emit(sdb_store_obj_t *obj, sdb_store_writer_t *w, sdb_object_t *wd)
+sdb_memstore_emit(sdb_memstore_obj_t *obj, sdb_store_writer_t *w, sdb_object_t *wd)
{
if ((! obj) || (! w))
return -1;
}
return -1;
-} /* sdb_store_emit */
+} /* sdb_memstore_emit */
int
-sdb_store_emit_full(sdb_store_obj_t *obj, sdb_store_matcher_t *filter,
+sdb_memstore_emit_full(sdb_memstore_obj_t *obj, sdb_memstore_matcher_t *filter,
sdb_store_writer_t *w, sdb_object_t *wd)
{
sdb_avltree_t *trees[] = { NULL, NULL, NULL };
size_t i;
- if (sdb_store_emit(obj, w, wd))
+ if (sdb_memstore_emit(obj, w, wd))
return -1;
if (obj->type == SDB_HOST) {
iter = sdb_avltree_get_iter(trees[i]);
while (sdb_avltree_iter_has_next(iter)) {
- sdb_store_obj_t *child;
+ sdb_memstore_obj_t *child;
child = STORE_OBJ(sdb_avltree_iter_get_next(iter));
- if (filter && (! sdb_store_matcher_matches(filter, child, NULL)))
+ if (filter && (! sdb_memstore_matcher_matches(filter, child, NULL)))
continue;
- if (sdb_store_emit_full(child, filter, w, wd)) {
+ if (sdb_memstore_emit_full(child, filter, w, wd)) {
sdb_avltree_iter_destroy(iter);
return -1;
}
sdb_avltree_iter_destroy(iter);
}
return 0;
-} /* sdb_store_emit_full */
+} /* sdb_memstore_emit_full */
int
sdb_store_json_finish(sdb_store_json_formatter_t *f)
index 06151a81d4fdb04bb49143dd794ee60c30a00618..b69e7f994c17186964bfc1823587186dee640c98 100644 (file)
--- a/src/core/store_lookup.c
+++ b/src/core/store_lookup.c
#include <limits.h>
static int
-expr_eval2(sdb_store_expr_t *e1, sdb_data_t *v1,
- sdb_store_expr_t *e2, sdb_data_t *v2,
- sdb_store_obj_t *obj, sdb_store_matcher_t *filter)
+expr_eval2(sdb_memstore_expr_t *e1, sdb_data_t *v1,
+ sdb_memstore_expr_t *e2, sdb_data_t *v2,
+ sdb_memstore_obj_t *obj, sdb_memstore_matcher_t *filter)
{
if (e1->type) {
- if (sdb_store_expr_eval(e1, obj, v1, filter))
+ if (sdb_memstore_expr_eval(e1, obj, v1, filter))
return -1;
}
else
*v1 = e1->data;
if (e2->type) {
- if (sdb_store_expr_eval(e2, obj, v2, filter)) {
+ if (sdb_memstore_expr_eval(e2, obj, v2, filter)) {
if (e1->type)
sdb_data_free_datum(v1);
return -1;
} /* expr_eval2 */
static void
-expr_free_datum2(sdb_store_expr_t *e1, sdb_data_t *v1,
- sdb_store_expr_t *e2, sdb_data_t *v2)
+expr_free_datum2(sdb_memstore_expr_t *e1, sdb_data_t *v1,
+ sdb_memstore_expr_t *e2, sdb_data_t *v2)
{
if (e1->type)
sdb_data_free_datum(v1);
} /* match_regex_value */
static int
-match_logical(sdb_store_matcher_t *m, sdb_store_obj_t *obj,
- sdb_store_matcher_t *filter)
+match_logical(sdb_memstore_matcher_t *m, sdb_memstore_obj_t *obj,
+ sdb_memstore_matcher_t *filter)
{
int status;
assert((m->type == MATCHER_AND) || (m->type == MATCHER_OR));
assert(OP_M(m)->left && OP_M(m)->right);
- status = sdb_store_matcher_matches(OP_M(m)->left, obj, filter);
+ status = sdb_memstore_matcher_matches(OP_M(m)->left, obj, filter);
/* lazy evaluation */
if ((! status) && (m->type == MATCHER_AND))
else if (status && (m->type == MATCHER_OR))
return status;
- return sdb_store_matcher_matches(OP_M(m)->right, obj, filter);
+ return sdb_memstore_matcher_matches(OP_M(m)->right, obj, filter);
} /* match_logical */
static int
-match_uop(sdb_store_matcher_t *m, sdb_store_obj_t *obj,
- sdb_store_matcher_t *filter)
+match_uop(sdb_memstore_matcher_t *m, sdb_memstore_obj_t *obj,
+ sdb_memstore_matcher_t *filter)
{
assert(m->type == MATCHER_NOT);
assert(UOP_M(m)->op);
- return !sdb_store_matcher_matches(UOP_M(m)->op, obj, filter);
+ return !sdb_memstore_matcher_matches(UOP_M(m)->op, obj, filter);
} /* match_uop */
/* iterate: ANY/ALL <iter> <cmp> <value> */
static int
-match_iter(sdb_store_matcher_t *m, sdb_store_obj_t *obj,
- sdb_store_matcher_t *filter)
+match_iter(sdb_memstore_matcher_t *m, sdb_memstore_obj_t *obj,
+ sdb_memstore_matcher_t *filter)
{
- sdb_store_expr_iter_t *iter = NULL;
+ sdb_memstore_expr_iter_t *iter = NULL;
int status;
int all = (int)(m->type == MATCHER_ALL);
assert((m->type == MATCHER_ANY) || (m->type == MATCHER_ALL));
assert((! CMP_M(ITER_M(m)->m)->left) && CMP_M(ITER_M(m)->m)->right);
- iter = sdb_store_expr_iter(ITER_M(m)->iter, obj, filter);
+ iter = sdb_memstore_expr_iter(ITER_M(m)->iter, obj, filter);
if (! iter) {
sdb_log(SDB_LOG_WARNING, "store: Invalid iterator");
return 0;
}
status = all;
- while (sdb_store_expr_iter_has_next(iter)) {
- sdb_data_t v = sdb_store_expr_iter_get_next(iter);
- sdb_store_expr_t expr = CONST_EXPR(v);
+ while (sdb_memstore_expr_iter_has_next(iter)) {
+ sdb_data_t v = sdb_memstore_expr_iter_get_next(iter);
+ sdb_memstore_expr_t expr = CONST_EXPR(v);
bool matches;
CMP_M(ITER_M(m)->m)->left = &expr;
- matches = sdb_store_matcher_matches(ITER_M(m)->m, obj, filter);
+ matches = sdb_memstore_matcher_matches(ITER_M(m)->m, obj, filter);
CMP_M(ITER_M(m)->m)->left = NULL;
sdb_data_free_datum(&v);
break;
}
}
- sdb_store_expr_iter_destroy(iter);
+ sdb_memstore_expr_iter_destroy(iter);
return status;
} /* match_iter */
static int
-match_cmp(sdb_store_matcher_t *m, sdb_store_obj_t *obj,
- sdb_store_matcher_t *filter)
+match_cmp(sdb_memstore_matcher_t *m, sdb_memstore_obj_t *obj,
+ sdb_memstore_matcher_t *filter)
{
- sdb_store_expr_t *e1 = CMP_M(m)->left;
- sdb_store_expr_t *e2 = CMP_M(m)->right;
+ sdb_memstore_expr_t *e1 = CMP_M(m)->left;
+ sdb_memstore_expr_t *e2 = CMP_M(m)->right;
sdb_data_t v1 = SDB_DATA_INIT, v2 = SDB_DATA_INIT;
int status;
} /* match_cmp */
static int
-match_in(sdb_store_matcher_t *m, sdb_store_obj_t *obj,
- sdb_store_matcher_t *filter)
+match_in(sdb_memstore_matcher_t *m, sdb_memstore_obj_t *obj,
+ sdb_memstore_matcher_t *filter)
{
sdb_data_t value = SDB_DATA_INIT, array = SDB_DATA_INIT;
int status = 1;
} /* match_in */
static int
-match_regex(sdb_store_matcher_t *m, sdb_store_obj_t *obj,
- sdb_store_matcher_t *filter)
+match_regex(sdb_memstore_matcher_t *m, sdb_memstore_obj_t *obj,
+ sdb_memstore_matcher_t *filter)
{
sdb_data_t regex = SDB_DATA_INIT, v = SDB_DATA_INIT;
int status = 0;
} /* match_regex */
static int
-match_unary(sdb_store_matcher_t *m, sdb_store_obj_t *obj,
- sdb_store_matcher_t *filter)
+match_unary(sdb_memstore_matcher_t *m, sdb_memstore_obj_t *obj,
+ sdb_memstore_matcher_t *filter)
{
sdb_data_t v = SDB_DATA_INIT;
int status;
if (UNARY_M(m)->expr->type) {
/* TODO: this might hide real errors;
* improve error reporting and propagation */
- if (sdb_store_expr_eval(UNARY_M(m)->expr, obj, &v, filter))
+ if (sdb_memstore_expr_eval(UNARY_M(m)->expr, obj, &v, filter))
return 1;
}
else
return status;
} /* match_unary */
-typedef int (*matcher_cb)(sdb_store_matcher_t *, sdb_store_obj_t *,
- sdb_store_matcher_t *);
+typedef int (*matcher_cb)(sdb_memstore_matcher_t *, sdb_memstore_obj_t *,
+ sdb_memstore_matcher_t *);
/* this array needs to be indexable by the matcher types;
* -> update the enum in store-private.h when updating this */
if ((M(obj)->type != MATCHER_OR) && (M(obj)->type != MATCHER_AND))
return -1;
- OP_M(obj)->left = va_arg(ap, sdb_store_matcher_t *);
+ OP_M(obj)->left = va_arg(ap, sdb_memstore_matcher_t *);
sdb_object_ref(SDB_OBJ(OP_M(obj)->left));
- OP_M(obj)->right = va_arg(ap, sdb_store_matcher_t *);
+ OP_M(obj)->right = va_arg(ap, sdb_memstore_matcher_t *);
sdb_object_ref(SDB_OBJ(OP_M(obj)->right));
if ((! OP_M(obj)->left) || (! OP_M(obj)->right))
iter_matcher_init(sdb_object_t *obj, va_list ap)
{
M(obj)->type = va_arg(ap, int);
- ITER_M(obj)->iter = va_arg(ap, sdb_store_expr_t *);
- ITER_M(obj)->m = va_arg(ap, sdb_store_matcher_t *);
+ ITER_M(obj)->iter = va_arg(ap, sdb_memstore_expr_t *);
+ ITER_M(obj)->m = va_arg(ap, sdb_memstore_matcher_t *);
sdb_object_ref(SDB_OBJ(ITER_M(obj)->iter));
sdb_object_ref(SDB_OBJ(ITER_M(obj)->m));
{
M(obj)->type = va_arg(ap, int);
- CMP_M(obj)->left = va_arg(ap, sdb_store_expr_t *);
+ CMP_M(obj)->left = va_arg(ap, sdb_memstore_expr_t *);
sdb_object_ref(SDB_OBJ(CMP_M(obj)->left));
- CMP_M(obj)->right = va_arg(ap, sdb_store_expr_t *);
+ CMP_M(obj)->right = va_arg(ap, sdb_memstore_expr_t *);
sdb_object_ref(SDB_OBJ(CMP_M(obj)->right));
if (! CMP_M(obj)->right)
if (M(obj)->type != MATCHER_NOT)
return -1;
- UOP_M(obj)->op = va_arg(ap, sdb_store_matcher_t *);
+ UOP_M(obj)->op = va_arg(ap, sdb_memstore_matcher_t *);
sdb_object_ref(SDB_OBJ(UOP_M(obj)->op));
if (! UOP_M(obj)->op)
&& (M(obj)->type != MATCHER_ISFALSE))
return -1;
- UNARY_M(obj)->expr = va_arg(ap, sdb_store_expr_t *);
+ UNARY_M(obj)->expr = va_arg(ap, sdb_memstore_expr_t *);
sdb_object_ref(SDB_OBJ(UNARY_M(obj)->expr));
return 0;
} /* unary_matcher_init */
* public API
*/
-sdb_store_matcher_t *
-sdb_store_any_matcher(sdb_store_expr_t *iter, sdb_store_matcher_t *m)
+sdb_memstore_matcher_t *
+sdb_memstore_any_matcher(sdb_memstore_expr_t *iter, sdb_memstore_matcher_t *m)
{
if ((m->type < MATCHER_LT) || (MATCHER_NREGEX < m->type)) {
sdb_log(SDB_LOG_ERR, "store: Invalid ANY -> %s matcher "
}
return M(sdb_object_create("any-matcher", iter_type,
MATCHER_ANY, iter, m));
-} /* sdb_store_any_matcher */
+} /* sdb_memstore_any_matcher */
-sdb_store_matcher_t *
-sdb_store_all_matcher(sdb_store_expr_t *iter, sdb_store_matcher_t *m)
+sdb_memstore_matcher_t *
+sdb_memstore_all_matcher(sdb_memstore_expr_t *iter, sdb_memstore_matcher_t *m)
{
if ((m->type < MATCHER_LT) || (MATCHER_NREGEX < m->type)) {
sdb_log(SDB_LOG_ERR, "store: Invalid ALL -> %s matcher "
}
return M(sdb_object_create("all-matcher", iter_type,
MATCHER_ALL, iter, m));
-} /* sdb_store_all_matcher */
+} /* sdb_memstore_all_matcher */
-sdb_store_matcher_t *
-sdb_store_lt_matcher(sdb_store_expr_t *left, sdb_store_expr_t *right)
+sdb_memstore_matcher_t *
+sdb_memstore_lt_matcher(sdb_memstore_expr_t *left, sdb_memstore_expr_t *right)
{
return M(sdb_object_create("lt-matcher", cmp_type,
MATCHER_LT, left, right));
-} /* sdb_store_lt_matcher */
+} /* sdb_memstore_lt_matcher */
-sdb_store_matcher_t *
-sdb_store_le_matcher(sdb_store_expr_t *left, sdb_store_expr_t *right)
+sdb_memstore_matcher_t *
+sdb_memstore_le_matcher(sdb_memstore_expr_t *left, sdb_memstore_expr_t *right)
{
return M(sdb_object_create("le-matcher", cmp_type,
MATCHER_LE, left, right));
-} /* sdb_store_le_matcher */
+} /* sdb_memstore_le_matcher */
-sdb_store_matcher_t *
-sdb_store_eq_matcher(sdb_store_expr_t *left, sdb_store_expr_t *right)
+sdb_memstore_matcher_t *
+sdb_memstore_eq_matcher(sdb_memstore_expr_t *left, sdb_memstore_expr_t *right)
{
return M(sdb_object_create("eq-matcher", cmp_type,
MATCHER_EQ, left, right));
-} /* sdb_store_eq_matcher */
+} /* sdb_memstore_eq_matcher */
-sdb_store_matcher_t *
-sdb_store_ne_matcher(sdb_store_expr_t *left, sdb_store_expr_t *right)
+sdb_memstore_matcher_t *
+sdb_memstore_ne_matcher(sdb_memstore_expr_t *left, sdb_memstore_expr_t *right)
{
return M(sdb_object_create("ne-matcher", cmp_type,
MATCHER_NE, left, right));
-} /* sdb_store_ne_matcher */
+} /* sdb_memstore_ne_matcher */
-sdb_store_matcher_t *
-sdb_store_ge_matcher(sdb_store_expr_t *left, sdb_store_expr_t *right)
+sdb_memstore_matcher_t *
+sdb_memstore_ge_matcher(sdb_memstore_expr_t *left, sdb_memstore_expr_t *right)
{
return M(sdb_object_create("ge-matcher", cmp_type,
MATCHER_GE, left, right));
-} /* sdb_store_ge_matcher */
+} /* sdb_memstore_ge_matcher */
-sdb_store_matcher_t *
-sdb_store_gt_matcher(sdb_store_expr_t *left, sdb_store_expr_t *right)
+sdb_memstore_matcher_t *
+sdb_memstore_gt_matcher(sdb_memstore_expr_t *left, sdb_memstore_expr_t *right)
{
return M(sdb_object_create("gt-matcher", cmp_type,
MATCHER_GT, left, right));
-} /* sdb_store_gt_matcher */
+} /* sdb_memstore_gt_matcher */
-sdb_store_matcher_t *
-sdb_store_in_matcher(sdb_store_expr_t *left, sdb_store_expr_t *right)
+sdb_memstore_matcher_t *
+sdb_memstore_in_matcher(sdb_memstore_expr_t *left, sdb_memstore_expr_t *right)
{
return M(sdb_object_create("in-matcher", cmp_type,
MATCHER_IN, left, right));
-} /* sdb_store_in_matcher */
+} /* sdb_memstore_in_matcher */
-sdb_store_matcher_t *
-sdb_store_regex_matcher(sdb_store_expr_t *left, sdb_store_expr_t *right)
+sdb_memstore_matcher_t *
+sdb_memstore_regex_matcher(sdb_memstore_expr_t *left, sdb_memstore_expr_t *right)
{
if (! right->type) {
if ((right->data.type != SDB_TYPE_STRING)
}
return M(sdb_object_create("regex-matcher", cmp_type,
MATCHER_REGEX, left, right));
-} /* sdb_store_regex_matcher */
+} /* sdb_memstore_regex_matcher */
-sdb_store_matcher_t *
-sdb_store_nregex_matcher(sdb_store_expr_t *left, sdb_store_expr_t *right)
+sdb_memstore_matcher_t *
+sdb_memstore_nregex_matcher(sdb_memstore_expr_t *left, sdb_memstore_expr_t *right)
{
- sdb_store_matcher_t *m = sdb_store_regex_matcher(left, right);
+ sdb_memstore_matcher_t *m = sdb_memstore_regex_matcher(left, right);
if (! m)
return NULL;
m->type = MATCHER_NREGEX;
return m;
-} /* sdb_store_nregex_matcher */
+} /* sdb_memstore_nregex_matcher */
-sdb_store_matcher_t *
-sdb_store_isnull_matcher(sdb_store_expr_t *expr)
+sdb_memstore_matcher_t *
+sdb_memstore_isnull_matcher(sdb_memstore_expr_t *expr)
{
return M(sdb_object_create("isnull-matcher", unary_type,
MATCHER_ISNULL, expr));
-} /* sdb_store_isnull_matcher */
+} /* sdb_memstore_isnull_matcher */
-sdb_store_matcher_t *
-sdb_store_istrue_matcher(sdb_store_expr_t *expr)
+sdb_memstore_matcher_t *
+sdb_memstore_istrue_matcher(sdb_memstore_expr_t *expr)
{
return M(sdb_object_create("istrue-matcher", unary_type,
MATCHER_ISTRUE, expr));
-} /* sdb_store_istrue_matcher */
+} /* sdb_memstore_istrue_matcher */
-sdb_store_matcher_t *
-sdb_store_isfalse_matcher(sdb_store_expr_t *expr)
+sdb_memstore_matcher_t *
+sdb_memstore_isfalse_matcher(sdb_memstore_expr_t *expr)
{
return M(sdb_object_create("isfalse-matcher", unary_type,
MATCHER_ISFALSE, expr));
-} /* sdb_store_isfalse_matcher */
+} /* sdb_memstore_isfalse_matcher */
-sdb_store_matcher_t *
-sdb_store_dis_matcher(sdb_store_matcher_t *left, sdb_store_matcher_t *right)
+sdb_memstore_matcher_t *
+sdb_memstore_dis_matcher(sdb_memstore_matcher_t *left, sdb_memstore_matcher_t *right)
{
return M(sdb_object_create("dis-matcher", op_type, MATCHER_OR,
left, right));
-} /* sdb_store_dis_matcher */
+} /* sdb_memstore_dis_matcher */
-sdb_store_matcher_t *
-sdb_store_con_matcher(sdb_store_matcher_t *left, sdb_store_matcher_t *right)
+sdb_memstore_matcher_t *
+sdb_memstore_con_matcher(sdb_memstore_matcher_t *left, sdb_memstore_matcher_t *right)
{
return M(sdb_object_create("con-matcher", op_type, MATCHER_AND,
left, right));
-} /* sdb_store_con_matcher */
+} /* sdb_memstore_con_matcher */
-sdb_store_matcher_t *
-sdb_store_inv_matcher(sdb_store_matcher_t *m)
+sdb_memstore_matcher_t *
+sdb_memstore_inv_matcher(sdb_memstore_matcher_t *m)
{
return M(sdb_object_create("inv-matcher", uop_type, MATCHER_NOT, m));
-} /* sdb_store_inv_matcher */
+} /* sdb_memstore_inv_matcher */
int
-sdb_store_matcher_matches(sdb_store_matcher_t *m, sdb_store_obj_t *obj,
- sdb_store_matcher_t *filter)
+sdb_memstore_matcher_matches(sdb_memstore_matcher_t *m, sdb_memstore_obj_t *obj,
+ sdb_memstore_matcher_t *filter)
{
- if (filter && (! sdb_store_matcher_matches(filter, obj, NULL)))
+ if (filter && (! sdb_memstore_matcher_matches(filter, obj, NULL)))
return 0;
/* "NULL" always matches */
if (! matchers[m->type])
return 0;
return matchers[m->type](m, obj, filter);
-} /* sdb_store_matcher_matches */
+} /* sdb_memstore_matcher_matches */
/* vim: set tw=78 sw=4 ts=4 noexpandtab : */
diff --git a/src/core/store_query.c b/src/core/store_query.c
index ff7089c42e51b0294eae53b4780e4d517bfcd6cb..341cb16b1da7e5ebcf8d3cfaa5d04e2138856811 100644 (file)
--- a/src/core/store_query.c
+++ b/src/core/store_query.c
#include <assert.h>
-static sdb_store_matcher_t *
+static sdb_memstore_matcher_t *
node_to_matcher(sdb_ast_node_t *n);
-static sdb_store_expr_t *
+static sdb_memstore_expr_t *
node_to_expr(sdb_ast_node_t *n)
{
- sdb_store_expr_t *left = NULL, *right = NULL;
- sdb_store_expr_t *e;
+ sdb_memstore_expr_t *left = NULL, *right = NULL;
+ sdb_memstore_expr_t *e;
int op;
if (! n) {
return NULL;
}
op = SDB_AST_OP_TO_DATA_OP(SDB_AST_OP(n)->kind);
- e = sdb_store_expr_create(op, left, right);
+ e = sdb_memstore_expr_create(op, left, right);
break;
case SDB_AST_TYPE_CONST:
- return sdb_store_expr_constvalue(&SDB_AST_CONST(n)->value);
+ return sdb_memstore_expr_constvalue(&SDB_AST_CONST(n)->value);
case SDB_AST_TYPE_VALUE:
if (SDB_AST_VALUE(n)->type == SDB_ATTRIBUTE)
- return sdb_store_expr_attrvalue(SDB_AST_VALUE(n)->name);
- return sdb_store_expr_fieldvalue(SDB_AST_VALUE(n)->type);
+ return sdb_memstore_expr_attrvalue(SDB_AST_VALUE(n)->name);
+ return sdb_memstore_expr_fieldvalue(SDB_AST_VALUE(n)->type);
case SDB_AST_TYPE_TYPED:
right = node_to_expr(SDB_AST_TYPED(n)->expr);
if (! right)
return NULL;
- e = sdb_store_expr_typed(SDB_AST_TYPED(n)->type, right);
+ e = sdb_memstore_expr_typed(SDB_AST_TYPED(n)->type, right);
break;
default:
return e;
} /* node_to_expr */
-static sdb_store_matcher_t *
+static sdb_memstore_matcher_t *
logical_to_matcher(sdb_ast_node_t *n)
{
- sdb_store_matcher_t *left = NULL, *right;
- sdb_store_matcher_t *m;
+ sdb_memstore_matcher_t *left = NULL, *right;
+ sdb_memstore_matcher_t *m;
if (SDB_AST_OP(n)->left) {
left = node_to_matcher(SDB_AST_OP(n)->left);
switch (SDB_AST_OP(n)->kind) {
case SDB_AST_AND:
- m = sdb_store_con_matcher(left, right);
+ m = sdb_memstore_con_matcher(left, right);
break;
case SDB_AST_OR:
- m = sdb_store_dis_matcher(left, right);
+ m = sdb_memstore_dis_matcher(left, right);
break;
case SDB_AST_NOT:
- m = sdb_store_inv_matcher(right);
+ m = sdb_memstore_inv_matcher(right);
break;
default:
return m;
} /* logical_to_matcher */
-static sdb_store_matcher_t *
+static sdb_memstore_matcher_t *
cmp_to_matcher(sdb_ast_node_t *n)
{
- sdb_store_expr_t *left = NULL, *right;
- sdb_store_matcher_t *m;
+ sdb_memstore_expr_t *left = NULL, *right;
+ sdb_memstore_matcher_t *m;
if (SDB_AST_OP(n)->left) {
left = node_to_expr(SDB_AST_OP(n)->left);
switch (SDB_AST_OP(n)->kind) {
case SDB_AST_LT:
- m = sdb_store_lt_matcher(left, right);
+ m = sdb_memstore_lt_matcher(left, right);
break;
case SDB_AST_LE:
- m = sdb_store_le_matcher(left, right);
+ m = sdb_memstore_le_matcher(left, right);
break;
case SDB_AST_EQ:
- m = sdb_store_eq_matcher(left, right);
+ m = sdb_memstore_eq_matcher(left, right);
break;
case SDB_AST_NE:
- m = sdb_store_ne_matcher(left, right);
+ m = sdb_memstore_ne_matcher(left, right);
break;
case SDB_AST_GE:
- m = sdb_store_ge_matcher(left, right);
+ m = sdb_memstore_ge_matcher(left, right);
break;
case SDB_AST_GT:
- m = sdb_store_gt_matcher(left, right);
+ m = sdb_memstore_gt_matcher(left, right);
break;
case SDB_AST_REGEX:
- m = sdb_store_regex_matcher(left, right);
+ m = sdb_memstore_regex_matcher(left, right);
break;
case SDB_AST_NREGEX:
- m = sdb_store_nregex_matcher(left, right);
+ m = sdb_memstore_nregex_matcher(left, right);
break;
case SDB_AST_ISNULL:
- m = sdb_store_isnull_matcher(right);
+ m = sdb_memstore_isnull_matcher(right);
break;
case SDB_AST_ISTRUE:
- m = sdb_store_istrue_matcher(right);
+ m = sdb_memstore_istrue_matcher(right);
break;
case SDB_AST_ISFALSE:
- m = sdb_store_isfalse_matcher(right);
+ m = sdb_memstore_isfalse_matcher(right);
break;
case SDB_AST_IN:
- m = sdb_store_in_matcher(left, right);
+ m = sdb_memstore_in_matcher(left, right);
break;
default:
return m;
} /* cmp_to_matcher */
-static sdb_store_matcher_t *
+static sdb_memstore_matcher_t *
iter_to_matcher(sdb_ast_node_t *n)
{
- sdb_store_expr_t *iter;
- sdb_store_matcher_t *expr, *m;
+ sdb_memstore_expr_t *iter;
+ sdb_memstore_matcher_t *expr, *m;
assert((SDB_AST_ITER(n)->expr->type == SDB_AST_TYPE_OPERATOR)
&& (! SDB_AST_OP(SDB_AST_ITER(n)->expr)->left));
switch (SDB_AST_ITER(n)->kind) {
case SDB_AST_ALL:
- m = sdb_store_all_matcher(iter, expr);
+ m = sdb_memstore_all_matcher(iter, expr);
break;
case SDB_AST_ANY:
- m = sdb_store_any_matcher(iter, expr);
+ m = sdb_memstore_any_matcher(iter, expr);
break;
default:
return m;
} /* iter_to_matcher */
-static sdb_store_matcher_t *
+static sdb_memstore_matcher_t *
node_to_matcher(sdb_ast_node_t *n)
{
int kind;
} /* query_destroy */
static sdb_type_t query_type = {
- /* size = */ sizeof(sdb_store_query_t),
+ /* size = */ sizeof(sdb_memstore_query_t),
/* init = */ query_init,
/* destroy = */ query_destroy,
};
* public API
*/
-sdb_store_query_t *
-sdb_store_query_prepare(sdb_ast_node_t *ast)
+sdb_memstore_query_t *
+sdb_memstore_query_prepare(sdb_ast_node_t *ast)
{
if (! ast)
return NULL;
return QUERY(sdb_object_create(SDB_AST_TYPE_TO_STRING(ast), query_type, ast));
-} /* sdb_store_query_prepare */
+} /* sdb_memstore_query_prepare */
-sdb_store_matcher_t *
-sdb_store_query_prepare_matcher(sdb_ast_node_t *ast)
+sdb_memstore_matcher_t *
+sdb_memstore_query_prepare_matcher(sdb_ast_node_t *ast)
{
return node_to_matcher(ast);
-} /* sdb_store_query_prepare_matcher */
+} /* sdb_memstore_query_prepare_matcher */
/* vim: set tw=78 sw=4 ts=4 noexpandtab : */
index 818297fddb2580ecfd4eeeae8352cb41a6087d0a..03677e8feb33a2f5796ed39cc1d945db00a81fa3 100644 (file)
--- a/src/include/core/store.h
+++ b/src/include/core/store.h
: -1)
/*
- * sdb_store_t represents an in-memory store. It inherits from sdb_object_t
+ * sdb_memstore_t represents an in-memory store. It inherits from sdb_object_t
* and may safely be case to a generic object.
*/
-struct sdb_store;
-typedef struct sdb_store sdb_store_t;
-#define SDB_STORE(obj) ((sdb_store_t *)(obj))
+struct sdb_memstore;
+typedef struct sdb_memstore sdb_memstore_t;
+#define SDB_MEMSTORE(obj) ((sdb_memstore_t *)(obj))
/*
- * sdb_store_obj_t represents the super-class of any stored object. It
+ * sdb_memstore_obj_t represents the super-class of any stored object. It
* inherits from sdb_object_t and may safely be cast to a generic object to
* access its name.
*/
-struct sdb_store_obj;
-typedef struct sdb_store_obj sdb_store_obj_t;
+struct sdb_memstore_obj;
+typedef struct sdb_memstore_obj sdb_memstore_obj_t;
/*
* sdb_store_host_t represents the meta-data of a stored host object.
* An expression object inherits from sdb_object_t and, thus, may safely be
* cast to a generic object.
*/
-struct sdb_store_expr;
-typedef struct sdb_store_expr sdb_store_expr_t;
-#define SDB_STORE_EXPR(obj) ((sdb_store_expr_t *)(obj))
+struct sdb_memstore_expr;
+typedef struct sdb_memstore_expr sdb_memstore_expr_t;
+#define SDB_MEMSTORE_EXPR(obj) ((sdb_memstore_expr_t *)(obj))
/*
* An expression iterator iterates over the values of an iterable expression.
*/
-struct sdb_store_expr_iter;
-typedef struct sdb_store_expr_iter sdb_store_expr_iter_t;
+struct sdb_memstore_expr_iter;
+typedef struct sdb_memstore_expr_iter sdb_memstore_expr_iter_t;
/*
* Store matchers may be used to lookup hosts from the store based on their
* A store matcher object inherits from sdb_object_t and, thus, may safely be
* cast to a generic object.
*/
-struct sdb_store_matcher;
-typedef struct sdb_store_matcher sdb_store_matcher_t;
-#define SDB_STORE_MATCHER(obj) ((sdb_store_matcher_t *)(obj))
+struct sdb_memstore_matcher;
+typedef struct sdb_memstore_matcher sdb_memstore_matcher_t;
+#define SDB_MEMSTORE_MATCHER(obj) ((sdb_memstore_matcher_t *)(obj))
/*
* A JSON formatter converts stored objects into the JSON format.
} sdb_store_writer_t;
/*
- * sdb_store_writer:
+ * sdb_memstore_writer:
* A store writer implementation that provides an in-memory object store. It
* expects a store object as its user-data argument.
*/
-extern sdb_store_writer_t sdb_store_writer;
+extern sdb_store_writer_t sdb_memstore_writer;
/*
* A store reader describes the interface to query a store implementation.
} sdb_store_reader_t;
/*
- * sdb_store_reader:
+ * sdb_memstore_reader:
* A store reader implementation that uses an in-memory object store. It
* expects a store object as its user-data argument.
*/
-extern sdb_store_reader_t sdb_store_reader;
+extern sdb_store_reader_t sdb_memstore_reader;
/*
- * sdb_store_create:
+ * sdb_memstore_create:
* Allocate a new in-memory store.
*/
-sdb_store_t *
-sdb_store_create(void);
+sdb_memstore_t *
+sdb_memstore_create(void);
/*
- * sdb_store_host, sdb_store_service, sdb_store_metric, sdb_store_attribute,
- * sdb_store_metric_attr:
+ * sdb_memstore_host, sdb_memstore_service, sdb_memstore_metric,
+ * sdb_memstore_attribute, sdb_memstore_metric_attr:
* Store an object in the specified store. The hostname is expected to be
* canonical.
*/
int
-sdb_store_host(sdb_store_t *store, const char *name, sdb_time_t last_update);
+sdb_memstore_host(sdb_memstore_t *store, const char *name, sdb_time_t last_update);
int
-sdb_store_service(sdb_store_t *store, const char *hostname, const char *name,
+sdb_memstore_service(sdb_memstore_t *store, const char *hostname, const char *name,
sdb_time_t last_update);
int
-sdb_store_metric(sdb_store_t *store, const char *hostname, const char *name,
+sdb_memstore_metric(sdb_memstore_t *store, const char *hostname, const char *name,
sdb_metric_store_t *metric_store, sdb_time_t last_update);
int
-sdb_store_attribute(sdb_store_t *store, const char *hostname,
+sdb_memstore_attribute(sdb_memstore_t *store, const char *hostname,
const char *key, const sdb_data_t *value, sdb_time_t last_update);
int
-sdb_store_service_attr(sdb_store_t *store, const char *hostname,
+sdb_memstore_service_attr(sdb_memstore_t *store, const char *hostname,
const char *service, const char *key, const sdb_data_t *value,
sdb_time_t last_update);
int
-sdb_store_metric_attr(sdb_store_t *store, const char *hostname,
+sdb_memstore_metric_attr(sdb_memstore_t *store, const char *hostname,
const char *metric, const char *key, const sdb_data_t *value,
sdb_time_t last_update);
/*
- * sdb_store_get_host:
+ * sdb_memstore_get_host:
* Query the specified store for a host by its (canonicalized) name.
*
* The function increments the ref count of the host object. The caller needs
* to deref it when no longer using it.
*/
-sdb_store_obj_t *
-sdb_store_get_host(sdb_store_t *store, const char *name);
+sdb_memstore_obj_t *
+sdb_memstore_get_host(sdb_memstore_t *store, const char *name);
/*
- * sdb_store_get_child:
+ * sdb_memstore_get_child:
* Retrieve a host's child object of the specified type and name. The
* reference count of the child object will be incremented before returning
* it. The caller is responsible for releasing the object once it's no longer
* - the child object on success
* - NULL else
*/
-sdb_store_obj_t *
-sdb_store_get_child(sdb_store_obj_t *host, int type, const char *name);
+sdb_memstore_obj_t *
+sdb_memstore_get_child(sdb_memstore_obj_t *host, int type, const char *name);
/*
- * sdb_store_get_field:
+ * sdb_memstore_get_field:
* Get the value of a stored object's queryable field. The caller is
* responsible for freeing any dynamically allocated memory possibly stored in
* the returned value. If 'res' is NULL, the function will return whether the
* - a negative value else
*/
int
-sdb_store_get_field(sdb_store_obj_t *obj, int field, sdb_data_t *res);
+sdb_memstore_get_field(sdb_memstore_obj_t *obj, int field, sdb_data_t *res);
/*
- * sdb_store_get_attr:
+ * sdb_memstore_get_attr:
* Get the value of a stored object's attribute. The caller is responsible for
* freeing any dynamically allocated memory possibly stored in the returned
* value. If 'res' is NULL, the function will return whether the attribute
* - a negative value else
*/
int
-sdb_store_get_attr(sdb_store_obj_t *obj, const char *name, sdb_data_t *res,
- sdb_store_matcher_t *filter);
+sdb_memstore_get_attr(sdb_memstore_obj_t *obj, const char *name, sdb_data_t *res,
+ sdb_memstore_matcher_t *filter);
/*
* Querying a store:
*/
/*
- * sdb_store_query_t:
+ * sdb_memstore_query_t:
* A parsed query readily prepared for execution.
*/
-struct sdb_store_query;
-typedef struct sdb_store_query sdb_store_query_t;
+struct sdb_memstore_query;
+typedef struct sdb_memstore_query sdb_memstore_query_t;
/*
- * sdb_store_query_prepare:
+ * sdb_memstore_query_prepare:
* Prepare the query described by 'ast' for execution in a store.
*
* Returns:
* - a store query on success
* - NULL else
*/
-sdb_store_query_t *
-sdb_store_query_prepare(sdb_ast_node_t *ast);
+sdb_memstore_query_t *
+sdb_memstore_query_prepare(sdb_ast_node_t *ast);
/*
- * sdb_store_query_prepare_matcher:
+ * sdb_memstore_query_prepare_matcher:
* Prepare the logical expression described by 'ast' for execution as a store
* matcher.
*
* - a matcher on success
* - NULL else
*/
-sdb_store_matcher_t *
-sdb_store_query_prepare_matcher(sdb_ast_node_t *ast);
+sdb_memstore_matcher_t *
+sdb_memstore_query_prepare_matcher(sdb_ast_node_t *ast);
/*
- * sdb_store_query_execute:
+ * sdb_memstore_query_execute:
* Execute a previously prepared query in the specified store. The query
* result will be written to 'buf' and any errors to 'errbuf'.
*
* - a negative value on error
*/
int
-sdb_store_query_execute(sdb_store_t *store, sdb_store_query_t *m,
+sdb_memstore_query_execute(sdb_memstore_t *store, sdb_memstore_query_t *m,
sdb_store_writer_t *w, sdb_object_t *wd, sdb_strbuf_t *errbuf);
/*
- * sdb_store_expr_create:
+ * sdb_memstore_expr_create:
* Creates an arithmetic expression implementing the specified operator on the
* specified left and right operand.
*
* - an expression object on success
* - NULL else
*/
-sdb_store_expr_t *
-sdb_store_expr_create(int op, sdb_store_expr_t *left, sdb_store_expr_t *right);
+sdb_memstore_expr_t *
+sdb_memstore_expr_create(int op,
+ sdb_memstore_expr_t *left, sdb_memstore_expr_t *right);
/*
- * sdb_store_expr_typed:
+ * sdb_memstore_expr_typed:
* Creates an expression which evaluates in the context of an object's sibling
* as specified by the given type.
*
@@ -471,11 +472,11 @@ sdb_store_expr_create(int op, sdb_store_expr_t *left, sdb_store_expr_t *right);
* - an expression object on success
* - NULL else
*/
-sdb_store_expr_t *
-sdb_store_expr_typed(int typ, sdb_store_expr_t *expr);
+sdb_memstore_expr_t *
+sdb_memstore_expr_typed(int typ, sdb_memstore_expr_t *expr);
/*
- * sdb_store_expr_fieldvalue:
+ * sdb_memstore_expr_fieldvalue:
* Creates an expression which evaluates to the value of the specified
* queryable field of a stored object.
*
* - an expression object on success
* - NULL else
*/
-sdb_store_expr_t *
-sdb_store_expr_fieldvalue(int field);
+sdb_memstore_expr_t *
+sdb_memstore_expr_fieldvalue(int field);
/*
- * sdb_store_expr_attrvalue:
+ * sdb_memstore_expr_attrvalue:
* Creates an expression which evaluates to the value of the specified
* attribute of a stored object. Evaluates to a NULL value if the attribute
* does not exist.
* - an expression object on success
* - NULL else
*/
-sdb_store_expr_t *
-sdb_store_expr_attrvalue(const char *name);
+sdb_memstore_expr_t *
+sdb_memstore_expr_attrvalue(const char *name);
/*
- * sdb_store_expr_constvalue:
+ * sdb_memstore_expr_constvalue:
* Creates an expression which evaluates to the specified constant value.
*
* Returns:
* - an expression object on success
* - NULL else
*/
-sdb_store_expr_t *
-sdb_store_expr_constvalue(const sdb_data_t *value);
+sdb_memstore_expr_t *
+sdb_memstore_expr_constvalue(const sdb_data_t *value);
/*
- * sdb_store_expr_eval:
+ * sdb_memstore_expr_eval:
* Evaluate an expression for the specified stored object and stores the
* result in 'res'. The result's value will be allocated dynamically if
* necessary and, thus, should be free'd by the caller (e.g. using
* - a negative value else
*/
int
-sdb_store_expr_eval(sdb_store_expr_t *expr, sdb_store_obj_t *obj,
- sdb_data_t *res, sdb_store_matcher_t *filter);
+sdb_memstore_expr_eval(sdb_memstore_expr_t *expr, sdb_memstore_obj_t *obj,
+ sdb_data_t *res, sdb_memstore_matcher_t *filter);
/*
- * sdb_store_expr_iter:
- * Iterate over the elements of an iterable expression. sdb_store_expr_iter
+ * sdb_memstore_expr_iter:
+ * Iterate over the elements of an iterable expression. sdb_memstore_expr_iter
* returns NULL if the expression is not iterable (for the specified object).
*
- * sdb_store_expr_iter_get_next returns NULL if there is no next element.
+ * sdb_memstore_expr_iter_get_next returns NULL if there is no next element.
*/
-sdb_store_expr_iter_t *
-sdb_store_expr_iter(sdb_store_expr_t *expr, sdb_store_obj_t *obj,
- sdb_store_matcher_t *filter);
+sdb_memstore_expr_iter_t *
+sdb_memstore_expr_iter(sdb_memstore_expr_t *expr, sdb_memstore_obj_t *obj,
+ sdb_memstore_matcher_t *filter);
void
-sdb_store_expr_iter_destroy(sdb_store_expr_iter_t *iter);
+sdb_memstore_expr_iter_destroy(sdb_memstore_expr_iter_t *iter);
bool
-sdb_store_expr_iter_has_next(sdb_store_expr_iter_t *iter);
+sdb_memstore_expr_iter_has_next(sdb_memstore_expr_iter_t *iter);
sdb_data_t
-sdb_store_expr_iter_get_next(sdb_store_expr_iter_t *iter);
+sdb_memstore_expr_iter_get_next(sdb_memstore_expr_iter_t *iter);
/*
- * sdb_store_dis_matcher:
+ * sdb_memstore_dis_matcher:
* Creates a matcher matching the disjunction (logical OR) of two matchers.
*/
-sdb_store_matcher_t *
-sdb_store_dis_matcher(sdb_store_matcher_t *left, sdb_store_matcher_t *right);
+sdb_memstore_matcher_t *
+sdb_memstore_dis_matcher(sdb_memstore_matcher_t *left, sdb_memstore_matcher_t *right);
/*
- * sdb_store_con_matcher:
+ * sdb_memstore_con_matcher:
* Creates a matcher matching the conjunction (logical AND) of two matchers.
*/
-sdb_store_matcher_t *
-sdb_store_con_matcher(sdb_store_matcher_t *left, sdb_store_matcher_t *right);
+sdb_memstore_matcher_t *
+sdb_memstore_con_matcher(sdb_memstore_matcher_t *left, sdb_memstore_matcher_t *right);
/*
- * sdb_store_inv_matcher::
+ * sdb_memstore_inv_matcher:
* Creates a matcher matching the inverse (logical NOT) of a matcher.
*/
-sdb_store_matcher_t *
-sdb_store_inv_matcher(sdb_store_matcher_t *m);
+sdb_memstore_matcher_t *
+sdb_memstore_inv_matcher(sdb_memstore_matcher_t *m);
/*
- * sdb_store_any_matcher:
+ * sdb_memstore_any_matcher:
* Creates a matcher iterating over values of the first expression (which has
* to be iterable). It matches if *any* of those elements match 'm'. 'm' has
* to be an ary operation with the left operand unset.
*/
-sdb_store_matcher_t *
-sdb_store_any_matcher(sdb_store_expr_t *iter, sdb_store_matcher_t *m);
+sdb_memstore_matcher_t *
+sdb_memstore_any_matcher(sdb_memstore_expr_t *iter, sdb_memstore_matcher_t *m);
/*
- * sdb_store_all_matcher:
+ * sdb_memstore_all_matcher:
* Creates a matcher iterating over values of the first expression (which has
* to be iterable). It matches if *all* of those elements match 'm'. 'm' has
* to be an ary operation with the left operand unset.
*/
-sdb_store_matcher_t *
-sdb_store_all_matcher(sdb_store_expr_t *iter, sdb_store_matcher_t *m);
+sdb_memstore_matcher_t *
+sdb_memstore_all_matcher(sdb_memstore_expr_t *iter, sdb_memstore_matcher_t *m);
/*
- * sdb_store_in_matcher:
+ * sdb_memstore_in_matcher:
* Creates a matcher which matches if the right value evaluates to an array
* value and the left value is included in that array. See sdb_data_inarray
* for more details.
*/
-sdb_store_matcher_t *
-sdb_store_in_matcher(sdb_store_expr_t *left, sdb_store_expr_t *right);
+sdb_memstore_matcher_t *
+sdb_memstore_in_matcher(sdb_memstore_expr_t *left, sdb_memstore_expr_t *right);
/*
- * sdb_store_lt_matcher, sdb_store_le_matcher, sdb_store_eq_matcher,
- * sdb_store_ge_matcher, sdb_store_gt_matcher:
+ * sdb_memstore_lt_matcher, sdb_memstore_le_matcher, sdb_memstore_eq_matcher,
+ * sdb_memstore_ge_matcher, sdb_memstore_gt_matcher:
* Create conditional matchers comparing the values of two expressions. The
* matcher matches if the left expression compres less than, less or equal
* than, equal to, not equal to, greater or equal than, or greater than the
* right expression.
*/
-sdb_store_matcher_t *
-sdb_store_lt_matcher(sdb_store_expr_t *left, sdb_store_expr_t *right);
-sdb_store_matcher_t *
-sdb_store_le_matcher(sdb_store_expr_t *left, sdb_store_expr_t *right);
-sdb_store_matcher_t *
-sdb_store_eq_matcher(sdb_store_expr_t *left, sdb_store_expr_t *right);
-sdb_store_matcher_t *
-sdb_store_ne_matcher(sdb_store_expr_t *left, sdb_store_expr_t *right);
-sdb_store_matcher_t *
-sdb_store_ge_matcher(sdb_store_expr_t *left, sdb_store_expr_t *right);
-sdb_store_matcher_t *
-sdb_store_gt_matcher(sdb_store_expr_t *left, sdb_store_expr_t *right);
-
-/*
- * sdb_store_regex_matcher:
+sdb_memstore_matcher_t *
+sdb_memstore_lt_matcher(sdb_memstore_expr_t *left, sdb_memstore_expr_t *right);
+sdb_memstore_matcher_t *
+sdb_memstore_le_matcher(sdb_memstore_expr_t *left, sdb_memstore_expr_t *right);
+sdb_memstore_matcher_t *
+sdb_memstore_eq_matcher(sdb_memstore_expr_t *left, sdb_memstore_expr_t *right);
+sdb_memstore_matcher_t *
+sdb_memstore_ne_matcher(sdb_memstore_expr_t *left, sdb_memstore_expr_t *right);
+sdb_memstore_matcher_t *
+sdb_memstore_ge_matcher(sdb_memstore_expr_t *left, sdb_memstore_expr_t *right);
+sdb_memstore_matcher_t *
+sdb_memstore_gt_matcher(sdb_memstore_expr_t *left, sdb_memstore_expr_t *right);
+
+/*
+ * sdb_memstore_regex_matcher:
* Creates a matcher which matches the string value the left expression
* evaluates to against the regular expression the right expression evaluates
* to. The right expression may either be a constant value regular expression
* or string or a dynamic value evaluating to a string. In the latter case,
* the string is compiled to a regex every time the matcher is executed.
*/
-sdb_store_matcher_t *
-sdb_store_regex_matcher(sdb_store_expr_t *left, sdb_store_expr_t *right);
+sdb_memstore_matcher_t *
+sdb_memstore_regex_matcher(sdb_memstore_expr_t *left, sdb_memstore_expr_t *right);
/*
- * sdb_store_nregex_matcher:
- * Creates a regex matcher just like sdb_store_regex_matcher except that it
+ * sdb_memstore_nregex_matcher:
+ * Creates a regex matcher just like sdb_memstore_regex_matcher except that it
* matches in case the regular expression does not match.
*/
-sdb_store_matcher_t *
-sdb_store_nregex_matcher(sdb_store_expr_t *left, sdb_store_expr_t *right);
+sdb_memstore_matcher_t *
+sdb_memstore_nregex_matcher(sdb_memstore_expr_t *left, sdb_memstore_expr_t *right);
/*
- * sdb_store_isnull_matcher:
+ * sdb_memstore_isnull_matcher:
* Creates a matcher matching NULL values.
*/
-sdb_store_matcher_t *
-sdb_store_isnull_matcher(sdb_store_expr_t *expr);
+sdb_memstore_matcher_t *
+sdb_memstore_isnull_matcher(sdb_memstore_expr_t *expr);
/*
- * sdb_store_istrue_matcher, sdb_store_isfalse_matcher:
+ * sdb_memstore_istrue_matcher, sdb_memstore_isfalse_matcher:
* Creates a matcher matching boolean values.
*/
-sdb_store_matcher_t *
-sdb_store_istrue_matcher(sdb_store_expr_t *expr);
-sdb_store_matcher_t *
-sdb_store_isfalse_matcher(sdb_store_expr_t *expr);
+sdb_memstore_matcher_t *
+sdb_memstore_istrue_matcher(sdb_memstore_expr_t *expr);
+sdb_memstore_matcher_t *
+sdb_memstore_isfalse_matcher(sdb_memstore_expr_t *expr);
/*
- * sdb_store_matcher_matches:
+ * sdb_memstore_matcher_matches:
* Check whether the specified matcher matches the specified store object. If
* specified, the filter will be used to preselect objects for further
* evaluation. It is applied to any object that's used during the evaluation
* - 0 else
*/
int
-sdb_store_matcher_matches(sdb_store_matcher_t *m, sdb_store_obj_t *obj,
- sdb_store_matcher_t *filter);
+sdb_memstore_matcher_matches(sdb_memstore_matcher_t *m, sdb_memstore_obj_t *obj,
+ sdb_memstore_matcher_t *filter);
/*
- * sdb_store_matcher_op_cb:
+ * sdb_memstore_matcher_op_cb:
* Callback constructing a matcher operator.
*/
-typedef sdb_store_matcher_t *(*sdb_store_matcher_op_cb)
- (sdb_store_expr_t *, sdb_store_expr_t *);
+typedef sdb_memstore_matcher_t *(*sdb_memstore_matcher_op_cb)
+ (sdb_memstore_expr_t *, sdb_memstore_expr_t *);
/*
- * sdb_store_lookup_cb:
+ * sdb_memstore_lookup_cb:
* Lookup callback. It is called for each matching object when looking up data
* in the store passing on the lookup filter and the specified user-data. The
* lookup aborts early if the callback returns non-zero.
*/
-typedef int (*sdb_store_lookup_cb)(sdb_store_obj_t *obj,
- sdb_store_matcher_t *filter, void *user_data);
+typedef int (*sdb_memstore_lookup_cb)(sdb_memstore_obj_t *obj,
+ sdb_memstore_matcher_t *filter, void *user_data);
/*
- * sdb_store_scan:
+ * sdb_memstore_scan:
* Look up objects of the specified type in the specified store. The specified
* callback function is called for each object in the store matching 'm'. The
* function performs a full scan of all stored objects. If specified, the
* filter will be used to preselect objects for further evaluation. See the
- * description of 'sdb_store_matcher_matches' for details.
+ * description of 'sdb_memstore_matcher_matches' for details.
*
* Returns:
* - 0 on success
* - a negative value else
*/
int
-sdb_store_scan(sdb_store_t *store, int type,
- sdb_store_matcher_t *m, sdb_store_matcher_t *filter,
- sdb_store_lookup_cb cb, void *user_data);
+sdb_memstore_scan(sdb_memstore_t *store, int type,
+ sdb_memstore_matcher_t *m, sdb_memstore_matcher_t *filter,
+ sdb_memstore_lookup_cb cb, void *user_data);
/*
* Flags for JSON formatting.
sdb_store_json_formatter(sdb_strbuf_t *buf, int type, int flags);
/*
- * sdb_store_emit:
+ * sdb_memstore_emit:
* Serialize a single object to JSON adding it to the string buffer associated
* with the formatter object. The serialized object will not include
* attributes or any child objects. Instead, call the function again for each
* of those objects. All attributes have to be emitted before any other
- * children types. Use sdb_store_emit_full() to emit a full (filtered) object.
+ * children types. Use sdb_memstore_emit_full() to emit a full (filtered) object.
*
* Note that the output might not be valid JSON before calling
* sdb_store_json_finish().
* - a negative value else
*/
int
-sdb_store_emit(sdb_store_obj_t *obj, sdb_store_writer_t *w, sdb_object_t *wd);
+sdb_memstore_emit(sdb_memstore_obj_t *obj, sdb_store_writer_t *w, sdb_object_t *wd);
/*
- * sdb_store_emit_full:
+ * sdb_memstore_emit_full:
* Serialize a single object including it's attributes and all children to
* JSON, adding it to the string buffer associated with the formatter object.
* The filter, if specified, is applied to each attribute and child object.
* - a negative value else
*/
int
-sdb_store_emit_full(sdb_store_obj_t *obj, sdb_store_matcher_t *filter,
+sdb_memstore_emit_full(sdb_memstore_obj_t *obj, sdb_memstore_matcher_t *filter,
sdb_store_writer_t *w, sdb_object_t *wd);
/*
index 3cbc1e87c1c2ecd10d858539059b1d0fff98bd64..67a795b0ef3d7d1d6ba362ef7fc62fc6d9286004 100644 (file)
static int
mem_init(sdb_object_t *user_data)
{
- sdb_store_t *store = SDB_STORE(user_data);
+ sdb_memstore_t *store = SDB_MEMSTORE(user_data);
if (! store) {
sdb_log(SDB_LOG_ERR, "store: Failed to allocate store");
return -1;
}
if (sdb_plugin_register_writer("memstore",
- &sdb_store_writer, SDB_OBJ(store))) {
+ &sdb_memstore_writer, SDB_OBJ(store))) {
sdb_object_deref(SDB_OBJ(store));
return -1;
}
if (sdb_plugin_register_reader("memstore",
- &sdb_store_reader, SDB_OBJ(store))) {
+ &sdb_memstore_reader, SDB_OBJ(store))) {
sdb_object_deref(SDB_OBJ(store));
return -1;
}
sdb_module_init(sdb_plugin_info_t *info)
{
/* store singleton */
- static sdb_store_t *store;
+ static sdb_memstore_t *store;
sdb_plugin_set_info(info, SDB_PLUGIN_INFO_DESC, "in-memory object store");
sdb_plugin_set_info(info, SDB_PLUGIN_INFO_COPYRIGHT,
sdb_plugin_set_info(info, SDB_PLUGIN_INFO_PLUGIN_VERSION, SDB_VERSION);
if (! store) {
- if (! (store = sdb_store_create())) {
+ if (! (store = sdb_memstore_create())) {
sdb_log(SDB_LOG_ERR, "store::memory plugin: "
"Failed to create store object");
return -1;
index 3f21a82f9f21952dd684a6361d13deefac662aae..04dfc8b9ee0b9b6e07b245de973c3a762aa04d92 100644 (file)
#include <check.h>
-static sdb_store_t *store;
+static sdb_memstore_t *store;
static void
populate(void)
size_t i;
- store = sdb_store_create();
+ store = sdb_memstore_create();
ck_assert(store != NULL);
for (i = 0; i < SDB_STATIC_ARRAY_LEN(hosts); ++i) {
- int status = sdb_store_host(store, hosts[i], 1);
+ int status = sdb_memstore_host(store, hosts[i], 1);
ck_assert(status == 0);
}
for (i = 0; i < SDB_STATIC_ARRAY_LEN(metrics); ++i) {
- int status = sdb_store_metric(store, metrics[i].host,
+ int status = sdb_memstore_metric(store, metrics[i].host,
metrics[i].metric, /* store */ NULL, 1);
ck_assert(status == 0);
}
for (i = 0; i < SDB_STATIC_ARRAY_LEN(services); ++i) {
- int status = sdb_store_service(store, services[i].host,
+ int status = sdb_memstore_service(store, services[i].host,
services[i].service, 1);
ck_assert(status == 0);
}
for (i = 0; i < SDB_STATIC_ARRAY_LEN(attrs); ++i) {
- int status = sdb_store_attribute(store, attrs[i].host,
+ int status = sdb_memstore_attribute(store, attrs[i].host,
attrs[i].name, &attrs[i].value, 1);
ck_assert(status == 0);
}
for (i = 0; i < SDB_STATIC_ARRAY_LEN(svc_attrs); ++i) {
- int status = sdb_store_service_attr(store, svc_attrs[i].host,
+ int status = sdb_memstore_service_attr(store, svc_attrs[i].host,
svc_attrs[i].service, svc_attrs[i].name,
&svc_attrs[i].value, 1);
ck_assert(status == 0);
}
for (i = 0; i < SDB_STATIC_ARRAY_LEN(metric_attrs); ++i) {
- int status = sdb_store_metric_attr(store, metric_attrs[i].host,
+ int status = sdb_memstore_metric_attr(store, metric_attrs[i].host,
metric_attrs[i].metric, metric_attrs[i].name,
&metric_attrs[i].value, 1);
ck_assert(status == 0);
#define SERVICES { SDB_TYPE_INTEGER, { .integer = SDB_SERVICE } }
#define METRICS { SDB_TYPE_INTEGER, { .integer = SDB_METRIC } }
#define ATTRS { SDB_TYPE_INTEGER, { .integer = SDB_ATTRIBUTE } }
-static sdb_store_expr_t namer = {
+static sdb_memstore_expr_t namer = {
SDB_OBJECT_INIT, FIELD_VALUE, -1, NULL, NULL, NAME,
};
static int64_t int_values[] = { 1, 2, 3, 4, 5 };
unsigned char *datum;
} bin_values[] = { { 4, (unsigned char *)"\3\2\0\1" } };
struct {
- sdb_store_expr_t expr;
+ sdb_memstore_expr_t expr;
bool iterable;
char *host;
START_TEST(test_expr_iter)
{
- sdb_store_obj_t *obj = NULL;
- sdb_store_matcher_t *filter = NULL;
+ sdb_memstore_obj_t *obj = NULL;
+ sdb_memstore_matcher_t *filter = NULL;
int context = SDB_HOST;
- sdb_store_expr_iter_t *iter;
+ sdb_memstore_expr_iter_t *iter;
size_t i;
if (expr_iter_data[_i].host) {
- obj = sdb_store_get_host(store, expr_iter_data[_i].host);
+ obj = sdb_memstore_get_host(store, expr_iter_data[_i].host);
ck_assert(obj != NULL);
if (expr_iter_data[_i].child) {
- sdb_store_obj_t *child = sdb_store_get_child(obj,
+ sdb_memstore_obj_t *child = sdb_memstore_get_child(obj,
expr_iter_data[_i].child_type, expr_iter_data[_i].child);
ck_assert(child != NULL);
sdb_object_deref(SDB_OBJ(obj));
if (expr_iter_data[_i].filter) {
sdb_ast_node_t *ast;
ast = sdb_parser_parse_conditional(context, expr_iter_data[_i].filter, -1, NULL);
- filter = sdb_store_query_prepare_matcher(ast);
+ filter = sdb_memstore_query_prepare_matcher(ast);
sdb_object_deref(SDB_OBJ(ast));
ck_assert(filter != NULL);
}
- iter = sdb_store_expr_iter(&expr_iter_data[_i].expr, obj, filter);
+ iter = sdb_memstore_expr_iter(&expr_iter_data[_i].expr, obj, filter);
fail_unless((iter != NULL) == expr_iter_data[_i].iterable,
- "sdb_store_expr_iter(%s expression, %s, %s) = %s; expected: %s",
+ "sdb_memstore_expr_iter(%s expression, %s, %s) = %s; expected: %s",
EXPR_TO_STRING(&expr_iter_data[_i].expr),
obj ? SDB_STORE_TYPE_TO_NAME(obj->type) : "<array>",
expr_iter_data[_i].filter, iter ? "<iter>" : "NULL",
sdb_object_deref(SDB_OBJ(filter)); filter = NULL;
i = 0;
- while (sdb_store_expr_iter_has_next(iter)) {
+ while (sdb_memstore_expr_iter_has_next(iter)) {
char v_str[64], expected_str[64];
sdb_data_t v;
SDB_STORE_TYPE_TO_NAME(context), expr_iter_data[_i].filter,
i + 1, expr_iter_data[_i].expected_len);
- v = sdb_store_expr_iter_get_next(iter);
+ v = sdb_memstore_expr_iter_get_next(iter);
sdb_data_format(&v, v_str, sizeof(v_str), SDB_DOUBLE_QUOTED);
sdb_data_format(&expr_iter_data[_i].expected[i],
expected_str, sizeof(expected_str), SDB_DOUBLE_QUOTED);
"expected: %zu", EXPR_TO_STRING(&expr_iter_data[_i].expr),
SDB_STORE_TYPE_TO_NAME(context), expr_iter_data[_i].filter,
i, expr_iter_data[_i].expected_len);
- fail_unless(sdb_store_expr_iter_get_next(iter).type == SDB_TYPE_NULL,
+ fail_unless(sdb_memstore_expr_iter_get_next(iter).type == SDB_TYPE_NULL,
"iter<%s expression, %s, %s> returned further elements "
"passed the end", EXPR_TO_STRING(&expr_iter_data[_i].expr),
SDB_STORE_TYPE_TO_NAME(context), expr_iter_data[_i].filter);
- sdb_store_expr_iter_destroy(iter);
+ sdb_memstore_expr_iter_destroy(iter);
}
END_TEST
index b880f7b99a43c5bf9c5381491b9649d43bd53c5a..40548c09340d444ed3d90064a2c4d82f84349858 100644 (file)
#undef SDB_INTERVAL_SECOND
#define SDB_INTERVAL_SECOND 1000000000L
-static sdb_store_t *store;
+static sdb_memstore_t *store;
static void
populate(void)
{
sdb_data_t datum;
- store = sdb_store_create();
+ store = sdb_memstore_create();
ck_assert(store != NULL);
- sdb_store_host(store, "h1", 1 * SDB_INTERVAL_SECOND);
- sdb_store_host(store, "h2", 3 * SDB_INTERVAL_SECOND);
+ sdb_memstore_host(store, "h1", 1 * SDB_INTERVAL_SECOND);
+ sdb_memstore_host(store, "h2", 3 * SDB_INTERVAL_SECOND);
datum.type = SDB_TYPE_STRING;
datum.data.string = "v1";
- sdb_store_attribute(store, "h1", "k1", &datum, 1 * SDB_INTERVAL_SECOND);
+ sdb_memstore_attribute(store, "h1", "k1", &datum, 1 * SDB_INTERVAL_SECOND);
datum.data.string = "v2";
- sdb_store_attribute(store, "h1", "k2", &datum, 2 * SDB_INTERVAL_SECOND);
+ sdb_memstore_attribute(store, "h1", "k2", &datum, 2 * SDB_INTERVAL_SECOND);
datum.data.string = "v3";
- sdb_store_attribute(store, "h1", "k3", &datum, 2 * SDB_INTERVAL_SECOND);
+ sdb_memstore_attribute(store, "h1", "k3", &datum, 2 * SDB_INTERVAL_SECOND);
/* make sure that older updates don't overwrite existing values */
datum.data.string = "fail";
- sdb_store_attribute(store, "h1", "k2", &datum, 1 * SDB_INTERVAL_SECOND);
- sdb_store_attribute(store, "h1", "k3", &datum, 2 * SDB_INTERVAL_SECOND);
+ sdb_memstore_attribute(store, "h1", "k2", &datum, 1 * SDB_INTERVAL_SECOND);
+ sdb_memstore_attribute(store, "h1", "k3", &datum, 2 * SDB_INTERVAL_SECOND);
- sdb_store_metric(store, "h1", "m1", /* store */ NULL, 2 * SDB_INTERVAL_SECOND);
- sdb_store_metric(store, "h1", "m2", /* store */ NULL, 1 * SDB_INTERVAL_SECOND);
- sdb_store_metric(store, "h2", "m1", /* store */ NULL, 1 * SDB_INTERVAL_SECOND);
+ sdb_memstore_metric(store, "h1", "m1", /* store */ NULL, 2 * SDB_INTERVAL_SECOND);
+ sdb_memstore_metric(store, "h1", "m2", /* store */ NULL, 1 * SDB_INTERVAL_SECOND);
+ sdb_memstore_metric(store, "h2", "m1", /* store */ NULL, 1 * SDB_INTERVAL_SECOND);
- sdb_store_service(store, "h2", "s1", 1 * SDB_INTERVAL_SECOND);
- sdb_store_service(store, "h2", "s2", 2 * SDB_INTERVAL_SECOND);
+ sdb_memstore_service(store, "h2", "s1", 1 * SDB_INTERVAL_SECOND);
+ sdb_memstore_service(store, "h2", "s2", 2 * SDB_INTERVAL_SECOND);
datum.type = SDB_TYPE_INTEGER;
datum.data.integer = 42;
- sdb_store_metric_attr(store, "h1", "m1", "k3",
+ sdb_memstore_metric_attr(store, "h1", "m1", "k3",
&datum, 2 * SDB_INTERVAL_SECOND);
datum.data.integer = 123;
- sdb_store_service_attr(store, "h2", "s2", "k1",
+ sdb_memstore_service_attr(store, "h2", "s2", "k1",
&datum, 2 * SDB_INTERVAL_SECOND);
datum.data.integer = 4711;
- sdb_store_service_attr(store, "h2", "s2", "k2",
+ sdb_memstore_service_attr(store, "h2", "s2", "k2",
&datum, 1 * SDB_INTERVAL_SECOND);
/* don't overwrite k1 */
datum.data.integer = 666;
- sdb_store_service_attr(store, "h2", "s2", "k1",
+ sdb_memstore_service_attr(store, "h2", "s2", "k1",
&datum, 2 * SDB_INTERVAL_SECOND);
} /* populate */
} /* turndown */
static int
-scan_tojson(sdb_store_obj_t *obj,
- sdb_store_matcher_t __attribute__((unused)) *filter,
+scan_tojson(sdb_memstore_obj_t *obj,
+ sdb_memstore_matcher_t __attribute__((unused)) *filter,
void *user_data)
{
- return sdb_store_emit(obj, &sdb_store_json_writer, user_data);
+ return sdb_memstore_emit(obj, &sdb_store_json_writer, user_data);
} /* scan_tojson */
static int
-scan_tojson_full(sdb_store_obj_t *obj, sdb_store_matcher_t *filter,
+scan_tojson_full(sdb_memstore_obj_t *obj, sdb_memstore_matcher_t *filter,
void *user_data)
{
- return sdb_store_emit_full(obj, filter, &sdb_store_json_writer, user_data);
+ return sdb_memstore_emit_full(obj, filter, &sdb_store_json_writer, user_data);
} /* scan_tojson_full */
static void
struct {
struct {
- sdb_store_matcher_t *(*m)(sdb_store_expr_t *, sdb_store_expr_t *);
+ sdb_memstore_matcher_t *(*m)(sdb_memstore_expr_t *, sdb_memstore_expr_t *);
int field;
sdb_data_t value;
} filter;
int type;
- int (*f)(sdb_store_obj_t *, sdb_store_matcher_t *, void *);
+ int (*f)(sdb_memstore_obj_t *, sdb_memstore_matcher_t *, void *);
const char *expected;
} store_tojson_data[] = {
{ { NULL, 0, SDB_DATA_INIT },
"{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:03 +0000\", "
"\"update_interval\": \"0s\", \"backends\": []}"
"]" },
- { { sdb_store_eq_matcher, SDB_FIELD_NAME,
+ { { sdb_memstore_eq_matcher, SDB_FIELD_NAME,
{ SDB_TYPE_STRING, { .string = "h1" } } },
SDB_HOST, scan_tojson_full,
"["
"{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:01 +0000\", "
"\"update_interval\": \"0s\", \"backends\": []}"
"]" },
- { { sdb_store_gt_matcher, SDB_FIELD_LAST_UPDATE,
+ { { sdb_memstore_gt_matcher, SDB_FIELD_LAST_UPDATE,
{ SDB_TYPE_DATETIME, { .datetime = 1 * SDB_INTERVAL_SECOND } } },
SDB_HOST, scan_tojson_full,
"["
"]}"
"]}"
"]" },
- { { sdb_store_le_matcher, SDB_FIELD_LAST_UPDATE,
+ { { sdb_memstore_le_matcher, SDB_FIELD_LAST_UPDATE,
{ SDB_TYPE_DATETIME, { .datetime = 1 * SDB_INTERVAL_SECOND } } },
SDB_HOST, scan_tojson_full,
"["
"\"update_interval\": \"0s\", \"backends\": []}"
"]}"
"]" },
- { { sdb_store_ge_matcher, SDB_FIELD_LAST_UPDATE,
+ { { sdb_memstore_ge_matcher, SDB_FIELD_LAST_UPDATE,
{ SDB_TYPE_DATETIME, { .datetime = 3 * SDB_INTERVAL_SECOND } } },
SDB_HOST, scan_tojson_full,
"["
"{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:03 +0000\", "
"\"update_interval\": \"0s\", \"backends\": []}"
"]" },
- { { sdb_store_lt_matcher, SDB_FIELD_LAST_UPDATE,
+ { { sdb_memstore_lt_matcher, SDB_FIELD_LAST_UPDATE,
{ SDB_TYPE_DATETIME, { .datetime = 0 } } },
SDB_HOST, scan_tojson_full,
"[]" },
"\"last_update\": \"1970-01-01 00:00:02 +0000\", "
"\"update_interval\": \"0s\", \"backends\": []}"
"]" },
- { { sdb_store_gt_matcher, SDB_FIELD_LAST_UPDATE,
+ { { sdb_memstore_gt_matcher, SDB_FIELD_LAST_UPDATE,
{ SDB_TYPE_DATETIME, { .datetime = 1 * SDB_INTERVAL_SECOND } } },
SDB_SERVICE, scan_tojson_full,
"["
"\"update_interval\": \"0s\", \"backends\": []}"
"]}"
"]" },
- { { sdb_store_lt_matcher, SDB_FIELD_LAST_UPDATE,
+ { { sdb_memstore_lt_matcher, SDB_FIELD_LAST_UPDATE,
{ SDB_TYPE_DATETIME, { .datetime = 0 } } },
SDB_SERVICE, scan_tojson_full,
"[]" },
"\"last_update\": \"1970-01-01 00:00:01 +0000\", "
"\"update_interval\": \"0s\", \"backends\": []}"
"]" },
- { { sdb_store_le_matcher, SDB_FIELD_LAST_UPDATE,
+ { { sdb_memstore_le_matcher, SDB_FIELD_LAST_UPDATE,
{ SDB_TYPE_DATETIME, { .datetime = 1 * SDB_INTERVAL_SECOND } } },
SDB_METRIC, scan_tojson_full,
"["
"\"last_update\": \"1970-01-01 00:00:01 +0000\", "
"\"update_interval\": \"0s\", \"backends\": []}"
"]" },
- { { sdb_store_lt_matcher, SDB_FIELD_LAST_UPDATE,
+ { { sdb_memstore_lt_matcher, SDB_FIELD_LAST_UPDATE,
{ SDB_TYPE_DATETIME, { .datetime = 0 } } },
SDB_METRIC, scan_tojson_full,
"[]" },
START_TEST(test_store_tojson)
{
sdb_strbuf_t *buf = sdb_strbuf_create(0);
- sdb_store_matcher_t *filter = NULL;
+ sdb_memstore_matcher_t *filter = NULL;
sdb_store_json_formatter_t *f;
int status;
if (store_tojson_data[_i].filter.m) {
- sdb_store_expr_t *field;
- sdb_store_expr_t *value;
+ sdb_memstore_expr_t *field;
+ sdb_memstore_expr_t *value;
- field = sdb_store_expr_fieldvalue(store_tojson_data[_i].filter.field);
+ field = sdb_memstore_expr_fieldvalue(store_tojson_data[_i].filter.field);
fail_unless(field != NULL,
- "INTERNAL ERROR: sdb_store_expr_fieldvalue() = NULL");
- value = sdb_store_expr_constvalue(&store_tojson_data[_i].filter.value);
+ "INTERNAL ERROR: sdb_memstore_expr_fieldvalue() = NULL");
+ value = sdb_memstore_expr_constvalue(&store_tojson_data[_i].filter.value);
fail_unless(value != NULL,
- "INTERNAL ERROR: sdb_store_expr_constvalue() = NULL");
+ "INTERNAL ERROR: sdb_memstore_expr_constvalue() = NULL");
filter = store_tojson_data[_i].filter.m(field, value);
fail_unless(filter != NULL,
- "INTERNAL ERROR: sdb_store_*_matcher() = NULL");
+ "INTERNAL ERROR: sdb_memstore_*_matcher() = NULL");
sdb_object_deref(SDB_OBJ(field));
sdb_object_deref(SDB_OBJ(value));
f = sdb_store_json_formatter(buf, store_tojson_data[_i].type, SDB_WANT_ARRAY);
ck_assert(f != NULL);
- status = sdb_store_scan(store, store_tojson_data[_i].type,
+ status = sdb_memstore_scan(store, store_tojson_data[_i].type,
/* m = */ NULL, filter, store_tojson_data[_i].f, f);
fail_unless(status == 0,
- "sdb_store_scan(HOST, ..., tojson) = %d; expected: 0",
+ "sdb_memstore_scan(HOST, ..., tojson) = %d; expected: 0",
status);
sdb_store_json_finish(f);
index d2c006494ab04f95cffce6fb2f4494dc6b740242..ef0900e8949805344a13b7e6a1320f50ece507c8 100644 (file)
#include <check.h>
#include <string.h>
-static sdb_store_t *store;
+static sdb_memstore_t *store;
static void
populate(void)
size_t i;
- store = sdb_store_create();
+ store = sdb_memstore_create();
ck_assert(store != NULL);
for (i = 0; i < SDB_STATIC_ARRAY_LEN(hosts); ++i) {
- int status = sdb_store_host(store, hosts[i], 1);
+ int status = sdb_memstore_host(store, hosts[i], 1);
fail_unless(status == 0,
- "sdb_store_host(%s, 1) = %d; expected: 0",
+ "sdb_memstore_host(%s, 1) = %d; expected: 0",
hosts[i], status);
}
for (i = 0; i < SDB_STATIC_ARRAY_LEN(metrics); ++i) {
- int status = sdb_store_metric(store, metrics[i].host,
+ int status = sdb_memstore_metric(store, metrics[i].host,
metrics[i].metric, /* store */ NULL, 1);
fail_unless(status == 0,
- "sdb_store_metric(%s, %s, NULL, 1) = %d; expected: 0",
+ "sdb_memstore_metric(%s, %s, NULL, 1) = %d; expected: 0",
metrics[i].host, metrics[i].metric, status);
}
for (i = 0; i < SDB_STATIC_ARRAY_LEN(services); ++i) {
- int status = sdb_store_service(store, services[i].host,
+ int status = sdb_memstore_service(store, services[i].host,
services[i].service, 1);
fail_unless(status == 0,
- "sdb_store_service(%s, %s, 1) = %d; expected: 0",
+ "sdb_memstore_service(%s, %s, 1) = %d; expected: 0",
services[i].host, services[i].service, status);
}
for (i = 0; i < SDB_STATIC_ARRAY_LEN(attrs); ++i) {
- int status = sdb_store_attribute(store, attrs[i].host,
+ int status = sdb_memstore_attribute(store, attrs[i].host,
attrs[i].name, &attrs[i].value, 1);
fail_unless(status == 0,
- "sdb_store_attribute(%s, %s, <val>, 1) = %d; expected: 0",
+ "sdb_memstore_attribute(%s, %s, <val>, 1) = %d; expected: 0",
attrs[i].host, attrs[i].name, status);
}
} /* populate */
START_TEST(test_cmp_name)
{
- sdb_store_obj_t *host;
+ sdb_memstore_obj_t *host;
sdb_data_t datum;
- sdb_store_expr_t *obj = NULL, *value;
- sdb_store_matcher_t *m, *n;
+ sdb_memstore_expr_t *obj = NULL, *value;
+ sdb_memstore_matcher_t *m, *n;
int status;
- host = sdb_store_get_host(store, "a");
+ host = sdb_memstore_get_host(store, "a");
fail_unless(host != NULL,
- "sdb_store_get_host(a) = NULL; expected: <host>");
+ "sdb_memstore_get_host(a) = NULL; expected: <host>");
datum.type = SDB_TYPE_STRING;
datum.data.string = cmp_name_data[_i].name;
if (cmp_name_data[_i].type == SDB_HOST) {
- obj = sdb_store_expr_fieldvalue(SDB_FIELD_NAME);
+ obj = sdb_memstore_expr_fieldvalue(SDB_FIELD_NAME);
fail_unless(obj != NULL,
- "sdb_store_expr_fieldvalue(SDB_STORE_NAME) = NULL; "
+ "sdb_memstore_expr_fieldvalue(SDB_STORE_NAME) = NULL; "
"expected: <expr>");
}
- value = sdb_store_expr_constvalue(&datum);
+ value = sdb_memstore_expr_constvalue(&datum);
fail_unless(value != NULL,
- "sdb_store_expr_constvalue(%s) = NULL; "
+ "sdb_memstore_expr_constvalue(%s) = NULL; "
"expected: <expr>", cmp_name_data[_i].name);
if (cmp_name_data[_i].re)
- m = sdb_store_regex_matcher(obj, value);
+ m = sdb_memstore_regex_matcher(obj, value);
else
- m = sdb_store_eq_matcher(obj, value);
+ m = sdb_memstore_eq_matcher(obj, value);
if (cmp_name_data[_i].type != SDB_HOST) {
- sdb_store_expr_t *iter;
- sdb_store_matcher_t *tmp;
- obj = sdb_store_expr_fieldvalue(SDB_FIELD_NAME);
- iter = sdb_store_expr_typed(cmp_name_data[_i].type, obj);
- tmp = sdb_store_any_matcher(iter, m);
+ sdb_memstore_expr_t *iter;
+ sdb_memstore_matcher_t *tmp;
+ obj = sdb_memstore_expr_fieldvalue(SDB_FIELD_NAME);
+ iter = sdb_memstore_expr_typed(cmp_name_data[_i].type, obj);
+ tmp = sdb_memstore_any_matcher(iter, m);
ck_assert(iter && m);
sdb_object_deref(SDB_OBJ(iter));
sdb_object_deref(SDB_OBJ(m));
sdb_object_deref(SDB_OBJ(obj));
sdb_object_deref(SDB_OBJ(value));
fail_unless(m != NULL,
- "sdb_store_%s_matcher(%s, %s) = NULL; "
+ "sdb_memstore_%s_matcher(%s, %s) = NULL; "
"expected: <matcher>",
cmp_name_data[_i].re ? "regex" : "eq",
SDB_STORE_TYPE_TO_NAME(cmp_name_data[_i].type),
cmp_name_data[_i].name);
- status = sdb_store_matcher_matches(m, host, /* filter */ NULL);
+ status = sdb_memstore_matcher_matches(m, host, /* filter */ NULL);
fail_unless(status == cmp_name_data[_i].expected,
- "sdb_store_matcher_matches(%s->%s, <host a>, NULL) = %d; "
+ "sdb_memstore_matcher_matches(%s->%s, <host a>, NULL) = %d; "
"expected: %d", SDB_STORE_TYPE_TO_NAME(cmp_name_data[_i].type),
cmp_name_data[_i].name, status, cmp_name_data[_i].expected);
- n = sdb_store_inv_matcher(m);
+ n = sdb_memstore_inv_matcher(m);
fail_unless(n != NULL,
- "sdb_store_inv_matcher() = NULL; expected: <matcher>");
+ "sdb_memstore_inv_matcher() = NULL; expected: <matcher>");
sdb_object_deref(SDB_OBJ(m));
/* now match the inverted set of objects */
- status = sdb_store_matcher_matches(n, host, /* filter */ NULL);
+ status = sdb_memstore_matcher_matches(n, host, /* filter */ NULL);
fail_unless(status == !cmp_name_data[_i].expected,
- "sdb_store_matcher_matches(%s->%s, <host a>, NULL) = %d; "
+ "sdb_memstore_matcher_matches(%s->%s, <host a>, NULL) = %d; "
"expected: %d", SDB_STORE_TYPE_TO_NAME(cmp_name_data[_i].type),
cmp_name_data[_i].name, status, !cmp_name_data[_i].expected);
START_TEST(test_cmp_attr)
{
- sdb_store_obj_t *host;
- sdb_store_expr_t *attr;
- sdb_store_expr_t *value;
+ sdb_memstore_obj_t *host;
+ sdb_memstore_expr_t *attr;
+ sdb_memstore_expr_t *value;
char value_str[1024];
int status;
size_t j;
struct {
- sdb_store_matcher_t *(*matcher)(sdb_store_expr_t *,
- sdb_store_expr_t *);
+ sdb_memstore_matcher_t *(*matcher)(sdb_memstore_expr_t *,
+ sdb_memstore_expr_t *);
int expected;
} tests[] = {
- { sdb_store_lt_matcher, cmp_attr_data[_i].expected_lt },
- { sdb_store_le_matcher, cmp_attr_data[_i].expected_le },
- { sdb_store_eq_matcher, cmp_attr_data[_i].expected_eq },
- { sdb_store_ge_matcher, cmp_attr_data[_i].expected_ge },
- { sdb_store_gt_matcher, cmp_attr_data[_i].expected_gt },
+ { sdb_memstore_lt_matcher, cmp_attr_data[_i].expected_lt },
+ { sdb_memstore_le_matcher, cmp_attr_data[_i].expected_le },
+ { sdb_memstore_eq_matcher, cmp_attr_data[_i].expected_eq },
+ { sdb_memstore_ge_matcher, cmp_attr_data[_i].expected_ge },
+ { sdb_memstore_gt_matcher, cmp_attr_data[_i].expected_gt },
};
const char *op_str[] = { "<", "<=", "=", ">=", ">" };
ck_assert(SDB_STATIC_ARRAY_LEN(tests) == SDB_STATIC_ARRAY_LEN(op_str));
- host = sdb_store_get_host(store, "a");
+ host = sdb_memstore_get_host(store, "a");
fail_unless(host != NULL,
- "sdb_store_get_host(a) = NULL; expected: <host>");
+ "sdb_memstore_get_host(a) = NULL; expected: <host>");
sdb_data_format(&cmp_attr_data[_i].value,
value_str, sizeof(value_str), SDB_UNQUOTED);
- attr = sdb_store_expr_attrvalue(cmp_attr_data[_i].attr);
+ attr = sdb_memstore_expr_attrvalue(cmp_attr_data[_i].attr);
fail_unless(attr != NULL,
- "sdb_store_expr_attrvalue(%s) = NULL; expected: <expr>",
+ "sdb_memstore_expr_attrvalue(%s) = NULL; expected: <expr>",
cmp_attr_data[_i].attr);
- value = sdb_store_expr_constvalue(&cmp_attr_data[_i].value);
+ value = sdb_memstore_expr_constvalue(&cmp_attr_data[_i].value);
fail_unless(value != NULL,
- "sdb_store_expr_constvalue(%s) = NULL; expected: <expr>",
+ "sdb_memstore_expr_constvalue(%s) = NULL; expected: <expr>",
value_str);
for (j = 0; j < SDB_STATIC_ARRAY_LEN(tests); ++j) {
- sdb_store_matcher_t *m;
+ sdb_memstore_matcher_t *m;
m = tests[j].matcher(attr, value);
fail_unless(m != NULL,
- "sdb_store_<cond>_matcher() = NULL; expected: <matcher>");
+ "sdb_memstore_<cond>_matcher() = NULL; expected: <matcher>");
- status = sdb_store_matcher_matches(m, host, /* filter */ NULL);
+ status = sdb_memstore_matcher_matches(m, host, /* filter */ NULL);
fail_unless(status == tests[j].expected,
- "sdb_store_matcher_matches(<attr[%s] %s %s>, "
+ "sdb_memstore_matcher_matches(<attr[%s] %s %s>, "
"<host>, NULL) = %d; expected: %d",
cmp_attr_data[_i].attr, op_str[j], value_str,
status, tests[j].expected);
START_TEST(test_cmp_obj)
{
- sdb_store_obj_t *host;
- sdb_store_expr_t *field;
- sdb_store_expr_t *value;
+ sdb_memstore_obj_t *host;
+ sdb_memstore_expr_t *field;
+ sdb_memstore_expr_t *value;
char value_str[1024];
int status;
size_t j;
struct {
- sdb_store_matcher_t *(*matcher)(sdb_store_expr_t *,
- sdb_store_expr_t *);
+ sdb_memstore_matcher_t *(*matcher)(sdb_memstore_expr_t *,
+ sdb_memstore_expr_t *);
int expected;
} tests[] = {
- { sdb_store_lt_matcher, cmp_obj_data[_i].expected_lt },
- { sdb_store_le_matcher, cmp_obj_data[_i].expected_le },
- { sdb_store_eq_matcher, cmp_obj_data[_i].expected_eq },
- { sdb_store_ge_matcher, cmp_obj_data[_i].expected_ge },
- { sdb_store_gt_matcher, cmp_obj_data[_i].expected_gt },
+ { sdb_memstore_lt_matcher, cmp_obj_data[_i].expected_lt },
+ { sdb_memstore_le_matcher, cmp_obj_data[_i].expected_le },
+ { sdb_memstore_eq_matcher, cmp_obj_data[_i].expected_eq },
+ { sdb_memstore_ge_matcher, cmp_obj_data[_i].expected_ge },
+ { sdb_memstore_gt_matcher, cmp_obj_data[_i].expected_gt },
};
char *op_str[] = { "<", "<=", "=", ">=", ">" };
ck_assert(SDB_STATIC_ARRAY_LEN(tests) == SDB_STATIC_ARRAY_LEN(op_str));
- host = sdb_store_get_host(store, cmp_obj_data[_i].host);
+ host = sdb_memstore_get_host(store, cmp_obj_data[_i].host);
fail_unless(host != NULL,
- "sdb_store_get_host(%s) = NULL; expected: <host>",
+ "sdb_memstore_get_host(%s) = NULL; expected: <host>",
cmp_obj_data[_i].host);
sdb_data_format(&cmp_obj_data[_i].value,
value_str, sizeof(value_str), SDB_UNQUOTED);
- field = sdb_store_expr_fieldvalue(cmp_obj_data[_i].field);
+ field = sdb_memstore_expr_fieldvalue(cmp_obj_data[_i].field);
fail_unless(field != NULL,
- "sdb_store_expr_fieldvalue(%d) = NULL; "
+ "sdb_memstore_expr_fieldvalue(%d) = NULL; "
"expected: <expr>", cmp_obj_data[_i].field);
- value = sdb_store_expr_constvalue(&cmp_obj_data[_i].value);
+ value = sdb_memstore_expr_constvalue(&cmp_obj_data[_i].value);
fail_unless(value != NULL,
- "sdb_store_expr_constvalue(%s) = NULL; "
+ "sdb_memstore_expr_constvalue(%s) = NULL; "
"expected: <expr>", value_str);
for (j = 0; j < SDB_STATIC_ARRAY_LEN(tests); ++j) {
char m_str[1024];
- sdb_store_matcher_t *m;
+ sdb_memstore_matcher_t *m;
snprintf(m_str, sizeof(m_str), "%s %s %s",
SDB_FIELD_TO_NAME(cmp_obj_data[_i].field),
m = tests[j].matcher(field, value);
fail_unless(m != NULL,
- "sdb_store_<cond>_matcher() = NULL; expected: <matcher>");
+ "sdb_memstore_<cond>_matcher() = NULL; expected: <matcher>");
- status = sdb_store_matcher_matches(m, host, /* filter */ NULL);
+ status = sdb_memstore_matcher_matches(m, host, /* filter */ NULL);
fail_unless(status == tests[j].expected,
- "sdb_store_matcher_matches(<%s>, <host '%s'>, NULL) = %d; "
+ "sdb_memstore_matcher_matches(<%s>, <host '%s'>, NULL) = %d; "
"expected: %d", m_str, cmp_obj_data[_i].host, status,
tests[j].expected);
START_TEST(test_store_match_op)
{
- sdb_store_obj_t *obj;
+ sdb_memstore_obj_t *obj;
sdb_data_t d = { SDB_TYPE_STRING, { .string = "a" } };
- sdb_store_expr_t *e = sdb_store_expr_constvalue(&d);
+ sdb_memstore_expr_t *e = sdb_memstore_expr_constvalue(&d);
- sdb_store_matcher_t *never = sdb_store_isnull_matcher(e);
- sdb_store_matcher_t *always = sdb_store_inv_matcher(never);
+ sdb_memstore_matcher_t *never = sdb_memstore_isnull_matcher(e);
+ sdb_memstore_matcher_t *always = sdb_memstore_inv_matcher(never);
struct {
const char *op;
- sdb_store_matcher_t *left;
- sdb_store_matcher_t *right;
+ sdb_memstore_matcher_t *left;
+ sdb_memstore_matcher_t *right;
int expected;
} golden_data[] = {
{ "OR", always, always, 1 },
int status;
size_t i;
- obj = sdb_store_get_host(store, "a");
+ obj = sdb_memstore_get_host(store, "a");
- status = sdb_store_matcher_matches(always, obj, /* filter */ NULL);
+ status = sdb_memstore_matcher_matches(always, obj, /* filter */ NULL);
fail_unless(status == 1,
"INTERNAL ERROR: 'always' did not match host");
- status = sdb_store_matcher_matches(never, obj, /* filter */ NULL);
+ status = sdb_memstore_matcher_matches(never, obj, /* filter */ NULL);
fail_unless(status == 0,
"INTERNAL ERROR: 'never' matches host");
for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_data); ++i) {
- sdb_store_matcher_t *m;
+ sdb_memstore_matcher_t *m;
if (! strcmp(golden_data[i].op, "OR"))
- m = sdb_store_dis_matcher(golden_data[i].left,
+ m = sdb_memstore_dis_matcher(golden_data[i].left,
golden_data[i].right);
else if (! strcmp(golden_data[i].op, "AND"))
- m = sdb_store_con_matcher(golden_data[i].left,
+ m = sdb_memstore_con_matcher(golden_data[i].left,
golden_data[i].right);
else {
fail("INTERNAL ERROR: unexpected operator %s", golden_data[i].op);
#define TO_NAME(v) (((v) == always) ? "always" \
: ((v) == never) ? "never" : "<unknown>")
- status = sdb_store_matcher_matches(m, obj, /* filter */ NULL);
+ status = sdb_memstore_matcher_matches(m, obj, /* filter */ NULL);
fail_unless(status == golden_data[i].expected,
"%s(%s, %s, NULL) = %d; expected: %d", golden_data[i].op,
TO_NAME(golden_data[i].left), TO_NAME(golden_data[i].right),
END_TEST
static int
-scan_cb(sdb_store_obj_t *obj, sdb_store_matcher_t *filter, void *user_data)
+scan_cb(sdb_memstore_obj_t *obj, sdb_memstore_matcher_t *filter, void *user_data)
{
int *i = user_data;
- if (! sdb_store_matcher_matches(filter, obj, NULL))
+ if (! sdb_memstore_matcher_matches(filter, obj, NULL))
return 0;
fail_unless(obj != NULL,
- "sdb_store_scan callback received NULL obj; expected: "
+ "sdb_memstore_scan callback received NULL obj; expected: "
"<store base obj>");
fail_unless(i != NULL,
- "sdb_store_scan callback received NULL user_data; "
+ "sdb_memstore_scan callback received NULL user_data; "
"expected: <pointer to data>");
++(*i);
START_TEST(test_scan)
{
sdb_strbuf_t *errbuf = sdb_strbuf_create(64);
- sdb_store_matcher_t *m, *filter = NULL;
+ sdb_memstore_matcher_t *m, *filter = NULL;
sdb_ast_node_t *ast;
int check, n;
n = 0;
- check = sdb_store_scan(store, SDB_HOST,
+ check = sdb_memstore_scan(store, SDB_HOST,
/* matcher */ NULL, /* filter */ NULL,
scan_cb, &n);
fail_unless(check == 0,
- "sdb_store_scan() = %d; expected: 0", check);
+ "sdb_memstore_scan() = %d; expected: 0", check);
fail_unless(n == 3,
- "sdb_store_scan called callback %d times; expected: 3", (int)n);
+ "sdb_memstore_scan called callback %d times; expected: 3", (int)n);
ast = sdb_parser_parse_conditional(SDB_HOST, scan_data[_i].query, -1, errbuf);
- m = sdb_store_query_prepare_matcher(ast);
+ m = sdb_memstore_query_prepare_matcher(ast);
sdb_object_deref(SDB_OBJ(ast));
fail_unless(m != NULL,
"sdb_parser_parse_conditional(HOST, %s, -1) = NULL; expected: <ast> "
if (scan_data[_i].filter) {
ast = sdb_parser_parse_conditional(SDB_HOST, scan_data[_i].filter, -1, errbuf);
- filter = sdb_store_query_prepare_matcher(ast);
+ filter = sdb_memstore_query_prepare_matcher(ast);
sdb_object_deref(SDB_OBJ(ast));
fail_unless(filter != NULL,
"sdb_parser_parse_conditional(HOST, %s, -1) = NULL; "
}
n = 0;
- sdb_store_scan(store, SDB_HOST, m, filter, scan_cb, &n);
+ sdb_memstore_scan(store, SDB_HOST, m, filter, scan_cb, &n);
fail_unless(n == scan_data[_i].expected,
- "sdb_store_scan(HOST, matcher{%s}, filter{%s}) "
+ "sdb_memstore_scan(HOST, matcher{%s}, filter{%s}) "
"found %d hosts; expected: %d", scan_data[_i].query,
scan_data[_i].filter, n, scan_data[_i].expected);
index 1d524b6070bb966ca8c7ae74b3963fd3bd00281b..5299a318691d8d577db15c677ee97a84bcd926a6 100644 (file)
--- a/t/unit/core/store_test.c
+++ b/t/unit/core/store_test.c
#include <string.h>
#include <strings.h>
-static sdb_store_t *store;
+static sdb_memstore_t *store;
static void
init(void)
{
- store = sdb_store_create();
+ store = sdb_memstore_create();
ck_assert(store != NULL);
}
{
sdb_data_t datum;
- sdb_store_host(store, "h1", 1);
- sdb_store_host(store, "h2", 3);
+ sdb_memstore_host(store, "h1", 1);
+ sdb_memstore_host(store, "h2", 3);
datum.type = SDB_TYPE_STRING;
datum.data.string = "v1";
- sdb_store_attribute(store, "h1", "k1", &datum, 1);
+ sdb_memstore_attribute(store, "h1", "k1", &datum, 1);
datum.data.string = "v2";
- sdb_store_attribute(store, "h1", "k2", &datum, 2);
+ sdb_memstore_attribute(store, "h1", "k2", &datum, 2);
datum.data.string = "v3";
- sdb_store_attribute(store, "h1", "k3", &datum, 2);
+ sdb_memstore_attribute(store, "h1", "k3", &datum, 2);
/* make sure that older updates don't overwrite existing values */
datum.data.string = "fail";
- sdb_store_attribute(store, "h1", "k2", &datum, 1);
- sdb_store_attribute(store, "h1", "k3", &datum, 2);
+ sdb_memstore_attribute(store, "h1", "k2", &datum, 1);
+ sdb_memstore_attribute(store, "h1", "k3", &datum, 2);
- sdb_store_metric(store, "h1", "m1", /* store */ NULL, 2);
- sdb_store_metric(store, "h1", "m2", /* store */ NULL, 1);
- sdb_store_metric(store, "h2", "m1", /* store */ NULL, 1);
+ sdb_memstore_metric(store, "h1", "m1", /* store */ NULL, 2);
+ sdb_memstore_metric(store, "h1", "m2", /* store */ NULL, 1);
+ sdb_memstore_metric(store, "h2", "m1", /* store */ NULL, 1);
- sdb_store_service(store, "h2", "s1", 1);
- sdb_store_service(store, "h2", "s2", 2);
+ sdb_memstore_service(store, "h2", "s1", 1);
+ sdb_memstore_service(store, "h2", "s2", 2);
datum.type = SDB_TYPE_INTEGER;
datum.data.integer = 42;
- sdb_store_metric_attr(store, "h1", "m1", "k3", &datum, 2);
+ sdb_memstore_metric_attr(store, "h1", "m1", "k3", &datum, 2);
datum.data.integer = 123;
- sdb_store_service_attr(store, "h2", "s2", "k1", &datum, 2);
+ sdb_memstore_service_attr(store, "h2", "s2", "k1", &datum, 2);
datum.data.integer = 4711;
- sdb_store_service_attr(store, "h2", "s2", "k2", &datum, 1);
+ sdb_memstore_service_attr(store, "h2", "s2", "k2", &datum, 1);
/* don't overwrite k1 */
datum.data.integer = 666;
- sdb_store_service_attr(store, "h2", "s2", "k1", &datum, 2);
+ sdb_memstore_service_attr(store, "h2", "s2", "k1", &datum, 2);
} /* populate */
static void
for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_data); ++i) {
int status;
- status = sdb_store_host(store, golden_data[i].name,
+ status = sdb_memstore_host(store, golden_data[i].name,
golden_data[i].last_update);
fail_unless(status == golden_data[i].expected,
- "sdb_store_host(%s, %d) = %d; expected: %d",
+ "sdb_memstore_host(%s, %d) = %d; expected: %d",
golden_data[i].name, (int)golden_data[i].last_update,
status, golden_data[i].expected);
}
for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_hosts); ++i) {
- sdb_store_obj_t *have;
+ sdb_memstore_obj_t *have;
- have = sdb_store_get_host(store, golden_hosts[i].name);
+ have = sdb_memstore_get_host(store, golden_hosts[i].name);
fail_unless((have != NULL) == golden_hosts[i].have,
- "sdb_store_get_host(%s) = %p; expected: %s",
+ "sdb_memstore_get_host(%s) = %p; expected: %s",
golden_hosts[i].name, have,
golden_hosts[i].have ? "<host>" : "NULL");
sdb_object_deref(SDB_OBJ(have));
size_t i;
for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_hosts); ++i) {
- int status = sdb_store_host(store, golden_hosts[i], 1);
+ int status = sdb_memstore_host(store, golden_hosts[i], 1);
fail_unless(status >= 0,
- "sdb_store_host(%s) = %d; expected: >=0",
+ "sdb_memstore_host(%s) = %d; expected: >=0",
golden_hosts[i], status);
}
for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_hosts); ++i) {
- sdb_store_obj_t *sobj1, *sobj2;
+ sdb_memstore_obj_t *sobj1, *sobj2;
int ref_cnt;
- sobj1 = sdb_store_get_host(store, golden_hosts[i]);
+ sobj1 = sdb_memstore_get_host(store, golden_hosts[i]);
fail_unless(sobj1 != NULL,
- "sdb_store_get_host(%s) = NULL; expected: <host>",
+ "sdb_memstore_get_host(%s) = NULL; expected: <host>",
golden_hosts[i]);
ref_cnt = SDB_OBJ(sobj1)->ref_cnt;
fail_unless(ref_cnt > 1,
- "sdb_store_get_host(%s) did not increment ref count: "
+ "sdb_memstore_get_host(%s) did not increment ref count: "
"got: %d; expected: >1", golden_hosts[i], ref_cnt);
- sobj2 = sdb_store_get_host(store, golden_hosts[i]);
+ sobj2 = sdb_memstore_get_host(store, golden_hosts[i]);
fail_unless(sobj2 != NULL,
- "sdb_store_get_host(%s) = NULL; expected: <host>",
+ "sdb_memstore_get_host(%s) = NULL; expected: <host>",
golden_hosts[i]);
fail_unless(sobj1 == sobj2,
- "sdb_store_get_host(%s) returned different objects "
+ "sdb_memstore_get_host(%s) returned different objects "
"in successive calls", golden_hosts[i]);
fail_unless(SDB_OBJ(sobj2)->ref_cnt == ref_cnt + 1,
- "sdb_store_get_hosts(%s) did not increment ref count "
+ "sdb_memstore_get_hosts(%s) did not increment ref count "
"(first call: %d; second call: %d)",
golden_hosts[i], ref_cnt, SDB_OBJ(sobj2)->ref_cnt);
sdb_object_deref(SDB_OBJ(sobj2));
}
for (i = 0; i < SDB_STATIC_ARRAY_LEN(unknown_hosts); ++i) {
- sdb_store_obj_t *sobj;
+ sdb_memstore_obj_t *sobj;
- sobj = sdb_store_get_host(store, unknown_hosts[i]);
- fail_unless(!sobj, "sdb_store_get_host(%s) = <host:%s>; expected: NULL",
+ sobj = sdb_memstore_get_host(store, unknown_hosts[i]);
+ fail_unless(!sobj, "sdb_memstore_get_host(%s) = <host:%s>; expected: NULL",
unknown_hosts[i], sobj ? SDB_OBJ(sobj)->name : "NULL");
}
}
size_t i;
- sdb_store_host(store, "l", 1);
- sdb_store_host(store, "m", 1);
+ sdb_memstore_host(store, "l", 1);
+ sdb_memstore_host(store, "m", 1);
for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_data); ++i) {
sdb_data_t datum;
int status;
datum.type = SDB_TYPE_STRING;
datum.data.string = golden_data[i].value;
- status = sdb_store_attribute(store, golden_data[i].host,
+ status = sdb_memstore_attribute(store, golden_data[i].host,
golden_data[i].key, &datum,
golden_data[i].last_update);
fail_unless(status == golden_data[i].expected,
- "sdb_store_attribute(%s, %s, %s, %d) = %d; expected: %d",
+ "sdb_memstore_attribute(%s, %s, %s, %d) = %d; expected: %d",
golden_data[i].host, golden_data[i].key, golden_data[i].value,
golden_data[i].last_update, status, golden_data[i].expected);
}
size_t i;
- sdb_store_host(store, "m", 1);
- sdb_store_host(store, "l", 1);
+ sdb_memstore_host(store, "m", 1);
+ sdb_memstore_host(store, "l", 1);
for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_data); ++i) {
int status;
- status = sdb_store_metric(store, golden_data[i].host,
+ status = sdb_memstore_metric(store, golden_data[i].host,
golden_data[i].metric, golden_data[i].store,
golden_data[i].last_update);
fail_unless(status == golden_data[i].expected,
- "sdb_store_metric(%s, %s, %p, %d) = %d; expected: %d",
+ "sdb_memstore_metric(%s, %s, %p, %d) = %d; expected: %d",
golden_data[i].host, golden_data[i].metric,
golden_data[i].store, golden_data[i].last_update,
status, golden_data[i].expected);
size_t i;
- sdb_store_host(store, "m", 1);
- sdb_store_host(store, "l", 1);
- sdb_store_metric(store, "m", "m1", NULL, 1);
- sdb_store_metric(store, "l", "m1", NULL, 1);
- sdb_store_metric(store, "l", "m2", NULL, 1);
+ sdb_memstore_host(store, "m", 1);
+ sdb_memstore_host(store, "l", 1);
+ sdb_memstore_metric(store, "m", "m1", NULL, 1);
+ sdb_memstore_metric(store, "l", "m1", NULL, 1);
+ sdb_memstore_metric(store, "l", "m2", NULL, 1);
for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_data); ++i) {
int status;
- status = sdb_store_metric_attr(store, golden_data[i].host,
+ status = sdb_memstore_metric_attr(store, golden_data[i].host,
golden_data[i].metric, golden_data[i].attr,
&golden_data[i].value, golden_data[i].last_update);
fail_unless(status == golden_data[i].expected,
- "sdb_store_metric_attr(%s, %s, %s, %d, %d) = %d; "
+ "sdb_memstore_metric_attr(%s, %s, %s, %d, %d) = %d; "
"expected: %d", golden_data[i].host, golden_data[i].metric,
golden_data[i].attr, golden_data[i].value.data.integer,
golden_data[i].last_update, status, golden_data[i].expected);
size_t i;
- sdb_store_host(store, "m", 1);
- sdb_store_host(store, "l", 1);
+ sdb_memstore_host(store, "m", 1);
+ sdb_memstore_host(store, "l", 1);
for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_data); ++i) {
int status;
- status = sdb_store_service(store, golden_data[i].host,
+ status = sdb_memstore_service(store, golden_data[i].host,
golden_data[i].svc, golden_data[i].last_update);
fail_unless(status == golden_data[i].expected,
- "sdb_store_service(%s, %s, %d) = %d; expected: %d",
+ "sdb_memstore_service(%s, %s, %d) = %d; expected: %d",
golden_data[i].host, golden_data[i].svc,
golden_data[i].last_update, status, golden_data[i].expected);
}
size_t i;
- sdb_store_host(store, "m", 1);
- sdb_store_host(store, "l", 1);
- sdb_store_service(store, "m", "s1", 1);
- sdb_store_service(store, "l", "s1", 1);
- sdb_store_service(store, "l", "s2", 1);
+ sdb_memstore_host(store, "m", 1);
+ sdb_memstore_host(store, "l", 1);
+ sdb_memstore_service(store, "m", "s1", 1);
+ sdb_memstore_service(store, "l", "s1", 1);
+ sdb_memstore_service(store, "l", "s2", 1);
for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_data); ++i) {
int status;
- status = sdb_store_service_attr(store, golden_data[i].host,
+ status = sdb_memstore_service_attr(store, golden_data[i].host,
golden_data[i].svc, golden_data[i].attr,
&golden_data[i].value, golden_data[i].last_update);
fail_unless(status == golden_data[i].expected,
- "sdb_store_service_attr(%s, %s, %s, %d, %d) = %d; "
+ "sdb_memstore_service_attr(%s, %s, %s, %d, %d) = %d; "
"expected: %d", golden_data[i].host, golden_data[i].svc,
golden_data[i].attr, golden_data[i].value.data.integer,
golden_data[i].last_update, status, golden_data[i].expected);
(obj) ? SDB_OBJ(obj)->name : ""
START_TEST(test_get_field)
{
- sdb_store_obj_t *obj = NULL;
+ sdb_memstore_obj_t *obj = NULL;
sdb_data_t value = SDB_DATA_INIT;
char value_str[128], expected_value_str[128];
sdb_time_t now = sdb_gettime();
int check;
- sdb_store_host(store, "host", 10);
- sdb_store_host(store, "host", 20);
- sdb_store_attribute(store, "host", "attr", &get_field_data[_i].value, 10);
- sdb_store_attribute(store, "host", "attr", &get_field_data[_i].value, 20);
+ sdb_memstore_host(store, "host", 10);
+ sdb_memstore_host(store, "host", 20);
+ sdb_memstore_attribute(store, "host", "attr", &get_field_data[_i].value, 10);
+ sdb_memstore_attribute(store, "host", "attr", &get_field_data[_i].value, 20);
if (get_field_data[_i].hostname) {
- obj = sdb_store_get_host(store, get_field_data[_i].hostname);
+ obj = sdb_memstore_get_host(store, get_field_data[_i].hostname);
ck_assert(obj != NULL);
if (get_field_data[_i].attr) {
- sdb_store_obj_t *tmp = sdb_store_get_child(obj,
+ sdb_memstore_obj_t *tmp = sdb_memstore_get_child(obj,
SDB_ATTRIBUTE, get_field_data[_i].attr);
sdb_object_deref(SDB_OBJ(obj));
obj = tmp;
}
}
- check = sdb_store_get_field(obj, get_field_data[_i].field, NULL);
+ check = sdb_memstore_get_field(obj, get_field_data[_i].field, NULL);
fail_unless(check == get_field_data[_i].expected,
- "sdb_store_get_field(%s %s, %s, NULL) = %d; expected: %d",
+ "sdb_memstore_get_field(%s %s, %s, NULL) = %d; expected: %d",
OBJ_NAME(obj), SDB_FIELD_TO_NAME(get_field_data[_i].field),
check, get_field_data[_i].expected);
- check = sdb_store_get_field(obj, get_field_data[_i].field, &value);
+ check = sdb_memstore_get_field(obj, get_field_data[_i].field, &value);
fail_unless(check == get_field_data[_i].expected,
- "sdb_store_get_field(%s %s, %s, <value>) = %d; expected: %d",
+ "sdb_memstore_get_field(%s %s, %s, <value>) = %d; expected: %d",
OBJ_NAME(obj), SDB_FIELD_TO_NAME(get_field_data[_i].field),
check, get_field_data[_i].expected);
if (get_field_data[_i].field == SDB_FIELD_AGE) {
fail_unless((value.type == SDB_TYPE_DATETIME)
&& (value.data.datetime >= now),
- "sdb_store_get_field(%s %s, %s, <value>) "
+ "sdb_memstore_get_field(%s %s, %s, <value>) "
"returned value %s; expected >=%s", OBJ_NAME(obj),
SDB_FIELD_TO_NAME(get_field_data[_i].field),
value_str, expected_value_str);
}
else {
fail_unless(! sdb_data_cmp(&value, &get_field_data[_i].value),
- "sdb_store_get_field(%s %s, %s, <value>) "
+ "sdb_memstore_get_field(%s %s, %s, <value>) "
"returned value %s; expected %s", OBJ_NAME(obj),
SDB_FIELD_TO_NAME(get_field_data[_i].field),
value_str, expected_value_str);
populate();
for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_data); ++i) {
- sdb_store_obj_t *obj;
+ sdb_memstore_obj_t *obj;
const char *expected_name = golden_data[i].host;
- obj = sdb_store_get_host(store, golden_data[i].host);
+ obj = sdb_memstore_get_host(store, golden_data[i].host);
if (golden_data[i].expected && (golden_data[i].type == SDB_HOST))
fail_unless(obj == NULL,
- "sdb_store_get_host(%s) = %p; expected: NULL",
+ "sdb_memstore_get_host(%s) = %p; expected: NULL",
golden_data[i].host, obj);
else
fail_unless(obj != NULL,
- "sdb_store_get_host(%s) = NULL; expected: <host>",
+ "sdb_memstore_get_host(%s) = NULL; expected: <host>",
golden_data[i].host);
if (golden_data[i].type != SDB_HOST) {
- sdb_store_obj_t *tmp;
+ sdb_memstore_obj_t *tmp;
expected_name = golden_data[i].name;
- tmp = sdb_store_get_child(obj,
+ tmp = sdb_memstore_get_child(obj,
golden_data[i].type, golden_data[i].name);
if (golden_data[i].expected)
fail_unless(tmp == NULL,
- "sdb_store_get_child(<%s>, %s, %s) = %p; "
+ "sdb_memstore_get_child(<%s>, %s, %s) = %p; "
"expected: NULL", golden_data[i].host,
SDB_STORE_TYPE_TO_NAME(golden_data[i].type),
golden_data[i].name, tmp);
else
fail_unless(tmp != NULL,
- "sdb_store_get_child(<%s>, %s, %s) = NULL; "
+ "sdb_memstore_get_child(<%s>, %s, %s) = NULL; "
"expected: <obj>", golden_data[i].host,
SDB_STORE_TYPE_TO_NAME(golden_data[i].type),
golden_data[i].name);
continue;
fail_unless(obj->type == golden_data[i].type,
- "sdb_store_get_<%s>(%s, %s) returned object of type %d; "
+ "sdb_memstore_get_<%s>(%s, %s) returned object of type %d; "
"expected: %d", SDB_STORE_TYPE_TO_NAME(golden_data[i].type),
golden_data[i].host, golden_data[i].name, obj->type,
golden_data[i].type);
fail_unless(! strcasecmp(SDB_OBJ(obj)->name, expected_name),
- "sdb_store_get_<%s>(%s, %s) returned object named '%s'; "
+ "sdb_memstore_get_<%s>(%s, %s) returned object named '%s'; "
"expected: '%s'", SDB_STORE_TYPE_TO_NAME(golden_data[i].type),
golden_data[i].host, golden_data[i].name, SDB_OBJ(obj)->name,
expected_name);
START_TEST(test_interval)
{
- sdb_store_obj_t *host;
+ sdb_memstore_obj_t *host;
/* 10 us interval */
- sdb_store_host(store, "host", 10);
- sdb_store_host(store, "host", 20);
- sdb_store_host(store, "host", 30);
- sdb_store_host(store, "host", 40);
+ sdb_memstore_host(store, "host", 10);
+ sdb_memstore_host(store, "host", 20);
+ sdb_memstore_host(store, "host", 30);
+ sdb_memstore_host(store, "host", 40);
- host = sdb_store_get_host(store, "host");
+ host = sdb_memstore_get_host(store, "host");
fail_unless(host != NULL,
"INTERNAL ERROR: store doesn't have host after adding it");
fail_unless(host->interval == 10,
- "sdb_store_host() did not calculate interval correctly: "
+ "sdb_memstore_host() did not calculate interval correctly: "
"got: %"PRIsdbTIME"; expected: %"PRIsdbTIME, host->interval, 10);
/* multiple updates for the same timestamp don't modify the interval */
- sdb_store_host(store, "host", 40);
- sdb_store_host(store, "host", 40);
- sdb_store_host(store, "host", 40);
- sdb_store_host(store, "host", 40);
+ sdb_memstore_host(store, "host", 40);
+ sdb_memstore_host(store, "host", 40);
+ sdb_memstore_host(store, "host", 40);
+ sdb_memstore_host(store, "host", 40);
fail_unless(host->interval == 10,
- "sdb_store_host() changed interval when doing multiple updates "
+ "sdb_memstore_host() changed interval when doing multiple updates "
"using the same timestamp; got: %"PRIsdbTIME"; "
"expected: %"PRIsdbTIME, host->interval, 10);
/* multiple updates using an timestamp don't modify the interval */
- sdb_store_host(store, "host", 20);
- sdb_store_host(store, "host", 20);
- sdb_store_host(store, "host", 20);
- sdb_store_host(store, "host", 20);
+ sdb_memstore_host(store, "host", 20);
+ sdb_memstore_host(store, "host", 20);
+ sdb_memstore_host(store, "host", 20);
+ sdb_memstore_host(store, "host", 20);
fail_unless(host->interval == 10,
- "sdb_store_host() changed interval when doing multiple updates "
+ "sdb_memstore_host() changed interval when doing multiple updates "
"using an old timestamp; got: %"PRIsdbTIME"; expected: %"PRIsdbTIME,
host->interval, 10);
/* new interval: 20 us */
- sdb_store_host(store, "host", 60);
+ sdb_memstore_host(store, "host", 60);
fail_unless(host->interval == 11,
- "sdb_store_host() did not calculate interval correctly: "
+ "sdb_memstore_host() did not calculate interval correctly: "
"got: %"PRIsdbTIME"; expected: %"PRIsdbTIME, host->interval, 11);
/* new interval: 40 us */
- sdb_store_host(store, "host", 100);
+ sdb_memstore_host(store, "host", 100);
fail_unless(host->interval == 13,
- "sdb_store_host() did not calculate interval correctly: "
+ "sdb_memstore_host() did not calculate interval correctly: "
"got: %"PRIsdbTIME"; expected: %"PRIsdbTIME, host->interval, 11);
sdb_object_deref(SDB_OBJ(host));
END_TEST
static int
-scan_count(sdb_store_obj_t *obj, sdb_store_matcher_t *filter, void *user_data)
+scan_count(sdb_memstore_obj_t *obj, sdb_memstore_matcher_t *filter, void *user_data)
{
intptr_t *i = user_data;
- if (! sdb_store_matcher_matches(filter, obj, NULL))
+ if (! sdb_memstore_matcher_matches(filter, obj, NULL))
return 0;
fail_unless(obj != NULL,
- "sdb_store_scan callback received NULL obj; expected: "
+ "sdb_memstore_scan callback received NULL obj; expected: "
"<store base obj>");
fail_unless(i != NULL,
- "sdb_store_scan callback received NULL user_data; "
+ "sdb_memstore_scan callback received NULL user_data; "
"expected: <pointer to data>");
++(*i);
@@ -705,18 +705,18 @@ scan_count(sdb_store_obj_t *obj, sdb_store_matcher_t *filter, void *user_data)
} /* scan_count */
static int
-scan_error(sdb_store_obj_t *obj, sdb_store_matcher_t *filter, void *user_data)
+scan_error(sdb_memstore_obj_t *obj, sdb_memstore_matcher_t *filter, void *user_data)
{
intptr_t *i = user_data;
- if (! sdb_store_matcher_matches(filter, obj, NULL))
+ if (! sdb_memstore_matcher_matches(filter, obj, NULL))
return 0;
fail_unless(obj != NULL,
- "sdb_store_scan callback received NULL obj; expected: "
+ "sdb_memstore_scan callback received NULL obj; expected: "
"<store base obj>");
fail_unless(i != NULL,
- "sdb_store_scan callback received NULL user_data; "
+ "sdb_memstore_scan callback received NULL user_data; "
"expected: <pointer to data>");
++(*i);
int check;
/* empty store */
- check = sdb_store_scan(store, SDB_HOST, /* m, filter = */ NULL, NULL,
+ check = sdb_memstore_scan(store, SDB_HOST, /* m, filter = */ NULL, NULL,
scan_count, &i);
fail_unless(check == 0,
- "sdb_store_scan(HOST), empty store = %d; expected: 0", check);
+ "sdb_memstore_scan(HOST), empty store = %d; expected: 0", check);
fail_unless(i == 0,
- "sdb_store_scan(HOST) called callback %d times; "
+ "sdb_memstore_scan(HOST) called callback %d times; "
"expected: 0", (int)i);
populate();
- check = sdb_store_scan(store, SDB_HOST, /* m, filter = */ NULL, NULL,
+ check = sdb_memstore_scan(store, SDB_HOST, /* m, filter = */ NULL, NULL,
scan_count, &i);
fail_unless(check == 0,
- "sdb_store_scan(HOST) = %d; expected: 0", check);
+ "sdb_memstore_scan(HOST) = %d; expected: 0", check);
fail_unless(i == 2,
- "sdb_store_scan(HOST) called callback %d times; "
+ "sdb_memstore_scan(HOST) called callback %d times; "
"expected: 1", (int)i);
i = 0;
- check = sdb_store_scan(store, SDB_HOST, /* m, filter = */ NULL, NULL,
+ check = sdb_memstore_scan(store, SDB_HOST, /* m, filter = */ NULL, NULL,
scan_error, &i);
fail_unless(check == -1,
- "sdb_store_scan(HOST), error callback = %d; expected: -1", check);
+ "sdb_memstore_scan(HOST), error callback = %d; expected: -1", check);
fail_unless(i == 1,
- "sdb_store_scan(HOST) called callback %d times "
+ "sdb_memstore_scan(HOST) called callback %d times "
"(callback returned error); expected: 1", (int)i);
i = 0;
- check = sdb_store_scan(store, SDB_SERVICE, /* m, filter = */ NULL, NULL,
+ check = sdb_memstore_scan(store, SDB_SERVICE, /* m, filter = */ NULL, NULL,
scan_count, &i);
fail_unless(check == 0,
- "sdb_store_scan(SERVICE) = %d; expected: 0", check);
+ "sdb_memstore_scan(SERVICE) = %d; expected: 0", check);
fail_unless(i == 2,
- "sdb_store_scan(SERVICE) called callback %d times; "
+ "sdb_memstore_scan(SERVICE) called callback %d times; "
"expected: 2", (int)i);
i = 0;
- check = sdb_store_scan(store, SDB_METRIC, /* m, filter = */ NULL, NULL,
+ check = sdb_memstore_scan(store, SDB_METRIC, /* m, filter = */ NULL, NULL,
scan_count, &i);
fail_unless(check == 0,
- "sdb_store_scan(METRIC) = %d; expected: 0", check);
+ "sdb_memstore_scan(METRIC) = %d; expected: 0", check);
fail_unless(i == 3,
- "sdb_store_scan(METRIC) called callback %d times; "
+ "sdb_memstore_scan(METRIC) called callback %d times; "
"expected: 3", (int)i);
}
END_TEST
index de8ab806843a34be4942f78939864dc275d06f1c..d498ea0231208bca6178e7d2da469e169247830b 100644 (file)
static void
populate(void)
{
- sdb_store_t *store;
+ sdb_memstore_t *store;
sdb_data_t datum;
/* the frontend accesses the store via the plugin API */
- store = sdb_store_create();
+ store = sdb_memstore_create();
ck_assert(store != NULL);
ck_assert(sdb_plugin_register_writer("test-writer",
- &sdb_store_writer, SDB_OBJ(store)) == 0);
+ &sdb_memstore_writer, SDB_OBJ(store)) == 0);
ck_assert(sdb_plugin_register_reader("test-reader",
- &sdb_store_reader, SDB_OBJ(store)) == 0);
+ &sdb_memstore_reader, SDB_OBJ(store)) == 0);
sdb_object_deref(SDB_OBJ(store));
/* populate the store */
index 8da4ef0cc722a639e178d9714c89fa0ee16b0395..83a5845a87f614e109f72d2f268574356a83e0c9 100644 (file)
sdb_strbuf_t *errbuf = sdb_strbuf_create(64);
sdb_llist_t *check;
sdb_ast_node_t *node;
- sdb_store_query_t *q;
+ sdb_memstore_query_t *q;
_Bool ok;
check = sdb_parser_parse(parse_data[_i].query,
}
/* TODO: this should move into front-end specific tests */
- q = sdb_store_query_prepare(node);
+ q = sdb_memstore_query_prepare(node);
fail_unless(q != NULL,
"sdb_store_query_prepare(AST<%s>) = NULL; expected: <query>",
parse_data[_i].query);