summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 5d4e2d9)
raw | patch | inline | side by side (parent: 5d4e2d9)
author | Sebastian Harl <sh@tokkee.org> | |
Sun, 9 Aug 2015 22:19:28 +0000 (00:19 +0200) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Sun, 9 Aug 2015 22:19:28 +0000 (00:19 +0200) |
This plugin replaces the default, built-in store. It is a simple wrapper
around the built-in store implementation and, thus, provides exactly the same
functionality but wrapped into a plugin.
around the built-in store implementation and, thus, provides exactly the same
functionality but wrapped into a plugin.
14 files changed:
diff --git a/configure.ac b/configure.ac
index f54868c29dd7baa71b69d8541d8cc96a066f34d4..897112ef97192f7ffa847b3fc7b4ad2c842ecd8e 100644 (file)
--- a/configure.ac
+++ b/configure.ac
[fetch time-series data from RRD files])
m4_divert_once([HELP_ENABLE], [
-Store writers:])
+Store implementations:])
+AC_SDB_PLUGIN([store-memory], [yes],
+ [store objects in a volatile, in-memory database (read/write)])
AC_SDB_PLUGIN([store-network], [yes],
- [send stored objects to a remote instance])
+ [send stored objects to a remote instance (write only)])
m4_divert_once([HELP_ENABLE], [
Plugins:])
AC_MSG_RESULT([ Time-series fetchers:])
AC_MSG_RESULT([ rrdtool: . . . . . . . . . $enable_timeseries_rrdtool])
AC_MSG_RESULT()
-AC_MSG_RESULT([ Store writers:])
-AC_MSG_RESULT([ network: . . . . . . . . . $enable_store_network])
+AC_MSG_RESULT([ Store implementations:])
+AC_MSG_RESULT([ memory: . . . . . . . . . . $enable_store_memory])
+AC_MSG_RESULT([ network (writer): . . . . . $enable_store_network])
AC_MSG_RESULT()
AC_MSG_RESULT([ Plugins:])
AC_MSG_RESULT([ cname::dns: . . . . . . . . $enable_cname_dns])
diff --git a/src/Makefile.am b/src/Makefile.am
index 0dbd1511cf58321432a1b55ee21e2d06b61b01f2..f3bcae192846276a26dfbd868ba946868d5cbc19 100644 (file)
--- a/src/Makefile.am
+++ b/src/Makefile.am
sysdbd_DEPENDENCIES += plugins/timeseries/rrdtool.la
endif
+if BUILD_PLUGIN_STOREMEMORY
+pkgstorelib_LTLIBRARIES += plugins/store/memory.la
+plugins_store_memory_la_SOURCES = plugins/store/memory.c
+plugins_store_memory_la_LDFLAGS = $(AM_LDFLAGS) -module -avoid-version
+sysdbd_LDADD += -dlopen plugins/store/memory.la
+sysdbd_DEPENDENCIES += plugins/store/memory.la
+endif
+
if BUILD_PLUGIN_STORENETWORK
pkgstorelib_LTLIBRARIES += plugins/store/network.la
plugins_store_network_la_SOURCES = plugins/store/network.c
diff --git a/src/plugins/store/memory.c b/src/plugins/store/memory.c
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+ * SysDB - src/plugins/backend/store/memory.c
+ * Copyright (C) 2015 Sebastian 'tokkee' Harl <sh@tokkee.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "sysdb.h"
+#include "core/plugin.h"
+#include "core/store.h"
+#include "utils/error.h"
+
+SDB_PLUGIN_MAGIC;
+
+/*
+ * plugin API
+ */
+
+static int
+mem_init(sdb_object_t *user_data)
+{
+ sdb_store_t *store = SDB_STORE(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_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;
+ }
+ return 0;
+} /* mem_init */
+
+static int
+mem_shutdown(sdb_object_t *user_data)
+{
+ sdb_object_deref(user_data);
+ return 0;
+} /* mem_shutdown */
+
+int
+sdb_module_init(sdb_plugin_info_t *info)
+{
+ /* store singleton */
+ static sdb_store_t *store;
+
+ sdb_plugin_set_info(info, SDB_PLUGIN_INFO_DESC, "in-memory object store");
+ sdb_plugin_set_info(info, SDB_PLUGIN_INFO_COPYRIGHT,
+ "Copyright (C) 2015 Sebastian 'tokkee' Harl <sh@tokkee.org>");
+ sdb_plugin_set_info(info, SDB_PLUGIN_INFO_LICENSE, "BSD");
+ sdb_plugin_set_info(info, SDB_PLUGIN_INFO_VERSION, SDB_VERSION);
+ sdb_plugin_set_info(info, SDB_PLUGIN_INFO_PLUGIN_VERSION, SDB_VERSION);
+
+ if (! store) {
+ if (! (store = sdb_store_create())) {
+ sdb_log(SDB_LOG_ERR, "store::memory plugin: "
+ "Failed to create store object");
+ return -1;
+ }
+ }
+
+ sdb_plugin_register_init("main", mem_init, SDB_OBJ(store));
+ sdb_plugin_register_shutdown("main", mem_shutdown, SDB_OBJ(store));
+ return 0;
+} /* sdb_module_init */
+
+/* vim: set tw=78 sw=4 ts=4 noexpandtab : */
+
index ce54313542df26cd254847d601f01fc14413d74a..759eee2f5652ebee72c9131d22a05ddbf8f704b2 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;
index 964901f94bc198dfd3d13584ee42994d1868ee5d..589df3f83ed8bd869fbbde1396a04cac95402d10 100644 (file)
# to active the respective feature. #
#============================================================================#
+#----------------------------------------------------------------------------#
+# "Store" plugins provide means to store and/or query information. #
+#----------------------------------------------------------------------------#
+LoadPlugin "store::memory"
+LoadPlugin "store::network"
+
#----------------------------------------------------------------------------#
# "cname" plugins canonicalize hostnames before actually storing them. All #
# cname callbacks are applied to an hostname in the order in which they have #
index e7766efef7e323dfc56ae99360f62eb9f885534b..02cbdb35e4ab9bb6de41a4b7154de1b4e5fd1695 100755 (executable)
--- a/t/integration/client.sh
+++ b/t/integration/client.sh
PluginDir "$PLUGIN_DIR"
Interval 2
-LoadBackend mock_plugin
+LoadPlugin "store::memory"
+LoadBackend "mock_plugin"
<Backend "mock_plugin">
</Backend>
-LoadPlugin mock_timeseries
+LoadPlugin "mock_timeseries"
EOF
run_sysdbd -D -C "$SYSDBD_CONF"
index 7f0ab959e964b6f70ab07a00f8c5d23a32750cf5..4daeecfe4b0f8a8df0d26f5d9f5bf8ded182b62b 100755 (executable)
--- a/t/integration/config.sh
+++ b/t/integration/config.sh
cat <<EOF > "$SYSDBD_CONF"
Listen "${SOCKET_FILE}"
PluginDir "$PLUGIN_DIR"
-LoadBackend mock_plugin
+LoadPlugin "store::memory"
+LoadBackend "mock_plugin"
<Backend "mock_plugin">
</Backend>
EOF
cat <<EOF > "$SYSDBD_CONF"
Listen "${SOCKET_FILE}"
PluginDir "$PLUGIN_DIR"
-LoadBackend mock_plugin
+LoadPlugin "store::memory"
+LoadBackend "mock_plugin"
<Backend "mock_plugin">
</Backend>
EOF
index 9738fa6d59749a2b390256b26ceb1217058c98c1..3ddb9234fef6a609bd5f5bf825088187de127cfa 100755 (executable)
--- a/t/integration/filter.sh
+++ b/t/integration/filter.sh
PluginDir "$PLUGIN_DIR"
Interval 2
-LoadBackend mock_plugin
+LoadPlugin "store::memory"
+LoadBackend "mock_plugin"
<Backend "mock_plugin">
</Backend>
EOF
index 95dea02147d903f21c3ecc07afc3802aba9f94ec..2c9d8f386395a7da3a63e9630276ce2c35d72a97 100755 (executable)
PluginDir "$PLUGIN_DIR"
Interval 2
-LoadBackend mock_plugin
+LoadPlugin "store::memory"
+LoadBackend "mock_plugin"
<Backend "mock_plugin">
</Backend>
EOF
index b9c8ff9e3ff2b4d33204fb95e5b49221851382c3..0df531ce2b1cf7680c520c9113ffa27cc43d9950 100755 (executable)
PluginDir "$PLUGIN_DIR"
Interval 2
-LoadPlugin mock_timeseries
+LoadPlugin "store::memory"
+LoadPlugin "mock_timeseries"
EOF
run_sysdbd -D -C "$SYSDBD_CONF"
Server "$SOCKET_FILE"
</Plugin>
-LoadBackend mock_plugin
+LoadBackend "mock_plugin"
<Backend "mock_plugin">
</Backend>
EOF
index 28c365b96272d5b3d1c706b846c26e574aed2401..5607859b80c31402bbeacca105da85d8529ec710 100755 (executable)
PluginDir "$PLUGIN_DIR"
Interval 2
-LoadPlugin mock_timeseries
+LoadPlugin "store::memory"
+LoadPlugin "mock_timeseries"
EOF
run_sysdbd -D -C "$SYSDBD_CONF"
Server "$SOCKET_FILE"
</Plugin>
-LoadBackend mock_plugin
+LoadBackend "mock_plugin"
<Backend "mock_plugin">
</Backend>
EOF
index e0eb9c88f60bd0f14c4996edb446841efa6d0d94..f6d09cb4648e12dfb3bc2ce6946de3b985f0ad60 100755 (executable)
PluginDir "$PLUGIN_DIR"
Interval 2
-LoadPlugin mock_timeseries
+LoadPlugin "store::memory"
+LoadPlugin "mock_timeseries"
EOF
run_sysdbd -D -C "$SYSDBD_CONF"
Server "$SOCKET_FILE"
</Plugin>
-LoadBackend mock_plugin
+LoadBackend "mock_plugin"
<Backend "mock_plugin">
</Backend>
EOF
diff --git a/t/integration/ssl.sh b/t/integration/ssl.sh
index cea2380087aa7626cf91e32943d623461db47fc1..0c7177dc27a334beffae60407a1ae2e20e88cafb 100755 (executable)
--- a/t/integration/ssl.sh
+++ b/t/integration/ssl.sh
SSLCertificateKey "$SERVER_KEY"
SSLCACertificates "$CA_CERT"
</Listen>
+PluginDir "$PLUGIN_DIR"
+LoadPlugin "store::memory"
EOF
run_sysdbd -D -C "$SYSDBD_CONF"
wait_for_sysdbd_tcp localhost 12345
index fe4efe3c1945ac9626017ff931a3ec6629d28d8c..78aa3be2fb81e7d72c3d794dc3fb52c41385d84d 100644 (file)
cp "$TOP_BUILDDIR/t/integration/.libs/mock_plugin.so" "$TESTDIR/backend"
mkdir "$TESTDIR/store"
+cp "$TOP_BUILDDIR/src/plugins/store/.libs/memory.so" "$TESTDIR/store"
cp "$TOP_BUILDDIR/src/plugins/store/.libs/network.so" "$TESTDIR/store"
cp "$TOP_BUILDDIR"/src/sysdb "$TESTDIR"