summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: e018e9e)
raw | patch | inline | side by side (parent: e018e9e)
author | Sebastian Harl <sh@tokkee.org> | |
Thu, 6 Aug 2015 15:22:31 +0000 (17:22 +0200) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Thu, 6 Aug 2015 15:26:22 +0000 (17:26 +0200) |
This is in preparation to more flexible store handling.
src/core/store.c | patch | blob | history | |
src/include/core/store.h | patch | blob | history |
diff --git a/src/core/store.c b/src/core/store.c
index 7671e9800f13a0ac0a81e2b24817d95b0f0a83ef..ccb35389f5c5c6a7f912dccd24787860ee525445 100644 (file)
--- a/src/core/store.c
+++ b/src/core/store.c
* private variables
*/
-typedef struct {
+struct sdb_store {
sdb_object_t super;
/* hosts are the top-level entries and
* reference everything else */
sdb_avltree_t *hosts;
pthread_rwlock_t host_lock;
-} sdb_store_t;
-#define ST(obj) ((sdb_store_t *)(obj))
+};
sdb_store_t *global_store = NULL;
store_init(sdb_object_t *obj, va_list __attribute__((unused)) ap)
{
int err;
- if (! (ST(obj)->hosts = sdb_avltree_create()))
+ if (! (SDB_STORE(obj)->hosts = sdb_avltree_create()))
return -1;
- if ((err = pthread_rwlock_init(&ST(obj)->host_lock, /* attr = */ NULL))) {
+ if ((err = pthread_rwlock_init(&SDB_STORE(obj)->host_lock,
+ /* attr = */ NULL))) {
char errbuf[128];
sdb_log(SDB_LOG_ERR, "store: Failed to initialize lock: %s",
sdb_strerror(err, errbuf, sizeof(errbuf)));
store_destroy(sdb_object_t *obj)
{
int err;
- if ((err = pthread_rwlock_destroy(&ST(obj)->host_lock))) {
+ if ((err = pthread_rwlock_destroy(&SDB_STORE(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(ST(obj)->hosts);
- ST(obj)->hosts = NULL;
+ sdb_avltree_destroy(SDB_STORE(obj)->hosts);
+ SDB_STORE(obj)->hosts = NULL;
} /* store_destroy */
static int
const char *key, const sdb_data_t *value,
sdb_time_t last_update, sdb_object_t *user_data)
{
- sdb_store_t *st = ST(user_data);
+ sdb_store_t *st = SDB_STORE(user_data);
sdb_host_t *host;
sdb_avltree_t *attrs;
static int
store_host(const char *name, sdb_time_t last_update, sdb_object_t *user_data)
{
- sdb_store_t *st = ST(user_data);
+ sdb_store_t *st = SDB_STORE(user_data);
char *cname = NULL;
int status = 0;
const char *key, const sdb_data_t *value, sdb_time_t last_update,
sdb_object_t *user_data)
{
- sdb_store_t *st = ST(user_data);
+ sdb_store_t *st = SDB_STORE(user_data);
sdb_host_t *host;
sdb_service_t *svc;
store_service(const char *hostname, const char *name,
sdb_time_t last_update, sdb_object_t *user_data)
{
- sdb_store_t *st = ST(user_data);
+ sdb_store_t *st = SDB_STORE(user_data);
sdb_host_t *host;
sdb_avltree_t *services;
const char *key, const sdb_data_t *value, sdb_time_t last_update,
sdb_object_t *user_data)
{
- sdb_store_t *st = ST(user_data);
+ sdb_store_t *st = SDB_STORE(user_data);
sdb_avltree_t *metrics;
sdb_host_t *host;
sdb_metric_store_t *store, sdb_time_t last_update,
sdb_object_t *user_data)
{
- sdb_store_t *st = ST(user_data);
+ sdb_store_t *st = SDB_STORE(user_data);
sdb_store_obj_t *obj = NULL;
sdb_host_t *host;
return status;
} /* store_metric */
-static sdb_store_writer_t store_writer = {
+sdb_store_writer_t sdb_store_writer = {
store_host, store_service, store_metric,
store_attribute, store_service_attr, store_metric_attr,
};
return sdb_store_query_execute(QUERY(q), buf, errbuf);
} /* execute_query */
-static sdb_store_reader_t store_reader = {
+sdb_store_reader_t sdb_store_reader = {
prepare_query, execute_query,
};
* public API
*/
+sdb_store_t *
+sdb_store_create(void)
+{
+ return SDB_STORE(sdb_object_create("store", store_type));
+} /* sdb_store_create */
+
int
sdb_store_init(void)
{
if (global_store)
return 0;
- global_store = ST(sdb_object_create("store", store_type));
+ 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",
- &store_writer, SDB_OBJ(global_store)))
+ &sdb_store_writer, SDB_OBJ(global_store)))
return -1;
return sdb_plugin_register_reader("memstore",
- &store_reader, SDB_OBJ(global_store));
+ &sdb_store_reader, SDB_OBJ(global_store));
} /* sdb_store_init */
void
index e851dd9f955ee38cb3bec993fe753aa3e4f5a537..e5e011875e1775a1592c0511e06d5f3928121b50 100644 (file)
--- a/src/include/core/store.h
+++ b/src/include/core/store.h
: ((f) == SDB_FIELD_TIMESERIES) ? SDB_TYPE_BOOLEAN \
: -1)
+/*
+ * sdb_store_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))
+
/*
* sdb_store_obj_t represents the super-class of any object stored in the
* database. It inherits from sdb_object_t and may safely be cast to a generic
sdb_object_t *user_data);
} sdb_store_writer_t;
+/*
+ * sdb_store_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;
+
/*
* A store reader describes the interface to query a store implementation.
*/
sdb_object_t *user_data);
} sdb_store_reader_t;
+/*
+ * sdb_store_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;
+
+/*
+ * sdb_store_create:
+ * Allocate a new in-memory store.
+ */
+sdb_store_t *
+sdb_store_create(void);
+
/*
* sdb_store_init:
* Initialize the store sub-system. This function has to be called before