From: Sebastian Harl Date: Wed, 7 Oct 2015 20:25:29 +0000 (+0200) Subject: Renamed in-memory store types and functions to sdb_memstore*. X-Git-Tag: sysdb-0.8.0~10^2~6 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=b54d9fff4bc9e70efe83123403a4c9f935efb74e;p=sysdb.git Renamed in-memory store types and functions to sdb_memstore*. --- diff --git a/src/core/store-private.h b/src/core/store-private.h index e851487..2f9d96c 100644 --- a/src/core/store-private.h +++ b/src/core/store-private.h @@ -26,7 +26,7 @@ */ /* - * private data structures used by the store module + * private data structures used by the memstore module */ #ifndef SDB_CORE_STORE_PRIVATE_H @@ -46,7 +46,7 @@ extern "C" { * core types */ -struct sdb_store_obj { +struct sdb_memstore_obj { sdb_object_t super; #define _name super.name @@ -58,13 +58,13 @@ struct sdb_store_obj { 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; @@ -72,7 +72,7 @@ typedef struct { #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; @@ -80,18 +80,18 @@ typedef struct { #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; @@ -108,13 +108,13 @@ typedef struct { * 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 @@ -128,14 +128,14 @@ enum { /* >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; }; @@ -203,53 +203,53 @@ enum { : "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 fa72955..7fc11e1 100644 --- a/src/core/store.c +++ b/src/core/store.c @@ -49,7 +49,7 @@ * private types */ -struct sdb_store { +struct sdb_memstore { sdb_object_t super; /* hosts are the top-level entries and @@ -60,7 +60,7 @@ struct sdb_store { /* 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; @@ -79,9 +79,9 @@ static int 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", @@ -95,20 +95,20 @@ static void 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); @@ -123,7 +123,7 @@ store_obj_init(sdb_object_t *obj, va_list ap) 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) @@ -209,7 +209,7 @@ service_destroy(sdb_object_t *obj) 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 */ @@ -228,7 +228,7 @@ metric_init(sdb_object_t *obj, va_list 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); @@ -271,7 +271,7 @@ attr_destroy(sdb_object_t *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, }; @@ -289,7 +289,7 @@ static sdb_type_t service_type = { }; static sdb_type_t metric_type = { - /* size = */ sizeof(sdb_metric_t), + /* size = */ sizeof(metric_t), /* init = */ metric_init, /* destroy = */ metric_destroy }; @@ -305,7 +305,7 @@ static sdb_type_t attribute_type = { */ 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; @@ -340,9 +340,9 @@ record_backends(sdb_store_obj_t *obj, } /* 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); @@ -434,7 +434,7 @@ store_obj(store_obj_t *obj, sdb_store_obj_t **updated_obj) } /* 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; @@ -490,9 +490,9 @@ get_host_children(host_t *host, int type) 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; @@ -574,7 +574,7 @@ store_attribute(sdb_store_attribute_t *attr, sdb_object_t *user_data) 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; @@ -595,7 +595,7 @@ store_host(sdb_store_host_t *host, sdb_object_t *user_data) 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; @@ -630,9 +630,9 @@ store_service(sdb_store_service_t *service, sdb_object_t *user_data) 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; @@ -675,7 +675,7 @@ store_metric(sdb_store_metric_t *metric, sdb_object_t *user_data) 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, }; @@ -684,7 +684,7 @@ prepare_query(sdb_ast_node_t *ast, 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 @@ -692,11 +692,11 @@ execute_query(sdb_object_t *q, 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, }; @@ -704,33 +704,33 @@ sdb_store_reader_t sdb_store_reader = { * 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 = { @@ -741,10 +741,10 @@ sdb_store_metric(sdb_store_t *store, const char *hostname, const char *name, 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 = { @@ -754,10 +754,10 @@ sdb_store_attribute(sdb_store_t *store, const char *hostname, 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) { @@ -768,10 +768,10 @@ sdb_store_service_attr(sdb_store_t *store, const char *hostname, 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) { @@ -782,10 +782,10 @@ sdb_store_metric_attr(sdb_store_t *store, const char *hostname, 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; @@ -797,10 +797,10 @@ sdb_store_get_host(sdb_store_t *store, const char *name) 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; @@ -811,10 +811,10 @@ sdb_store_get_child(sdb_store_obj_t *host, int type, const char *name) 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; @@ -866,14 +866,14 @@ sdb_store_get_field(sdb_store_obj_t *obj, int field, sdb_data_t *res) 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; @@ -891,7 +891,7 @@ sdb_store_get_attr(sdb_store_obj_t *obj, const char *name, sdb_data_t *res, 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; } @@ -901,12 +901,12 @@ sdb_store_get_attr(sdb_store_obj_t *obj, const char *name, sdb_data_t *res, 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; @@ -926,13 +926,13 @@ sdb_store_scan(sdb_store_t *store, int type, /* 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) @@ -942,11 +942,11 @@ sdb_store_scan(sdb_store_t *store, int type, 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"); @@ -956,7 +956,7 @@ sdb_store_scan(sdb_store_t *store, int type, } } } - 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"); @@ -972,7 +972,7 @@ sdb_store_scan(sdb_store_t *store, int type, 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 d4e3088..9b4ea07 100644 --- a/src/core/store_exec.c +++ b/src/core/store_exec.c @@ -43,40 +43,40 @@ */ 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 */ /* @@ -84,13 +84,13 @@ lookup_tojson(sdb_store_obj_t *obj, sdb_store_matcher_t *filter, */ 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; @@ -105,9 +105,9 @@ exec_fetch(sdb_store_t *store, 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); @@ -118,9 +118,9 @@ exec_fetch(sdb_store_t *store, 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); @@ -134,8 +134,8 @@ exec_fetch(sdb_store_t *store, 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); @@ -149,13 +149,13 @@ exec_fetch(sdb_store_t *store, } /* 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"); @@ -166,13 +166,13 @@ exec_list(sdb_store_t *store, } /* 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", @@ -188,7 +188,7 @@ exec_lookup(sdb_store_t *store, */ 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; @@ -222,6 +222,6 @@ sdb_store_query_execute(sdb_store_t *store, sdb_store_query_t *q, } 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 6405002..c96b339 100644 --- a/src/core/store_expr.c +++ b/src/core/store_expr.c @@ -48,9 +48,9 @@ */ /* 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; @@ -58,7 +58,7 @@ struct sdb_store_expr_iter { size_t array_idx; bool free_array; - sdb_store_matcher_t *filter; + sdb_memstore_matcher_t *filter; }; /* @@ -69,11 +69,11 @@ static int 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) @@ -105,7 +105,7 @@ expr_init(sdb_object_t *obj, va_list ap) 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)); @@ -114,7 +114,7 @@ expr_destroy(sdb_object_t *obj) } /* 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, }; @@ -123,17 +123,17 @@ static sdb_type_t expr_type = { * 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; @@ -219,15 +219,15 @@ sdb_store_expr_eval(sdb_store_expr_t *expr, sdb_store_obj_t *obj, 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; @@ -246,12 +246,12 @@ sdb_store_expr_eval(sdb_store_expr_t *expr, sdb_store_obj_t *obj, 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; } @@ -261,13 +261,13 @@ sdb_store_expr_eval(sdb_store_expr_t *expr, sdb_store_obj_t *obj, 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; @@ -329,7 +329,7 @@ sdb_store_expr_iter(sdb_store_expr_t *expr, sdb_store_obj_t *obj, } 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); @@ -360,10 +360,10 @@ sdb_store_expr_iter(sdb_store_expr_t *expr, sdb_store_obj_t *obj, 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; @@ -383,10 +383,10 @@ sdb_store_expr_iter_destroy(sdb_store_expr_iter_t *iter) 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; @@ -395,9 +395,9 @@ sdb_store_expr_iter_has_next(sdb_store_expr_iter_t *iter) /* 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); } @@ -407,10 +407,10 @@ sdb_store_expr_iter_has_next(sdb_store_expr_iter_t *iter) } 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; @@ -420,17 +420,17 @@ sdb_store_expr_iter_get_next(sdb_store_expr_iter_t *iter) 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; } @@ -438,7 +438,7 @@ sdb_store_expr_iter_get_next(sdb_store_expr_iter_t *iter) /* 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); } @@ -457,7 +457,7 @@ sdb_store_expr_iter_get_next(sdb_store_expr_iter_t *iter) 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 961e54c..b39ff21 100644 --- a/src/core/store_json.c +++ b/src/core/store_json.c @@ -382,7 +382,7 @@ sdb_store_json_formatter(sdb_strbuf_t *buf, int type, int flags) /* 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; @@ -456,16 +456,16 @@ sdb_store_emit(sdb_store_obj_t *obj, sdb_store_writer_t *w, sdb_object_t *wd) } 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) { @@ -490,13 +490,13 @@ sdb_store_emit_full(sdb_store_obj_t *obj, sdb_store_matcher_t *filter, 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; } @@ -504,7 +504,7 @@ sdb_store_emit_full(sdb_store_obj_t *obj, sdb_store_matcher_t *filter, 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) diff --git a/src/core/store_lookup.c b/src/core/store_lookup.c index 06151a8..b69e7f9 100644 --- a/src/core/store_lookup.c +++ b/src/core/store_lookup.c @@ -51,18 +51,18 @@ #include 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; @@ -74,8 +74,8 @@ expr_eval2(sdb_store_expr_t *e1, sdb_data_t *v1, } /* 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); @@ -154,15 +154,15 @@ match_regex_value(int op, sdb_data_t *v, sdb_data_t *re) } /* 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)) @@ -170,45 +170,45 @@ match_logical(sdb_store_matcher_t *m, sdb_store_obj_t *obj, 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 */ 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); @@ -222,16 +222,16 @@ match_iter(sdb_store_matcher_t *m, sdb_store_obj_t *obj, 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; @@ -254,8 +254,8 @@ match_cmp(sdb_store_matcher_t *m, sdb_store_obj_t *obj, } /* 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; @@ -275,8 +275,8 @@ match_in(sdb_store_matcher_t *m, sdb_store_obj_t *obj, } /* 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; @@ -295,8 +295,8 @@ match_regex(sdb_store_matcher_t *m, sdb_store_obj_t *obj, } /* 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; @@ -308,7 +308,7 @@ match_unary(sdb_store_matcher_t *m, sdb_store_obj_t *obj, 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 @@ -329,8 +329,8 @@ match_unary(sdb_store_matcher_t *m, sdb_store_obj_t *obj, 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 */ @@ -372,9 +372,9 @@ op_matcher_init(sdb_object_t *obj, va_list ap) 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)) @@ -395,8 +395,8 @@ static int 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)); @@ -418,9 +418,9 @@ cmp_matcher_init(sdb_object_t *obj, va_list ap) { 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) @@ -442,7 +442,7 @@ uop_matcher_init(sdb_object_t *obj, va_list ap) 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) @@ -466,7 +466,7 @@ unary_matcher_init(sdb_object_t *obj, va_list ap) && (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 */ @@ -512,8 +512,8 @@ static sdb_type_t unary_type = { * 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 " @@ -530,10 +530,10 @@ sdb_store_any_matcher(sdb_store_expr_t *iter, sdb_store_matcher_t *m) } 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 " @@ -550,59 +550,59 @@ sdb_store_all_matcher(sdb_store_expr_t *iter, sdb_store_matcher_t *m) } 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) @@ -618,64 +618,64 @@ sdb_store_regex_matcher(sdb_store_expr_t *left, sdb_store_expr_t *right) } 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 */ @@ -688,7 +688,7 @@ sdb_store_matcher_matches(sdb_store_matcher_t *m, sdb_store_obj_t *obj, 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 ff7089c..341cb16 100644 --- a/src/core/store_query.c +++ b/src/core/store_query.c @@ -32,14 +32,14 @@ #include -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) { @@ -64,22 +64,22 @@ node_to_expr(sdb_ast_node_t *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: @@ -94,11 +94,11 @@ node_to_expr(sdb_ast_node_t *n) 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); @@ -113,13 +113,13 @@ logical_to_matcher(sdb_ast_node_t *n) 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: @@ -132,11 +132,11 @@ logical_to_matcher(sdb_ast_node_t *n) 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); @@ -151,40 +151,40 @@ cmp_to_matcher(sdb_ast_node_t *n) 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: @@ -199,11 +199,11 @@ cmp_to_matcher(sdb_ast_node_t *n) 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)); @@ -219,10 +219,10 @@ iter_to_matcher(sdb_ast_node_t *n) 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: @@ -237,7 +237,7 @@ iter_to_matcher(sdb_ast_node_t *n) 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; @@ -328,7 +328,7 @@ query_destroy(sdb_object_t *obj) } /* 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, }; @@ -337,18 +337,18 @@ static sdb_type_t query_type = { * 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 : */ diff --git a/src/include/core/store.h b/src/include/core/store.h index 818297f..03677e8 100644 --- a/src/include/core/store.h +++ b/src/include/core/store.h @@ -95,20 +95,20 @@ enum { : -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. @@ -187,15 +187,15 @@ typedef struct { * 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 @@ -206,9 +206,9 @@ typedef struct sdb_store_expr_iter sdb_store_expr_iter_t; * 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. @@ -271,11 +271,11 @@ typedef struct { } 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. @@ -301,57 +301,57 @@ typedef struct { } 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 @@ -361,11 +361,11 @@ sdb_store_get_host(sdb_store_t *store, const char *name); * - 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 @@ -376,10 +376,10 @@ sdb_store_get_child(sdb_store_obj_t *host, int type, const char *name); * - 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 @@ -391,8 +391,8 @@ sdb_store_get_field(sdb_store_obj_t *obj, int field, sdb_data_t *res); * - 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: @@ -408,25 +408,25 @@ sdb_store_get_attr(sdb_store_obj_t *obj, const char *name, sdb_data_t *res, */ /* - * 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. * @@ -434,11 +434,11 @@ sdb_store_query_prepare(sdb_ast_node_t *ast); * - 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'. * @@ -447,11 +447,11 @@ sdb_store_query_prepare_matcher(sdb_ast_node_t *ast); * - 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. * @@ -459,11 +459,12 @@ sdb_store_query_execute(sdb_store_t *store, sdb_store_query_t *m, * - 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. * @@ -483,11 +484,11 @@ sdb_store_expr_typed(int typ, sdb_store_expr_t *expr); * - 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. @@ -496,22 +497,22 @@ sdb_store_expr_fieldvalue(int field); * - 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 @@ -524,133 +525,133 @@ sdb_store_expr_constvalue(const sdb_data_t *value); * - 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 @@ -665,41 +666,41 @@ sdb_store_isfalse_matcher(sdb_store_expr_t *expr); * - 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. @@ -717,12 +718,12 @@ sdb_store_json_formatter_t * 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(). @@ -732,10 +733,10 @@ sdb_store_json_formatter(sdb_strbuf_t *buf, int type, int flags); * - 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. @@ -749,7 +750,7 @@ sdb_store_emit(sdb_store_obj_t *obj, sdb_store_writer_t *w, sdb_object_t *wd); * - 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); /* diff --git a/src/plugins/store/memory.c b/src/plugins/store/memory.c index 3cbc1e8..67a795b 100644 --- a/src/plugins/store/memory.c +++ b/src/plugins/store/memory.c @@ -43,19 +43,19 @@ SDB_PLUGIN_MAGIC; 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; } @@ -73,7 +73,7 @@ int 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, @@ -83,7 +83,7 @@ sdb_module_init(sdb_plugin_info_t *info) 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; diff --git a/t/unit/core/store_expr_test.c b/t/unit/core/store_expr_test.c index 3f21a82..04dfc8b 100644 --- a/t/unit/core/store_expr_test.c +++ b/t/unit/core/store_expr_test.c @@ -36,7 +36,7 @@ #include -static sdb_store_t *store; +static sdb_memstore_t *store; static void populate(void) @@ -94,41 +94,41 @@ 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); @@ -151,7 +151,7 @@ turndown(void) #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 }; @@ -163,7 +163,7 @@ static struct { 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; @@ -555,19 +555,19 @@ struct { 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)); @@ -580,14 +580,14 @@ START_TEST(test_expr_iter) 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) : "", expr_iter_data[_i].filter, iter ? "" : "NULL", @@ -598,7 +598,7 @@ START_TEST(test_expr_iter) 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; @@ -608,7 +608,7 @@ START_TEST(test_expr_iter) 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); @@ -627,12 +627,12 @@ START_TEST(test_expr_iter) "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 diff --git a/t/unit/core/store_json_test.c b/t/unit/core/store_json_test.c index b880f7b..40548c0 100644 --- a/t/unit/core/store_json_test.c +++ b/t/unit/core/store_json_test.c @@ -39,54 +39,54 @@ #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 */ @@ -98,18 +98,18 @@ turndown(void) } /* 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 @@ -140,12 +140,12 @@ verify_json_output(sdb_strbuf_t *buf, const char *expected) 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 }, @@ -212,14 +212,14 @@ struct { "{\"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, "[" @@ -236,7 +236,7 @@ struct { "]}" "]}" "]" }, - { { 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, "[" @@ -254,14 +254,14 @@ struct { "\"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, "[]" }, @@ -294,7 +294,7 @@ struct { "\"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, "[" @@ -307,7 +307,7 @@ struct { "\"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, "[]" }, @@ -348,7 +348,7 @@ struct { "\"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, "[" @@ -357,7 +357,7 @@ struct { "\"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, "[]" }, @@ -366,24 +366,24 @@ struct { 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)); @@ -393,10 +393,10 @@ START_TEST(test_store_tojson) 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); diff --git a/t/unit/core/store_lookup_test.c b/t/unit/core/store_lookup_test.c index d2c0064..ef0900e 100644 --- a/t/unit/core/store_lookup_test.c +++ b/t/unit/core/store_lookup_test.c @@ -38,7 +38,7 @@ #include #include -static sdb_store_t *store; +static sdb_memstore_t *store; static void populate(void) @@ -76,37 +76,37 @@ 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, , 1) = %d; expected: 0", + "sdb_memstore_attribute(%s, %s, , 1) = %d; expected: 0", attrs[i].host, attrs[i].name, status); } } /* populate */ @@ -161,41 +161,41 @@ struct { 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: "); + "sdb_memstore_get_host(a) = NULL; expected: "); 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: "); } - 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: ", 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)); @@ -204,27 +204,27 @@ START_TEST(test_cmp_name) 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: ", 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, , NULL) = %d; " + "sdb_memstore_matcher_matches(%s->%s, , 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: "); + "sdb_memstore_inv_matcher() = NULL; expected: "); 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, , NULL) = %d; " + "sdb_memstore_matcher_matches(%s->%s, , 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); @@ -256,55 +256,55 @@ struct { 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: "); + "sdb_memstore_get_host(a) = NULL; expected: "); 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: ", + "sdb_memstore_expr_attrvalue(%s) = NULL; expected: ", 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: ", + "sdb_memstore_expr_constvalue(%s) = NULL; expected: ", 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__matcher() = NULL; expected: "); + "sdb_memstore__matcher() = NULL; expected: "); - 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(, " + "sdb_memstore_matcher_matches(, " ", NULL) = %d; expected: %d", cmp_attr_data[_i].attr, op_str[j], value_str, status, tests[j].expected); @@ -364,49 +364,49 @@ struct { 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: ", + "sdb_memstore_get_host(%s) = NULL; expected: ", 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: ", 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: ", 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), @@ -414,11 +414,11 @@ START_TEST(test_cmp_obj) m = tests[j].matcher(field, value); fail_unless(m != NULL, - "sdb_store__matcher() = NULL; expected: "); + "sdb_memstore__matcher() = NULL; expected: "); - 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>, , NULL) = %d; " + "sdb_memstore_matcher_matches(<%s>, , NULL) = %d; " "expected: %d", m_str, cmp_obj_data[_i].host, status, tests[j].expected); @@ -433,18 +433,18 @@ END_TEST 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 }, @@ -460,23 +460,23 @@ START_TEST(test_store_match_op) 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); @@ -486,7 +486,7 @@ START_TEST(test_store_match_op) #define TO_NAME(v) (((v) == always) ? "always" \ : ((v) == never) ? "never" : "") - 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), @@ -506,18 +506,18 @@ START_TEST(test_store_match_op) 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: " ""); fail_unless(i != NULL, - "sdb_store_scan callback received NULL user_data; " + "sdb_memstore_scan callback received NULL user_data; " "expected: "); ++(*i); @@ -628,21 +628,21 @@ struct { 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: " @@ -651,7 +651,7 @@ START_TEST(test_scan) 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; " @@ -660,9 +660,9 @@ START_TEST(test_scan) } 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); diff --git a/t/unit/core/store_test.c b/t/unit/core/store_test.c index 1d524b6..5299a31 100644 --- a/t/unit/core/store_test.c +++ b/t/unit/core/store_test.c @@ -38,12 +38,12 @@ #include #include -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); } @@ -52,41 +52,41 @@ populate(void) { 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 @@ -127,20 +127,20 @@ START_TEST(test_store_host) 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 ? "" : "NULL"); sdb_object_deref(SDB_OBJ(have)); @@ -155,36 +155,36 @@ START_TEST(test_store_get_host) 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: ", + "sdb_memstore_get_host(%s) = NULL; expected: ", 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: ", + "sdb_memstore_get_host(%s) = NULL; expected: ", 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); @@ -192,10 +192,10 @@ START_TEST(test_store_get_host) 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) = ; expected: NULL", + sobj = sdb_memstore_get_host(store, unknown_hosts[i]); + fail_unless(!sobj, "sdb_memstore_get_host(%s) = ; expected: NULL", unknown_hosts[i], sobj ? SDB_OBJ(sobj)->name : "NULL"); } } @@ -222,8 +222,8 @@ START_TEST(test_store_attr) 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; @@ -232,11 +232,11 @@ START_TEST(test_store_attr) 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); } @@ -275,16 +275,16 @@ START_TEST(test_store_metric) 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); @@ -319,20 +319,20 @@ START_TEST(test_store_metric_attr) 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); @@ -360,15 +360,15 @@ START_TEST(test_store_service) 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); } @@ -402,20 +402,20 @@ START_TEST(test_store_service_attr) 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); @@ -471,37 +471,37 @@ static struct { (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, ) = %d; expected: %d", + "sdb_memstore_get_field(%s %s, %s, ) = %d; expected: %d", OBJ_NAME(obj), SDB_FIELD_TO_NAME(get_field_data[_i].field), check, get_field_data[_i].expected); @@ -522,14 +522,14 @@ START_TEST(test_get_field) 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, ) " + "sdb_memstore_get_field(%s %s, %s, ) " "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, ) " + "sdb_memstore_get_field(%s %s, %s, ) " "returned value %s; expected %s", OBJ_NAME(obj), SDB_FIELD_TO_NAME(get_field_data[_i].field), value_str, expected_value_str); @@ -573,35 +573,35 @@ START_TEST(test_get_child) 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: ", + "sdb_memstore_get_host(%s) = NULL; expected: ", 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: ", golden_data[i].host, SDB_STORE_TYPE_TO_NAME(golden_data[i].type), golden_data[i].name); @@ -614,12 +614,12 @@ START_TEST(test_get_child) 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); @@ -631,54 +631,54 @@ END_TEST 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)); @@ -686,18 +686,18 @@ START_TEST(test_interval) 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: " ""); fail_unless(i != NULL, - "sdb_store_scan callback received NULL user_data; " + "sdb_memstore_scan callback received NULL user_data; " "expected: "); ++(*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: " ""); fail_unless(i != NULL, - "sdb_store_scan callback received NULL user_data; " + "sdb_memstore_scan callback received NULL user_data; " "expected: "); ++(*i); @@ -729,49 +729,49 @@ START_TEST(test_scan) 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 diff --git a/t/unit/frontend/query_test.c b/t/unit/frontend/query_test.c index de8ab80..d498ea0 100644 --- a/t/unit/frontend/query_test.c +++ b/t/unit/frontend/query_test.c @@ -43,16 +43,16 @@ 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 */ diff --git a/t/unit/parser/parser_test.c b/t/unit/parser/parser_test.c index 8da4ef0..83a5845 100644 --- a/t/unit/parser/parser_test.c +++ b/t/unit/parser/parser_test.c @@ -678,7 +678,7 @@ START_TEST(test_parse) 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, @@ -741,7 +741,7 @@ START_TEST(test_parse) } /* 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: ", parse_data[_i].query);