summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 637fd92)
raw | patch | inline | side by side (parent: 637fd92)
author | Sebastian Harl <sh@tokkee.org> | |
Tue, 13 Oct 2015 19:24:17 +0000 (21:24 +0200) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Tue, 13 Oct 2015 19:24:17 +0000 (21:24 +0200) |
For this purpose, let the sdb_plugin_store_* functions fetch the latest
revision of the object to determine the last update interval and last
recorded interval. The memstore now expects both values to be passed in
whenever storing/updating an object.
revision of the object to determine the last update interval and last
recorded interval. The memstore now expects both values to be passed in
whenever storing/updating an object.
diff --git a/src/core/memstore.c b/src/core/memstore.c
index 15c4202829159eee3665b74f7d1654b010d8b602..244982777cfb38fc82b5b99e8e8cf1c645e56b91 100644 (file)
--- a/src/core/memstore.c
+++ b/src/core/memstore.c
int type;
const char *name;
sdb_time_t last_update;
+ sdb_time_t interval;
const char * const *backends;
size_t backends_num;
} store_obj_t;
-#define STORE_OBJ_INIT { NULL, NULL, 0, NULL, 0, NULL, 0 }
+#define STORE_OBJ_INIT { NULL, NULL, 0, NULL, 0, 0, NULL, 0 }
static sdb_type_t host_type;
static sdb_type_t service_type;
store_obj_init(sdb_object_t *obj, va_list ap)
{
sdb_memstore_obj_t *sobj = STORE_OBJ(obj);
-
sobj->type = va_arg(ap, int);
-
- sobj->last_update = va_arg(ap, sdb_time_t);
- sobj->interval = 0;
- sobj->backends = NULL;
- sobj->backends_num = 0;
- sobj->parent = NULL;
return 0;
} /* store_obj_init */
const sdb_data_t *value;
int ret;
- /* this will consume the first two arguments
- * (type and last_update) of ap */
+ /* this will consume the first argument (type) of ap */
ret = store_obj_init(obj, ap);
if (ret)
return ret;
assert(obj->parent_tree);
- if (obj->last_update <= 0)
- obj->last_update = sdb_gettime();
-
old = STORE_OBJ(sdb_avltree_lookup(obj->parent_tree, obj->name));
if (old) {
- if (old->last_update > obj->last_update) {
- sdb_log(SDB_LOG_DEBUG, "memstore: Cannot update %s '%s' - "
- "value too old (%"PRIsdbTIME" < %"PRIsdbTIME")",
- SDB_STORE_TYPE_TO_NAME(obj->type), obj->name,
- obj->last_update, old->last_update);
- /* don't report an error; the object may be updated by multiple
- * backends */
- status = 1;
- }
- else if (old->last_update == obj->last_update) {
- /* don't report an error and also don't even log this to avoid
- * excessive noise on high sampling frequencies */
- status = 1;
- }
- else {
- sdb_time_t interval = obj->last_update - old->last_update;
- old->last_update = obj->last_update;
- if (interval) {
- if (old->interval)
- old->interval = (sdb_time_t)((0.9 * (double)old->interval)
- + (0.1 * (double)interval));
- else
- old->interval = interval;
- }
- }
-
new = old;
sdb_object_deref(SDB_OBJ(old));
}
if (obj->type == SDB_ATTRIBUTE) {
/* the value will be updated by the caller */
new = STORE_OBJ(sdb_object_create(obj->name, attribute_type,
- obj->type, obj->last_update, NULL));
+ obj->type, NULL));
}
else {
sdb_type_t t;
: obj->type == SDB_SERVICE
? service_type
: metric_type;
- new = STORE_OBJ(sdb_object_create(obj->name, t,
- obj->type, obj->last_update));
+ new = STORE_OBJ(sdb_object_create(obj->name, t, obj->type));
}
if (new) {
return status;
assert(new);
+ new->last_update = obj->last_update;
+ new->interval = obj->interval;
+
if (new->parent != obj->parent) {
// Avoid circular self-references which are not handled
// correctly by the ref-count based management layer.
obj.type = SDB_ATTRIBUTE;
obj.name = attr->key;
obj.last_update = attr->last_update;
+ obj.interval = attr->interval;
obj.backends = attr->backends;
obj.backends_num = attr->backends_num;
if (! status)
store_host(sdb_store_host_t *host, sdb_object_t *user_data)
{
sdb_memstore_t *st = SDB_MEMSTORE(user_data);
- store_obj_t obj = { NULL, st->hosts, SDB_HOST, NULL, 0, NULL, 0 };
+ store_obj_t obj = { NULL, st->hosts, SDB_HOST, NULL, 0, 0, NULL, 0 };
int status = 0;
if ((! host) || (! host->name))
obj.name = host->name;
obj.last_update = host->last_update;
+ obj.interval = host->interval;
obj.backends = host->backends;
obj.backends_num = host->backends_num;
pthread_rwlock_wrlock(&st->host_lock);
obj.name = service->name;
obj.last_update = service->last_update;
+ obj.interval = service->interval;
obj.backends = service->backends;
obj.backends_num = service->backends_num;
if (! status)
obj.name = metric->name;
obj.last_update = metric->last_update;
+ obj.interval = metric->interval;
obj.backends = metric->backends;
obj.backends_num = metric->backends_num;
if (! status)
} /* sdb_memstore_create */
int
-sdb_memstore_host(sdb_memstore_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_time_t interval)
{
sdb_store_host_t host = {
- name, last_update, 0, NULL, 0,
+ name, last_update, interval, NULL, 0,
};
return store_host(&host, SDB_OBJ(store));
} /* sdb_memstore_host */
int
sdb_memstore_service(sdb_memstore_t *store, const char *hostname, const char *name,
- sdb_time_t last_update)
+ sdb_time_t last_update, sdb_time_t interval)
{
sdb_store_service_t service = {
- hostname, name, last_update, 0, NULL, 0,
+ hostname, name, last_update, interval, NULL, 0,
};
return store_service(&service, SDB_OBJ(store));
} /* sdb_memstore_service */
int
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_metric_store_t *metric_store,
+ sdb_time_t last_update, sdb_time_t interval)
{
sdb_store_metric_t metric = {
- hostname, name, { NULL, NULL }, last_update, 0, NULL, 0,
+ hostname, name, { NULL, NULL }, last_update, interval, NULL, 0,
};
if (metric_store) {
metric.store.type = metric_store->type;
@@ -759,10 +731,12 @@ sdb_memstore_metric(sdb_memstore_t *store, const char *hostname, const char *nam
int
sdb_memstore_attribute(sdb_memstore_t *store, const char *hostname,
- const char *key, const sdb_data_t *value, sdb_time_t last_update)
+ const char *key, const sdb_data_t *value,
+ sdb_time_t last_update, sdb_time_t interval)
{
sdb_store_attribute_t attr = {
- NULL, SDB_HOST, hostname, key, SDB_DATA_INIT, last_update, 0, NULL, 0,
+ NULL, SDB_HOST, hostname, key, SDB_DATA_INIT,
+ last_update, interval, NULL, 0,
};
if (value) {
attr.value = *value;
int
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)
+ sdb_time_t last_update, sdb_time_t interval)
{
sdb_store_attribute_t attr = {
- hostname, SDB_SERVICE, service, key, SDB_DATA_INIT, last_update, 0, NULL, 0,
+ hostname, SDB_SERVICE, service, key, SDB_DATA_INIT,
+ last_update, interval, NULL, 0,
};
if (value) {
attr.value = *value;
int
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_time_t last_update, sdb_time_t interval)
{
sdb_store_attribute_t attr = {
- hostname, SDB_METRIC, metric, key, SDB_DATA_INIT, last_update, 0, NULL, 0,
+ hostname, SDB_METRIC, metric, key, SDB_DATA_INIT,
+ last_update, interval, NULL, 0,
};
if (value) {
attr.value = *value;
diff --git a/src/core/plugin.c b/src/core/plugin.c
index 728e20c1740815d83b2d1366ac852b20ec19c140..76b0b1e45b656a6416bb8aa526581cd311ac5921 100644 (file)
--- a/src/core/plugin.c
+++ b/src/core/plugin.c
return 0;
} /* plugin_add_callback */
+/*
+ * object meta-data
+ */
+
+typedef struct {
+ int obj_type;
+ sdb_time_t last_update;
+ sdb_time_t interval;
+} interval_fetcher_t;
+
+static int
+interval_fetcher_host(sdb_store_host_t *host, sdb_object_t *user_data)
+{
+ interval_fetcher_t *lu = SDB_OBJ_WRAPPER(user_data)->data;
+ lu->obj_type = SDB_HOST;
+ lu->last_update = host->last_update;
+ return 0;
+} /* interval_fetcher_host */
+
+static int
+interval_fetcher_service(sdb_store_service_t *svc, sdb_object_t *user_data)
+{
+ interval_fetcher_t *lu = SDB_OBJ_WRAPPER(user_data)->data;
+ lu->obj_type = SDB_SERVICE;
+ lu->last_update = svc->last_update;
+ return 0;
+} /* interval_fetcher_service */
+
+static int
+interval_fetcher_metric(sdb_store_metric_t *metric, sdb_object_t *user_data)
+{
+ interval_fetcher_t *lu = SDB_OBJ_WRAPPER(user_data)->data;
+ lu->obj_type = SDB_METRIC;
+ lu->last_update = metric->last_update;
+ return 0;
+} /* interval_fetcher_metric */
+
+static int
+interval_fetcher_attr(sdb_store_attribute_t *attr, sdb_object_t *user_data)
+{
+ interval_fetcher_t *lu = SDB_OBJ_WRAPPER(user_data)->data;
+ lu->obj_type = SDB_ATTRIBUTE;
+ lu->last_update = attr->last_update;
+ return 0;
+} /* interval_fetcher_attr */
+
+static sdb_store_writer_t interval_fetcher = {
+ interval_fetcher_host, interval_fetcher_service,
+ interval_fetcher_metric, interval_fetcher_attr,
+};
+
+static int
+get_interval(int obj_type, const char *hostname,
+ int parent_type, const char *parent, const char *name,
+ sdb_time_t last_update, sdb_time_t *interval_out)
+{
+ sdb_ast_fetch_t fetch = SDB_AST_FETCH_INIT;
+ char hn[hostname ? strlen(hostname) + 1 : 1];
+ char pn[parent ? strlen(parent) + 1 : 1];
+ char n[strlen(name) + 1];
+ int status;
+
+ interval_fetcher_t lu = { 0, 0, 0 };
+ sdb_object_wrapper_t obj = SDB_OBJECT_WRAPPER_STATIC(&lu);
+ sdb_time_t interval;
+
+ assert(name);
+
+ if (hostname)
+ strncpy(hn, hostname, sizeof(hn));
+ if (parent)
+ strncpy(pn, parent, sizeof(pn));
+ strncpy(n, name, sizeof(n));
+
+ fetch.obj_type = obj_type;
+ fetch.hostname = hostname ? hn : NULL;
+ fetch.parent_type = parent_type;
+ fetch.parent = parent ? pn : NULL;
+ fetch.name = n;
+
+ status = sdb_plugin_query(SDB_AST_NODE(&fetch),
+ &interval_fetcher, SDB_OBJ(&obj), NULL);
+ if ((status < 0) || (lu.obj_type != obj_type) || (lu.last_update == 0)) {
+ *interval_out = 0;
+ return 0;
+ }
+
+ if (lu.last_update >= last_update) {
+ if (lu.last_update > last_update)
+ sdb_log(SDB_LOG_DEBUG, "memstore: Cannot update %s '%s' - "
+ "value too old (%"PRIsdbTIME" < %"PRIsdbTIME")",
+ SDB_STORE_TYPE_TO_NAME(obj_type), name,
+ lu.last_update, last_update);
+ *interval_out = lu.interval;
+ return 1;
+ }
+
+ interval = last_update - lu.last_update;
+ if (lu.interval && interval)
+ interval = (sdb_time_t)((0.9 * (double)lu.interval)
+ + (0.1 * (double)interval));
+ *interval_out = interval;
+ return 0;
+} /* get_interval */
+
static void
get_backend(char **backends, size_t *backends_num)
{
}
host.name = cname;
- host.last_update = last_update;
+ host.last_update = last_update ? last_update : sdb_gettime();
+ if (get_interval(SDB_HOST, NULL, -1, NULL, cname,
+ host.last_update, &host.interval)) {
+ free(cname);
+ return 1;
+ }
host.backends = (const char * const *)backends;
get_backend(backends, &host.backends_num);
service.hostname = cname;
service.name = name;
- service.last_update = last_update;
+ service.last_update = last_update ? last_update : sdb_gettime();
+ if (get_interval(SDB_SERVICE, cname, -1, NULL, name,
+ service.last_update, &service.interval)) {
+ free(cname);
+ return 1;
+ }
service.backends = (const char * const *)backends;
get_backend(backends, &service.backends_num);
d.type = SDB_TYPE_STRING;
d.data.string = cname;
if (sdb_plugin_store_service_attribute(cname, name,
- "hostname", &d, last_update))
+ "hostname", &d, service.last_update))
status = -1;
}
metric.store.type = store->type;
metric.store.id = store->id;
}
- metric.last_update = last_update;
+ metric.last_update = last_update ? last_update : sdb_gettime();
+ if (get_interval(SDB_METRIC, cname, -1, NULL, name,
+ metric.last_update, &metric.interval)) {
+ free(cname);
+ return 1;
+ }
metric.backends = (const char * const *)backends;
get_backend(backends, &metric.backends_num);
d.type = SDB_TYPE_STRING;
d.data.string = cname;
if (sdb_plugin_store_metric_attribute(cname, name,
- "hostname", &d, last_update))
+ "hostname", &d, metric.last_update))
status = -1;
}
attr.parent = cname;
attr.key = key;
attr.value = *value;
- attr.last_update = last_update;
+ attr.last_update = last_update ? last_update : sdb_gettime();
+ if (get_interval(SDB_ATTRIBUTE, cname, -1, NULL, key,
+ attr.last_update, &attr.interval)) {
+ free(cname);
+ return 1;
+ }
attr.backends = (const char * const *)backends;
get_backend(backends, &attr.backends_num);
@@ -1728,7 +1853,12 @@ sdb_plugin_store_service_attribute(const char *hostname, const char *service,
attr.parent = service;
attr.key = key;
attr.value = *value;
- attr.last_update = last_update;
+ attr.last_update = last_update ? last_update : sdb_gettime();
+ if (get_interval(SDB_ATTRIBUTE, cname, SDB_SERVICE, service, key,
+ attr.last_update, &attr.interval)) {
+ free(cname);
+ return 1;
+ }
attr.backends = (const char * const *)backends;
get_backend(backends, &attr.backends_num);
attr.parent = metric;
attr.key = key;
attr.value = *value;
- attr.last_update = last_update;
+ attr.last_update = last_update ? last_update : sdb_gettime();
+ if (get_interval(SDB_ATTRIBUTE, cname, SDB_METRIC, metric, key,
+ attr.last_update, &attr.interval)) {
+ free(cname);
+ return 1;
+ }
attr.backends = (const char * const *)backends;
get_backend(backends, &attr.backends_num);
index 7c180fd2d44b2069c28a2e4e30f043c912a6a095..8c1739ed5c20089280518de9944692f4dab1d827 100644 (file)
* canonical.
*/
int
-sdb_memstore_host(sdb_memstore_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_time_t interval);
int
sdb_memstore_service(sdb_memstore_t *store, const char *hostname, const char *name,
- sdb_time_t last_update);
+ sdb_time_t last_update, sdb_time_t interval);
int
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_metric_store_t *metric_store,
+ sdb_time_t last_update, sdb_time_t interval);
int
sdb_memstore_attribute(sdb_memstore_t *store, const char *hostname,
- const char *key, const sdb_data_t *value, sdb_time_t last_update);
+ const char *key, const sdb_data_t *value,
+ sdb_time_t last_update, sdb_time_t interval);
int
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);
+ sdb_time_t last_update, sdb_time_t interval);
int
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_time_t last_update, sdb_time_t interval);
/*
* sdb_memstore_get_host:
index 1bf560ee68c23fb6481d57b628efbf72125022ca..c73ab3475bca6eb6b17b17565edd84e6601fe88b 100644 (file)
ck_assert(store != NULL);
for (i = 0; i < SDB_STATIC_ARRAY_LEN(hosts); ++i) {
- int status = sdb_memstore_host(store, hosts[i], 1);
+ int status = sdb_memstore_host(store, hosts[i], 1, 0);
ck_assert(status == 0);
}
for (i = 0; i < SDB_STATIC_ARRAY_LEN(metrics); ++i) {
int status = sdb_memstore_metric(store, metrics[i].host,
- metrics[i].metric, /* store */ NULL, 1);
+ metrics[i].metric, /* store */ NULL, 1, 0);
ck_assert(status == 0);
}
for (i = 0; i < SDB_STATIC_ARRAY_LEN(services); ++i) {
int status = sdb_memstore_service(store, services[i].host,
- services[i].service, 1);
+ services[i].service, 1, 0);
ck_assert(status == 0);
}
for (i = 0; i < SDB_STATIC_ARRAY_LEN(attrs); ++i) {
int status = sdb_memstore_attribute(store, attrs[i].host,
- attrs[i].name, &attrs[i].value, 1);
+ attrs[i].name, &attrs[i].value, 1, 0);
ck_assert(status == 0);
}
for (i = 0; i < SDB_STATIC_ARRAY_LEN(svc_attrs); ++i) {
int status = sdb_memstore_service_attr(store, svc_attrs[i].host,
svc_attrs[i].service, svc_attrs[i].name,
- &svc_attrs[i].value, 1);
+ &svc_attrs[i].value, 1, 0);
ck_assert(status == 0);
}
for (i = 0; i < SDB_STATIC_ARRAY_LEN(metric_attrs); ++i) {
int status = sdb_memstore_metric_attr(store, metric_attrs[i].host,
metric_attrs[i].metric, metric_attrs[i].name,
- &metric_attrs[i].value, 1);
+ &metric_attrs[i].value, 1, 0);
ck_assert(status == 0);
}
} /* populate */
index 461c583396583d87793809875659cac6ff02a941..a0447b639e8b5ea73de65ab8b15f4d9289c3da1a 100644 (file)
store = sdb_memstore_create();
ck_assert(store != NULL);
- sdb_memstore_host(store, "h1", 1 * SDB_INTERVAL_SECOND);
- sdb_memstore_host(store, "h2", 3 * SDB_INTERVAL_SECOND);
+ sdb_memstore_host(store, "h1", 1 * SDB_INTERVAL_SECOND, 0);
+ sdb_memstore_host(store, "h2", 3 * SDB_INTERVAL_SECOND, 0);
datum.type = SDB_TYPE_STRING;
datum.data.string = "v1";
- sdb_memstore_attribute(store, "h1", "k1", &datum, 1 * SDB_INTERVAL_SECOND);
+ sdb_memstore_attribute(store, "h1", "k1", &datum, 1 * SDB_INTERVAL_SECOND, 0);
datum.data.string = "v2";
- sdb_memstore_attribute(store, "h1", "k2", &datum, 2 * SDB_INTERVAL_SECOND);
+ sdb_memstore_attribute(store, "h1", "k2", &datum, 2 * SDB_INTERVAL_SECOND, 0);
datum.data.string = "v3";
- sdb_memstore_attribute(store, "h1", "k3", &datum, 2 * SDB_INTERVAL_SECOND);
+ sdb_memstore_attribute(store, "h1", "k3", &datum, 2 * SDB_INTERVAL_SECOND, 0);
+/* TODO: move these tests into generic store tests */
+#if 0
/* make sure that older updates don't overwrite existing values */
datum.data.string = "fail";
- sdb_memstore_attribute(store, "h1", "k2", &datum, 1 * SDB_INTERVAL_SECOND);
- sdb_memstore_attribute(store, "h1", "k3", &datum, 2 * SDB_INTERVAL_SECOND);
+ sdb_memstore_attribute(store, "h1", "k2", &datum, 1 * SDB_INTERVAL_SECOND, 0);
+ sdb_memstore_attribute(store, "h1", "k3", &datum, 2 * SDB_INTERVAL_SECOND, 0);
+#endif
- 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_memstore_metric(store, "h1", "m1", /* store */ NULL, 2 * SDB_INTERVAL_SECOND, 0);
+ sdb_memstore_metric(store, "h1", "m2", /* store */ NULL, 1 * SDB_INTERVAL_SECOND, 0);
+ sdb_memstore_metric(store, "h2", "m1", /* store */ NULL, 1 * SDB_INTERVAL_SECOND, 0);
- sdb_memstore_service(store, "h2", "s1", 1 * SDB_INTERVAL_SECOND);
- sdb_memstore_service(store, "h2", "s2", 2 * SDB_INTERVAL_SECOND);
+ sdb_memstore_service(store, "h2", "s1", 1 * SDB_INTERVAL_SECOND, 0);
+ sdb_memstore_service(store, "h2", "s2", 2 * SDB_INTERVAL_SECOND, 0);
datum.type = SDB_TYPE_INTEGER;
datum.data.integer = 42;
sdb_memstore_metric_attr(store, "h1", "m1", "k3",
- &datum, 2 * SDB_INTERVAL_SECOND);
+ &datum, 2 * SDB_INTERVAL_SECOND, 0);
datum.data.integer = 123;
sdb_memstore_service_attr(store, "h2", "s2", "k1",
- &datum, 2 * SDB_INTERVAL_SECOND);
+ &datum, 2 * SDB_INTERVAL_SECOND, 0);
datum.data.integer = 4711;
sdb_memstore_service_attr(store, "h2", "s2", "k2",
- &datum, 1 * SDB_INTERVAL_SECOND);
-
- /* don't overwrite k1 */
- datum.data.integer = 666;
- sdb_memstore_service_attr(store, "h2", "s2", "k1",
- &datum, 2 * SDB_INTERVAL_SECOND);
+ &datum, 1 * SDB_INTERVAL_SECOND, 0);
} /* populate */
static void
index 0c99ee1e294e7ef30b069e16d9b1d5ba6b6c05cd..0c30160b9eff10f8df9be6eaab96e9da6c6ca6f3 100644 (file)
ck_assert(store != NULL);
for (i = 0; i < SDB_STATIC_ARRAY_LEN(hosts); ++i) {
- int status = sdb_memstore_host(store, hosts[i], 1);
+ int status = sdb_memstore_host(store, hosts[i], 1, 0);
fail_unless(status == 0,
- "sdb_memstore_host(%s, 1) = %d; expected: 0",
+ "sdb_memstore_host(%s, 1, 0) = %d; expected: 0",
hosts[i], status);
}
for (i = 0; i < SDB_STATIC_ARRAY_LEN(metrics); ++i) {
int status = sdb_memstore_metric(store, metrics[i].host,
- metrics[i].metric, /* store */ NULL, 1);
+ metrics[i].metric, /* store */ NULL, 1, 0);
fail_unless(status == 0,
- "sdb_memstore_metric(%s, %s, NULL, 1) = %d; expected: 0",
+ "sdb_memstore_metric(%s, %s, NULL, 1, 0) = %d; expected: 0",
metrics[i].host, metrics[i].metric, status);
}
for (i = 0; i < SDB_STATIC_ARRAY_LEN(services); ++i) {
int status = sdb_memstore_service(store, services[i].host,
- services[i].service, 1);
+ services[i].service, 1, 0);
fail_unless(status == 0,
- "sdb_memstore_service(%s, %s, 1) = %d; expected: 0",
+ "sdb_memstore_service(%s, %s, 1, 0) = %d; expected: 0",
services[i].host, services[i].service, status);
}
for (i = 0; i < SDB_STATIC_ARRAY_LEN(attrs); ++i) {
int status = sdb_memstore_attribute(store, attrs[i].host,
- attrs[i].name, &attrs[i].value, 1);
+ attrs[i].name, &attrs[i].value, 1, 0);
fail_unless(status == 0,
- "sdb_memstore_attribute(%s, %s, <val>, 1) = %d; expected: 0",
+ "sdb_memstore_attribute(%s, %s, <val>, 1, 0) = %d; expected: 0",
attrs[i].host, attrs[i].name, status);
}
} /* populate */
index 7ddd50bcf4a1c4aaf2bb2e8f0a6231113025fca5..50d041ece884464501cd1768c2b6a990216a3662 100644 (file)
--- a/t/unit/core/store_test.c
+++ b/t/unit/core/store_test.c
{
sdb_data_t datum;
- sdb_memstore_host(store, "h1", 1);
- sdb_memstore_host(store, "h2", 3);
+ sdb_memstore_host(store, "h1", 1, 0);
+ sdb_memstore_host(store, "h2", 3, 0);
datum.type = SDB_TYPE_STRING;
datum.data.string = "v1";
- sdb_memstore_attribute(store, "h1", "k1", &datum, 1);
+ sdb_memstore_attribute(store, "h1", "k1", &datum, 1, 0);
datum.data.string = "v2";
- sdb_memstore_attribute(store, "h1", "k2", &datum, 2);
+ sdb_memstore_attribute(store, "h1", "k2", &datum, 2, 0);
datum.data.string = "v3";
- sdb_memstore_attribute(store, "h1", "k3", &datum, 2);
+ sdb_memstore_attribute(store, "h1", "k3", &datum, 2, 0);
/* make sure that older updates don't overwrite existing values */
datum.data.string = "fail";
- sdb_memstore_attribute(store, "h1", "k2", &datum, 1);
- sdb_memstore_attribute(store, "h1", "k3", &datum, 2);
+ sdb_memstore_attribute(store, "h1", "k2", &datum, 1, 0);
+ sdb_memstore_attribute(store, "h1", "k3", &datum, 2, 0);
- 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_memstore_metric(store, "h1", "m1", /* store */ NULL, 2, 0);
+ sdb_memstore_metric(store, "h1", "m2", /* store */ NULL, 1, 0);
+ sdb_memstore_metric(store, "h2", "m1", /* store */ NULL, 1, 0);
- sdb_memstore_service(store, "h2", "s1", 1);
- sdb_memstore_service(store, "h2", "s2", 2);
+ sdb_memstore_service(store, "h2", "s1", 1, 0);
+ sdb_memstore_service(store, "h2", "s2", 2, 0);
datum.type = SDB_TYPE_INTEGER;
datum.data.integer = 42;
- sdb_memstore_metric_attr(store, "h1", "m1", "k3", &datum, 2);
+ sdb_memstore_metric_attr(store, "h1", "m1", "k3", &datum, 2, 0);
datum.data.integer = 123;
- sdb_memstore_service_attr(store, "h2", "s2", "k1", &datum, 2);
+ sdb_memstore_service_attr(store, "h2", "s2", "k1", &datum, 2, 0);
datum.data.integer = 4711;
- sdb_memstore_service_attr(store, "h2", "s2", "k2", &datum, 1);
+ sdb_memstore_service_attr(store, "h2", "s2", "k2", &datum, 1, 0);
/* don't overwrite k1 */
datum.data.integer = 666;
- sdb_memstore_service_attr(store, "h2", "s2", "k1", &datum, 2);
+ sdb_memstore_service_attr(store, "h2", "s2", "k1", &datum, 2, 0);
} /* populate */
static void
} golden_data[] = {
{ "a", 1, 0 },
{ "a", 2, 0 },
- { "a", 1, 1 },
{ "b", 1, 0 },
- { "b", 1, 1 },
- { "A", 1, 1 }, /* case-insensitive */
- { "A", 3, 0 },
};
struct {
const char *name;
bool have;
} golden_hosts[] = {
- { "a", 1 == 1 },
- { "b", 1 == 1 },
- { "c", 0 == 1 },
- { "A", 1 == 1 },
+ { "a", 1 },
+ { "b", 1 },
+ { "c", 0 },
+ { "A", 1 },
};
size_t i;
int status;
status = sdb_memstore_host(store, golden_data[i].name,
- golden_data[i].last_update);
+ golden_data[i].last_update, 0);
fail_unless(status == golden_data[i].expected,
- "sdb_memstore_host(%s, %d) = %d; expected: %d",
+ "sdb_memstore_host(%s, %d, 0) = %d; expected: %d",
golden_data[i].name, (int)golden_data[i].last_update,
status, golden_data[i].expected);
}
size_t i;
for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_hosts); ++i) {
- int status = sdb_memstore_host(store, golden_hosts[i], 1);
+ int status = sdb_memstore_host(store, golden_hosts[i], 1, 0);
fail_unless(status >= 0,
"sdb_memstore_host(%s) = %d; expected: >=0",
golden_hosts[i], status);
{ "k", "k", "v", 1, -1 }, /* retry to ensure the host is not created */
{ "l", "k1", "v1", 1, 0 },
{ "l", "k1", "v2", 2, 0 },
- { "l", "k1", "v3", 2, 1 },
{ "l", "k2", "v1", 1, 0 },
{ "m", "k", "v1", 1, 0 },
- { "m", "k", "v2", 1, 1 },
};
size_t i;
- sdb_memstore_host(store, "l", 1);
- sdb_memstore_host(store, "m", 1);
+ sdb_memstore_host(store, "l", 1, 0);
+ sdb_memstore_host(store, "m", 1, 0);
for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_data); ++i) {
sdb_data_t datum;
int status;
status = sdb_memstore_attribute(store, golden_data[i].host,
golden_data[i].key, &datum,
- golden_data[i].last_update);
+ golden_data[i].last_update, 0);
fail_unless(status == golden_data[i].expected,
"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);
+ golden_data[i].last_update, status, golden_data[i].expected, 0);
}
}
END_TEST
{ "l", "m1", NULL, 1, 0 },
{ "l", "m1", &store1, 2, 0 },
{ "l", "m1", &store1, 3, 0 },
- { "l", "m1", NULL, 3, 1 },
{ "l", "m2", &store1, 1, 0 },
{ "l", "m2", &store2, 2, 0 },
{ "l", "m2", NULL, 3, 0 },
{ "m", "m", &store1, 1, 0 },
{ "m", "m", NULL, 2, 0 },
- { "m", "m", NULL, 2, 1 },
{ "m", "m", &store1, 3, 0 },
{ "m", "m", &store2, 4, 0 },
{ "m", "m", NULL, 5, 0 },
size_t i;
- sdb_memstore_host(store, "m", 1);
- sdb_memstore_host(store, "l", 1);
+ sdb_memstore_host(store, "m", 1, 0);
+ sdb_memstore_host(store, "l", 1, 0);
for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_data); ++i) {
int status;
status = sdb_memstore_metric(store, golden_data[i].host,
golden_data[i].metric, golden_data[i].store,
- golden_data[i].last_update);
+ golden_data[i].last_update, 0);
fail_unless(status == golden_data[i].expected,
- "sdb_memstore_metric(%s, %s, %p, %d) = %d; expected: %d",
+ "sdb_memstore_metric(%s, %s, %p, %d, 0) = %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);
/* retry, it should still fail */
{ "l", "mX", "a1", { SDB_TYPE_INTEGER, { .integer = 123 } }, 1, -1 },
{ "l", "m1", "a1", { SDB_TYPE_INTEGER, { .integer = 123 } }, 1, 0 },
- { "l", "m1", "a1", { SDB_TYPE_INTEGER, { .integer = 123 } }, 1, 1 },
{ "l", "m1", "a1", { SDB_TYPE_INTEGER, { .integer = 123 } }, 2, 0 },
{ "l", "m1", "a2", { SDB_TYPE_INTEGER, { .integer = 123 } }, 1, 0 },
- { "l", "m1", "a2", { SDB_TYPE_INTEGER, { .integer = 123 } }, 1, 1 },
{ "l", "m2", "a2", { SDB_TYPE_INTEGER, { .integer = 123 } }, 1, 0 },
{ "m", "m1", "a1", { SDB_TYPE_INTEGER, { .integer = 123 } }, 1, 0 },
};
size_t i;
- 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);
+ sdb_memstore_host(store, "m", 1, 0);
+ sdb_memstore_host(store, "l", 1, 0);
+ sdb_memstore_metric(store, "m", "m1", NULL, 1, 0);
+ sdb_memstore_metric(store, "l", "m1", NULL, 1, 0);
+ sdb_memstore_metric(store, "l", "m2", NULL, 1, 0);
for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_data); ++i) {
int status;
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);
+ &golden_data[i].value, golden_data[i].last_update, 0);
fail_unless(status == golden_data[i].expected,
- "sdb_memstore_metric_attr(%s, %s, %s, %d, %d) = %d; "
+ "sdb_memstore_metric_attr(%s, %s, %s, %d, %d, 0) = %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);
{ "k", "s", 1, -1 }, /* retry to ensure the host is not created */
{ "l", "s1", 1, 0 },
{ "l", "s1", 2, 0 },
- { "l", "s1", 2, 1 },
{ "l", "s2", 1, 0 },
{ "m", "s", 1, 0 },
- { "m", "s", 1, 1 },
};
size_t i;
- sdb_memstore_host(store, "m", 1);
- sdb_memstore_host(store, "l", 1);
+ sdb_memstore_host(store, "m", 1, 0);
+ sdb_memstore_host(store, "l", 1, 0);
for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_data); ++i) {
int status;
status = sdb_memstore_service(store, golden_data[i].host,
- golden_data[i].svc, golden_data[i].last_update);
+ golden_data[i].svc, golden_data[i].last_update, 0);
fail_unless(status == golden_data[i].expected,
- "sdb_memstore_service(%s, %s, %d) = %d; expected: %d",
+ "sdb_memstore_service(%s, %s, %d, 0) = %d; expected: %d",
golden_data[i].host, golden_data[i].svc,
golden_data[i].last_update, status, golden_data[i].expected);
}
/* retry, it should still fail */
{ "l", "sX", "a1", { SDB_TYPE_INTEGER, { .integer = 123 } }, 1, -1 },
{ "l", "s1", "a1", { SDB_TYPE_INTEGER, { .integer = 123 } }, 1, 0 },
- { "l", "s1", "a1", { SDB_TYPE_INTEGER, { .integer = 123 } }, 1, 1 },
{ "l", "s1", "a1", { SDB_TYPE_INTEGER, { .integer = 123 } }, 2, 0 },
{ "l", "s1", "a2", { SDB_TYPE_INTEGER, { .integer = 123 } }, 1, 0 },
- { "l", "s1", "a2", { SDB_TYPE_INTEGER, { .integer = 123 } }, 1, 1 },
{ "l", "s2", "a2", { SDB_TYPE_INTEGER, { .integer = 123 } }, 1, 0 },
{ "m", "s1", "a1", { SDB_TYPE_INTEGER, { .integer = 123 } }, 1, 0 },
};
size_t i;
- 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);
+ sdb_memstore_host(store, "m", 1, 0);
+ sdb_memstore_host(store, "l", 1, 0);
+ sdb_memstore_service(store, "m", "s1", 1, 0);
+ sdb_memstore_service(store, "l", "s1", 1, 0);
+ sdb_memstore_service(store, "l", "s2", 1, 0);
for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_data); ++i) {
int status;
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);
+ &golden_data[i].value, golden_data[i].last_update, 0);
fail_unless(status == golden_data[i].expected,
- "sdb_memstore_service_attr(%s, %s, %s, %d, %d) = %d; "
+ "sdb_memstore_service_attr(%s, %s, %s, %d, %d, 0) = %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);
sdb_time_t now = sdb_gettime();
int check;
- 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);
+ sdb_memstore_host(store, "host", 20, 10);
+ sdb_memstore_attribute(store, "host", "attr", &get_field_data[_i].value, 20, 10);
if (get_field_data[_i].hostname) {
obj = sdb_memstore_get_host(store, get_field_data[_i].hostname);
}
END_TEST
+/* TODO: move these tests into generic store tests */
+#if 0
START_TEST(test_interval)
{
sdb_memstore_obj_t *host;
sdb_object_deref(SDB_OBJ(host));
}
END_TEST
+#endif
static int
scan_count(sdb_memstore_obj_t *obj, sdb_memstore_matcher_t *filter, void *user_data)
tcase_add_test(tc, test_store_service_attr);
TC_ADD_LOOP_TEST(tc, get_field);
tcase_add_test(tc, test_get_child);
- tcase_add_test(tc, test_interval);
tcase_add_test(tc, test_scan);
ADD_TCASE(tc);
}