summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 873627f)
raw | patch | inline | side by side (parent: 873627f)
author | Sebastian Harl <sh@tokkee.org> | |
Sat, 8 Aug 2015 07:34:56 +0000 (09:34 +0200) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Sat, 8 Aug 2015 07:57:04 +0000 (09:57 +0200) |
Instead, register a store from sysdbd and make sure to re-register it on
reconfigure. Previously, the store plugin would have been dropped in that
case.
reconfigure. Previously, the store plugin would have been dropped in that
case.
src/core/store.c | patch | blob | history | |
src/include/core/store.h | patch | blob | history | |
src/tools/sysdbd/main.c | patch | blob | history | |
t/unit/frontend/query_test.c | patch | blob | history |
diff --git a/src/core/store.c b/src/core/store.c
index e24d2ef0a5356bf0a2badc8aa5fe468f94983a4f..bea4d2b578c421ed7706791e2aee0db95524de96 100644 (file)
--- a/src/core/store.c
+++ b/src/core/store.c
pthread_rwlock_t host_lock;
};
-sdb_store_t *global_store = NULL;
-
/*
* private types
*/
return SDB_STORE(sdb_object_create("store", store_type));
} /* sdb_store_create */
-int
-sdb_store_init(void)
-{
- if (global_store)
- return 0;
-
- global_store = SDB_STORE(sdb_object_create("store", store_type));
- if (! global_store) {
- sdb_log(SDB_LOG_ERR, "store: Failed to allocate store");
- return -1;
- }
- if (sdb_plugin_register_writer("memstore",
- &sdb_store_writer, SDB_OBJ(global_store)))
- return -1;
- return sdb_plugin_register_reader("memstore",
- &sdb_store_reader, SDB_OBJ(global_store));
-} /* sdb_store_init */
-
-void
-sdb_store_clear(void)
-{
- if (! global_store)
- return;
- sdb_avltree_clear(global_store->hosts);
-} /* sdb_store_clear */
-
int
sdb_store_host(sdb_store_t *store, const char *name, sdb_time_t last_update)
{
index aa53e8eadec81721c19d0c84adefe7634a146bb3..16a094adbf8e347b9278d94142a3ff4d0242632b 100644 (file)
--- a/src/include/core/store.h
+++ b/src/include/core/store.h
sdb_store_t *
sdb_store_create(void);
-/*
- * sdb_store_init:
- * Initialize the store sub-system. This function has to be called before
- * doing any other store operations.
- *
- * Returns:
- * - 0 on success
- * - a negative value else
- */
-int
-sdb_store_init(void);
-
-/*
- * sdb_store_clear:
- * Clear the entire store and remove all stored objects.
- */
-void
-sdb_store_clear(void);
-
/*
* sdb_store_host, sdb_store_service, sdb_store_metric, sdb_store_attribute,
* sdb_store_metric_attr:
index cc3525e30ef4374e3c904797cccd176de2e94043..ce54313542df26cd254847d601f01fc14413d74a 100644 (file)
--- a/src/tools/sysdbd/main.c
+++ b/src/tools/sysdbd/main.c
return 0;
} /* daemonize */
+static int
+store_init(void)
+{
+ sdb_store_t *store = sdb_store_create();
+
+ 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_object_deref(SDB_OBJ(store));
+ return -1;
+ }
+ if (sdb_plugin_register_reader("memstore",
+ &sdb_store_reader, SDB_OBJ(store))) {
+ sdb_object_deref(SDB_OBJ(store));
+ return -1;
+ }
+
+ /* Pass ownership to the plugins */
+ sdb_object_deref(SDB_OBJ(store));
+ return 0;
+} /* store_init */
+
static int
configure(void)
{
"\tCheck other error messages for details.");
return 1;
}
+ if (store_init()) {
+ sdb_log(SDB_LOG_ERR, "Failed to initialize the store");
+ return 1;
+ }
if (! listen_addresses) {
listen_addresses = default_listen_addresses;
if (sdb_ssl_init())
exit(1);
- if (sdb_store_init())
- exit(1);
sdb_plugin_init_all();
plugin_main_loop.default_interval = SECS_TO_SDB_TIME(60);
index 7fb73a453f33dc7bf84a8989557f8c9470f93b10..5330999c2d091e9828b00dc9d0c01fb1509b810a 100644 (file)
static void
populate(void)
{
+ sdb_store_t *store;
sdb_data_t datum;
- sdb_store_init();
+ /* the frontend accesses the store via the plugin API */
+ store = sdb_store_create();
+ ck_assert(store != NULL);
+ ck_assert(sdb_plugin_register_writer("test-writer",
+ &sdb_store_writer, SDB_OBJ(store)) == 0);
+ ck_assert(sdb_plugin_register_reader("test-reader",
+ &sdb_store_reader, SDB_OBJ(store)) == 0);
+ sdb_object_deref(SDB_OBJ(store));
+ /* populate the store */
sdb_plugin_store_host("h1", 1 * SDB_INTERVAL_SECOND);
sdb_plugin_store_host("h2", 3 * SDB_INTERVAL_SECOND);
&datum, 1 * SDB_INTERVAL_SECOND);
} /* populate */
+static void
+turndown(void)
+{
+ sdb_plugin_unregister_all();
+} /* turndown */
+
#define HOST_H1 \
"{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:01 +0000\", " \
"\"update_interval\": \"0s\", \"backends\": [], " \
TEST_MAIN("frontend::query")
{
TCase *tc = tcase_create("core");
- tcase_add_checked_fixture(tc, populate, sdb_store_clear);
+ tcase_add_checked_fixture(tc, populate, turndown);
TC_ADD_LOOP_TEST(tc, query);
ADD_TCASE(tc);
}