From: Sebastian Harl Date: Sun, 9 Aug 2015 22:19:28 +0000 (+0200) Subject: store::memory: Add a plugin providing an in-memory store. X-Git-Tag: sysdb-0.8.0~48 X-Git-Url: https://git.tokkee.org/?p=sysdb.git;a=commitdiff_plain;h=dc7d88e992d19870cbec25244e0f1d4ddc0541b7 store::memory: Add a plugin providing an in-memory store. 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. --- diff --git a/configure.ac b/configure.ac index f54868c..897112e 100644 --- a/configure.ac +++ b/configure.ac @@ -685,9 +685,11 @@ AC_SDB_PLUGIN([timeseries-rrdtool], [$rrdtool_default], [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:]) @@ -771,8 +773,9 @@ AC_MSG_RESULT() 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 0dbd151..f3bcae1 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -225,6 +225,14 @@ sysdbd_LDADD += -dlopen plugins/timeseries/rrdtool.la 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 new file mode 100644 index 0000000..3cbc1e8 --- /dev/null +++ b/src/plugins/store/memory.c @@ -0,0 +1,99 @@ +/* + * SysDB - src/plugins/backend/store/memory.c + * Copyright (C) 2015 Sebastian 'tokkee' Harl + * 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 "); + 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 : */ + diff --git a/src/tools/sysdbd/main.c b/src/tools/sysdbd/main.c index ce54313..759eee2 100644 --- a/src/tools/sysdbd/main.c +++ b/src/tools/sysdbd/main.c @@ -181,31 +181,6 @@ daemonize(void) 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) { @@ -219,10 +194,6 @@ 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; diff --git a/src/tools/sysdbd/sysdbd.conf.sample b/src/tools/sysdbd/sysdbd.conf.sample index 964901f..589df3f 100644 --- a/src/tools/sysdbd/sysdbd.conf.sample +++ b/src/tools/sysdbd/sysdbd.conf.sample @@ -27,6 +27,12 @@ LoadPlugin "syslog" # 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 # diff --git a/t/integration/client.sh b/t/integration/client.sh index e7766ef..02cbdb3 100755 --- a/t/integration/client.sh +++ b/t/integration/client.sh @@ -38,11 +38,12 @@ Listen "$SOCKET_FILE" PluginDir "$PLUGIN_DIR" Interval 2 -LoadBackend mock_plugin +LoadPlugin "store::memory" +LoadBackend "mock_plugin" -LoadPlugin mock_timeseries +LoadPlugin "mock_timeseries" EOF run_sysdbd -D -C "$SYSDBD_CONF" diff --git a/t/integration/config.sh b/t/integration/config.sh index 7f0ab95..4daeecf 100755 --- a/t/integration/config.sh +++ b/t/integration/config.sh @@ -95,7 +95,8 @@ SOCKET_FILE="$ORIG_SOCKET-3" cat < "$SYSDBD_CONF" Listen "${SOCKET_FILE}" PluginDir "$PLUGIN_DIR" -LoadBackend mock_plugin +LoadPlugin "store::memory" +LoadBackend "mock_plugin" EOF @@ -107,7 +108,8 @@ SOCKET_FILE="$ORIG_SOCKET-4" cat < "$SYSDBD_CONF" Listen "${SOCKET_FILE}" PluginDir "$PLUGIN_DIR" -LoadBackend mock_plugin +LoadPlugin "store::memory" +LoadBackend "mock_plugin" EOF diff --git a/t/integration/filter.sh b/t/integration/filter.sh index 9738fa6..3ddb923 100755 --- a/t/integration/filter.sh +++ b/t/integration/filter.sh @@ -38,7 +38,8 @@ Listen "$SOCKET_FILE" PluginDir "$PLUGIN_DIR" Interval 2 -LoadBackend mock_plugin +LoadPlugin "store::memory" +LoadBackend "mock_plugin" EOF diff --git a/t/integration/matching.sh b/t/integration/matching.sh index 95dea02..2c9d8f3 100755 --- a/t/integration/matching.sh +++ b/t/integration/matching.sh @@ -38,7 +38,8 @@ Listen "$SOCKET_FILE" PluginDir "$PLUGIN_DIR" Interval 2 -LoadBackend mock_plugin +LoadPlugin "store::memory" +LoadBackend "mock_plugin" EOF diff --git a/t/integration/query_fetch.sh b/t/integration/query_fetch.sh index b9c8ff9..0df531c 100755 --- a/t/integration/query_fetch.sh +++ b/t/integration/query_fetch.sh @@ -38,7 +38,8 @@ Listen "$SOCKET_FILE" PluginDir "$PLUGIN_DIR" Interval 2 -LoadPlugin mock_timeseries +LoadPlugin "store::memory" +LoadPlugin "mock_timeseries" EOF run_sysdbd -D -C "$SYSDBD_CONF" @@ -54,7 +55,7 @@ LoadPlugin "store::network" Server "$SOCKET_FILE" -LoadBackend mock_plugin +LoadBackend "mock_plugin" EOF diff --git a/t/integration/query_list.sh b/t/integration/query_list.sh index 28c365b..5607859 100755 --- a/t/integration/query_list.sh +++ b/t/integration/query_list.sh @@ -38,7 +38,8 @@ Listen "$SOCKET_FILE" PluginDir "$PLUGIN_DIR" Interval 2 -LoadPlugin mock_timeseries +LoadPlugin "store::memory" +LoadPlugin "mock_timeseries" EOF run_sysdbd -D -C "$SYSDBD_CONF" @@ -54,7 +55,7 @@ LoadPlugin "store::network" Server "$SOCKET_FILE" -LoadBackend mock_plugin +LoadBackend "mock_plugin" EOF diff --git a/t/integration/query_timeseries.sh b/t/integration/query_timeseries.sh index e0eb9c8..f6d09cb 100755 --- a/t/integration/query_timeseries.sh +++ b/t/integration/query_timeseries.sh @@ -38,7 +38,8 @@ Listen "$SOCKET_FILE" PluginDir "$PLUGIN_DIR" Interval 2 -LoadPlugin mock_timeseries +LoadPlugin "store::memory" +LoadPlugin "mock_timeseries" EOF run_sysdbd -D -C "$SYSDBD_CONF" @@ -54,7 +55,7 @@ LoadPlugin "store::network" Server "$SOCKET_FILE" -LoadBackend mock_plugin +LoadBackend "mock_plugin" EOF diff --git a/t/integration/ssl.sh b/t/integration/ssl.sh index cea2380..0c7177d 100755 --- a/t/integration/ssl.sh +++ b/t/integration/ssl.sh @@ -41,6 +41,8 @@ cat < "$SYSDBD_CONF" SSLCertificateKey "$SERVER_KEY" SSLCACertificates "$CA_CERT" +PluginDir "$PLUGIN_DIR" +LoadPlugin "store::memory" EOF run_sysdbd -D -C "$SYSDBD_CONF" wait_for_sysdbd_tcp localhost 12345 diff --git a/t/integration/test_lib.sh b/t/integration/test_lib.sh index fe4efe3..78aa3be 100644 --- a/t/integration/test_lib.sh +++ b/t/integration/test_lib.sh @@ -47,6 +47,7 @@ cp "$TOP_BUILDDIR/t/integration/.libs/mock_timeseries.so" "$TESTDIR" 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"