diff options
author | Adrien BĂ©raud <adrien.beraud@savoirfairelinux.com> | 2022-06-16 09:53:35 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-16 16:53:35 +0300 |
commit | 100a12c6cc01222b1518e5e50d2147f592d8a111 (patch) | |
tree | 1aa8f4a5f94f05dd10a07634e60544a523ba75fd /daemon | |
parent | 131e5f5f6e5822a1fd8107c228f1a9a49f08e847 (diff) |
Configurable storage engine for Netdata agents: step 3 (#12892)
* storage engine: add host context API
Add a new API to allow storage engines to manage host contexts.
* Replace single global context with per-engine global context
* Context is full managed by storage engines: a storage engine
can use no context, a global engine context, per host contexts,
or a mix of these.
* Currently, only dbengine uses contexts.
Following the current logic, legacy hosts use their own context,
while non-legacy hosts share the global context.
* storage engine: use empty function instead of null for context ops
* rrdhost: don't check return value for void call
* rrdhost: create context with host
* storage engine: move rrddim ops to rrddim_mem.{c,h}
* storage engine: don't use NULL for end-of-list marker
* storage engine: fallback to default engine
Diffstat (limited to 'daemon')
-rw-r--r-- | daemon/analytics.c | 3 | ||||
-rw-r--r-- | daemon/global_statistics.c | 5 | ||||
-rw-r--r-- | daemon/main.c | 21 | ||||
-rw-r--r-- | daemon/unit_test.c | 7 |
4 files changed, 27 insertions, 9 deletions
diff --git a/daemon/analytics.c b/daemon/analytics.c index 6c02561d0c..c779253485 100644 --- a/daemon/analytics.c +++ b/daemon/analytics.c @@ -2,6 +2,9 @@ #include "common.h" #include "buildinfo.h" +#ifdef ENABLE_DBENGINE +#include "database/engine/rrdengineapi.h" +#endif struct analytics_data analytics_data; extern void analytics_exporting_connectors (BUFFER *b); diff --git a/daemon/global_statistics.c b/daemon/global_statistics.c index b5740b176f..a5f7094d54 100644 --- a/daemon/global_statistics.c +++ b/daemon/global_statistics.c @@ -1,6 +1,9 @@ // SPDX-License-Identifier: GPL-3.0-or-later #include "common.h" +#ifdef ENABLE_DBENGINE +#include "database/engine/rrdengineapi.h" +#endif #define GLOBAL_STATS_RESET_WEB_USEC_MAX 0x01 @@ -456,7 +459,7 @@ static void dbengine_statistics_charts(void) { rrdhost_foreach_read(host) { if (host->rrd_memory_mode == RRD_MEMORY_MODE_DBENGINE && !rrdhost_flag_check(host, RRDHOST_FLAG_ARCHIVED)) { - if (&multidb_ctx == host->rrdeng_ctx) { + if (host->rrdeng_ctx == host->rrdeng_ctx->engine->context) { if (counted_multihost_db) continue; /* Only count multi-host DB once */ counted_multihost_db = 1; diff --git a/daemon/main.c b/daemon/main.c index 6a07add1c9..fd5a42d96c 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -3,6 +3,10 @@ #include "common.h" #include "buildinfo.h" #include "static_threads.h" +#include "database/storage_engine.h" +#ifdef ENABLE_DBENGINE +#include "database/engine/rrdengineapi.h" +#endif int netdata_zero_metrics_enabled; int netdata_anonymous_statistics_enabled; @@ -54,13 +58,18 @@ void netdata_cleanup_and_exit(int ret) { // free the database info("EXIT: freeing database memory..."); -#ifdef ENABLE_DBENGINE - rrdeng_prepare_exit(&multidb_ctx); -#endif + for (STORAGE_ENGINE* eng = storage_engine_foreach_init(); eng; eng = storage_engine_foreach_next(eng)) { + if (eng->context) + eng->api.engine_ops.exit(eng->context); + } + rrdhost_free_all(); -#ifdef ENABLE_DBENGINE - rrdeng_exit(&multidb_ctx); -#endif + for (STORAGE_ENGINE* eng = storage_engine_foreach_init(); eng; eng = storage_engine_foreach_next(eng)) { + if (eng->context) { + eng->api.engine_ops.destroy(eng->context); + eng->context = NULL; + } + } } sql_close_database(); diff --git a/daemon/unit_test.c b/daemon/unit_test.c index 35f8613a2b..2dc92dcb21 100644 --- a/daemon/unit_test.c +++ b/daemon/unit_test.c @@ -1,6 +1,9 @@ // SPDX-License-Identifier: GPL-3.0-or-later #include "common.h" +#ifdef ENABLE_DBENGINE +#include "database/engine/rrdengineapi.h" +#endif static int check_number_printing(void) { struct { @@ -1157,7 +1160,7 @@ int run_test(struct test *test) RRDSET *st = rrdset_create_localhost("netdata", name, name, "netdata", NULL, "Unit Testing", "a value", "unittest", NULL, 1 , test->update_every, RRDSET_TYPE_LINE); RRDDIM *rd = rrddim_add(st, "dim1", NULL, test->multiplier, test->divisor, test->algorithm); - + RRDDIM *rd2 = NULL; if(test->feed2) rd2 = rrddim_add(st, "dim2", NULL, test->multiplier, test->divisor, test->algorithm); @@ -1173,7 +1176,7 @@ int run_test(struct test *test) if(c) { time_now += test->feed[c].microseconds; - fprintf(stderr, " > %s: feeding position %lu, after %0.3f seconds (%0.3f seconds from start), delta " CALCULATED_NUMBER_FORMAT ", rate " CALCULATED_NUMBER_FORMAT "\n", + fprintf(stderr, " > %s: feeding position %lu, after %0.3f seconds (%0.3f seconds from start), delta " CALCULATED_NUMBER_FORMAT ", rate " CALCULATED_NUMBER_FORMAT "\n", test->name, c+1, (float)test->feed[c].microseconds / 1000000.0, (float)time_now / 1000000.0, |