Skip to content

Commit

Permalink
RRD files split, renames, cleanup Part 2 (netdata#19405)
Browse files Browse the repository at this point in the history
more splits, renames and cleanup - no functional changes
  • Loading branch information
ktsaou authored Jan 15, 2025
1 parent c03bde3 commit 78e27a8
Show file tree
Hide file tree
Showing 57 changed files with 629 additions and 564 deletions.
14 changes: 12 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1473,8 +1473,8 @@ set(RRD_PLUGIN_FILES
src/database/sqlite/vendored/sqlite3recover.c
src/database/sqlite/vendored/sqlite3recover.h
src/database/sqlite/vendored/dbdata.c
src/database/KolmogorovSmirnovDist.c
src/database/KolmogorovSmirnovDist.h
src/web/api/queries/KolmogorovSmirnovDist.c
src/web/api/queries/KolmogorovSmirnovDist.h
src/database/rrdfunctions-inflight.c
src/database/rrdfunctions-inflight.h
src/database/rrdfunctions-exporters.c
Expand Down Expand Up @@ -1503,6 +1503,16 @@ set(RRD_PLUGIN_FILES
src/database/rrddim-backfill.h
src/database/rrddim-collection.c
src/database/rrddim-collection.h
src/database/rrdset-type.c
src/database/rrdset-type.h
src/database/rrdhost-slots.c
src/database/rrdhost-slots.h
src/database/rrd-algorithm.c
src/database/rrd-algorithm.h
src/database/rrdhost-labels.c
src/database/rrdhost-labels.h
src/database/rrdhost-collection.c
src/database/rrdhost-collection.h
)

if(ENABLE_DBENGINE)
Expand Down
4 changes: 2 additions & 2 deletions src/collectors/cgroups.plugin/tests/test_doubles.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void mountinfo_free_all(struct mountinfo *mi)
RRDSET *rrdset_create_custom(
RRDHOST *host, const char *type, const char *id, const char *name, const char *family, const char *context,
const char *title, const char *units, const char *plugin, const char *module, long priority, int update_every,
RRDSET_TYPE chart_type, RRD_MEMORY_MODE memory_mode, long history_entries)
RRDSET_TYPE chart_type, RRD_DB_MODE memory_mode, long history_entries)
{
UNUSED(host);
UNUSED(type);
Expand All @@ -70,7 +70,7 @@ RRDSET *rrdset_create_custom(

RRDDIM *rrddim_add_custom(
RRDSET *st, const char *id, const char *name, collected_number multiplier, collected_number divisor,
RRD_ALGORITHM algorithm, RRD_MEMORY_MODE memory_mode)
RRD_ALGORITHM algorithm, RRD_DB_MODE memory_mode)
{
UNUSED(st);
UNUSED(id);
Expand Down
2 changes: 1 addition & 1 deletion src/collectors/statsd.plugin/statsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ typedef struct statsd_app {
const char *name;
SIMPLE_PATTERN *metrics;
STATS_METRIC_OPTIONS default_options;
RRD_MEMORY_MODE rrd_memory_mode;
RRD_DB_MODE rrd_memory_mode;
int32_t rrd_history_entries;
DICTIONARY *dict;

Expand Down
8 changes: 4 additions & 4 deletions src/daemon/config/netdata-conf-db.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ static void netdata_conf_dbengine_pre_logs(void) {
// }

#else
if (default_rrd_memory_mode == RRD_MEMORY_MODE_DBENGINE) {
error_report("RRD_MEMORY_MODE_DBENGINE is not supported in this platform. The agent will use db mode 'save' instead.");
default_rrd_memory_mode = RRD_MEMORY_MODE_RAM;
if (default_rrd_memory_mode == RRD_DB_MODE_DBENGINE) {
error_report("RRD_DB_MODE_DBENGINE is not supported in this platform. The agent will use db mode 'save' instead.");
default_rrd_memory_mode = RRD_DB_MODE_RAM;
}
#endif
}
Expand Down Expand Up @@ -381,7 +381,7 @@ void netdata_conf_section_db(void) {
// ------------------------------------------------------------------------
// get default database size

if(default_rrd_memory_mode != RRD_MEMORY_MODE_DBENGINE && default_rrd_memory_mode != RRD_MEMORY_MODE_NONE) {
if(default_rrd_memory_mode != RRD_DB_MODE_DBENGINE && default_rrd_memory_mode != RRD_DB_MODE_NONE) {
default_rrd_history_entries = (int)config_get_duration_seconds(
CONFIG_SECTION_DB, "retention",
align_entries_to_pagesize(default_rrd_memory_mode, RRD_DEFAULT_HISTORY_ENTRIES));
Expand Down
2 changes: 1 addition & 1 deletion src/daemon/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ int unittest_prepare_rrd(const char **user) {
netdata_conf_section_global_run_as_user(user);
netdata_conf_section_global();
nd_profile.update_every = 1;
default_rrd_memory_mode = RRD_MEMORY_MODE_RAM;
default_rrd_memory_mode = RRD_DB_MODE_RAM;
health_plugin_disable();
nd_profile.storage_tiers = 1;
registry_init();
Expand Down
2 changes: 1 addition & 1 deletion src/daemon/pulse/pulse-db-dbengine.c
Original file line number Diff line number Diff line change
Expand Up @@ -1490,7 +1490,7 @@ void pulse_dbengine_do(bool extended) {

/* get localhost's DB engine's statistics for each tier */
for(size_t tier = 0; tier < nd_profile.storage_tiers;tier++) {
if(host->db[tier].mode != RRD_MEMORY_MODE_DBENGINE) continue;
if(host->db[tier].mode != RRD_DB_MODE_DBENGINE) continue;
if(!host->db[tier].si) continue;

if(counted_multihost_db[tier])
Expand Down
2 changes: 1 addition & 1 deletion src/daemon/service.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ static void svc_rrddim_obsolete_to_archive(RRDDIM *rd) {
rrddim_flag_set(rd, RRDDIM_FLAG_ARCHIVED);
rrddim_flag_clear(rd, RRDDIM_FLAG_OBSOLETE);

if (rd->rrd_memory_mode == RRD_MEMORY_MODE_DBENGINE) {
if (rd->rrd_memory_mode == RRD_DB_MODE_DBENGINE) {
/* only a collector can mark a chart as obsolete, so we must remove the reference */
if (!rrddim_finalize_collection_and_check_retention(rd)) {
/* This metric has no data and no references */
Expand Down
4 changes: 2 additions & 2 deletions src/daemon/unit_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -1268,7 +1268,7 @@ int run_test(struct test *test)
{
fprintf(stderr, "\nRunning test '%s':\n%s\n", test->name, test->description);

default_rrd_memory_mode = RRD_MEMORY_MODE_ALLOC;
default_rrd_memory_mode = RRD_DB_MODE_ALLOC;
nd_profile.update_every = test->update_every;

char name[101];
Expand Down Expand Up @@ -1537,7 +1537,7 @@ int unit_test(long delay, long shift)
snprintfz(name, sizeof(name) - 1, "unittest-%d-%ld-%ld", repeat, delay, shift);

//debug_flags = 0xffffffff;
default_rrd_memory_mode = RRD_MEMORY_MODE_ALLOC;
default_rrd_memory_mode = RRD_DB_MODE_ALLOC;
nd_profile.update_every = 1;

int do_abs = 1;
Expand Down
2 changes: 1 addition & 1 deletion src/database/contexts/contexts-loading.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ void rrdhost_load_rrdcontext_data(RRDHOST *host) {
if(host->rrdctx.contexts) return;

rrdhost_create_rrdcontexts(host);
if (host->rrd_memory_mode != RRD_MEMORY_MODE_DBENGINE)
if (host->rrd_memory_mode != RRD_DB_MODE_DBENGINE)
return;

ignored_metrics = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/database/contexts/worker.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ void rrdcontext_delete_from_sql_unsafe(RRDCONTEXT *rc) {
rc->hub.units = string2str(rc->units);
rc->hub.family = string2str(rc->family);

if (rc->rrdhost->rrd_memory_mode != RRD_MEMORY_MODE_DBENGINE)
if (rc->rrdhost->rrd_memory_mode != RRD_DB_MODE_DBENGINE)
return;

// delete it from SQL
Expand Down Expand Up @@ -762,7 +762,7 @@ void rrdcontext_message_send_unsafe(RRDCONTEXT *rc, bool snapshot __maybe_unused
rrdcontext_delete_from_sql_unsafe(rc);

else {
if (rc->rrdhost->rrd_memory_mode != RRD_MEMORY_MODE_DBENGINE)
if (rc->rrdhost->rrd_memory_mode != RRD_DB_MODE_DBENGINE)
return;
if (ctx_store_context(&rc->rrdhost->host_id.uuid, &rc->hub) != 0)
netdata_log_error(
Expand Down
6 changes: 3 additions & 3 deletions src/database/engine/dbengine-stresstest.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ static RRDHOST *dbengine_rrdhost_find_or_create(char *name) {
NETDATA_VERSION,
nd_profile.update_every,
default_rrd_history_entries,
RRD_MEMORY_MODE_DBENGINE,
RRD_DB_MODE_DBENGINE,
health_plugin_enabled(),
stream_send.enabled,
stream_send.parents.destination,
Expand Down Expand Up @@ -140,7 +140,7 @@ void generate_dbengine_dataset(unsigned history_seconds)
int i;
time_t time_present;

default_rrd_memory_mode = RRD_MEMORY_MODE_DBENGINE;
default_rrd_memory_mode = RRD_DB_MODE_DBENGINE;
default_rrdeng_page_cache_mb = 128;
// Worst case for uncompressible data
default_rrdeng_disk_quota_mb = (((uint64_t)DSET_DIMS * DSET_CHARTS) * sizeof(storage_number) * history_seconds) /
Expand Down Expand Up @@ -333,7 +333,7 @@ void dbengine_stress_test(unsigned TEST_DURATION_SEC, unsigned DSET_CHARTS, unsi
if (PAGE_CACHE_MB < RRDENG_MIN_PAGE_CACHE_SIZE_MB)
PAGE_CACHE_MB = RRDENG_MIN_PAGE_CACHE_SIZE_MB;

default_rrd_memory_mode = RRD_MEMORY_MODE_DBENGINE;
default_rrd_memory_mode = RRD_DB_MODE_DBENGINE;
default_rrdeng_page_cache_mb = PAGE_CACHE_MB;
if (DISK_SPACE_MB) {
fprintf(stderr, "By setting disk space limit data are allowed to be deleted. "
Expand Down
4 changes: 2 additions & 2 deletions src/database/engine/dbengine-unittest.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ static RRDHOST *dbengine_rrdhost_find_or_create(char *name) {
NETDATA_VERSION,
nd_profile.update_every,
default_rrd_history_entries,
RRD_MEMORY_MODE_DBENGINE,
RRD_DB_MODE_DBENGINE,
health_plugin_enabled(),
stream_send.enabled,
stream_send.parents.destination,
Expand Down Expand Up @@ -362,7 +362,7 @@ int test_dbengine(void) {
nd_log_limits_unlimited();
fprintf(stderr, "\nRunning DB-engine test\n");

default_rrd_memory_mode = RRD_MEMORY_MODE_DBENGINE;
default_rrd_memory_mode = RRD_DB_MODE_DBENGINE;
fprintf(stderr, "Initializing localhost with hostname 'unittest-dbengine'");
RRDHOST *host = dbengine_rrdhost_find_or_create("unittest-dbengine");
if(!host)
Expand Down
37 changes: 37 additions & 0 deletions src/database/rrd-algorithm.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// SPDX-License-Identifier: GPL-3.0-or-later

#include "rrd-algorithm.h"

RRD_ALGORITHM rrd_algorithm_id(const char *name) {
if(strcmp(name, RRD_ALGORITHM_INCREMENTAL_NAME) == 0)
return RRD_ALGORITHM_INCREMENTAL;

else if(strcmp(name, RRD_ALGORITHM_ABSOLUTE_NAME) == 0)
return RRD_ALGORITHM_ABSOLUTE;

else if(strcmp(name, RRD_ALGORITHM_PCENT_OVER_ROW_TOTAL_NAME) == 0)
return RRD_ALGORITHM_PCENT_OVER_ROW_TOTAL;

else if(strcmp(name, RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL_NAME) == 0)
return RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL;

else
return RRD_ALGORITHM_ABSOLUTE;
}

const char *rrd_algorithm_name(RRD_ALGORITHM algorithm) {
switch(algorithm) {
case RRD_ALGORITHM_ABSOLUTE:
default:
return RRD_ALGORITHM_ABSOLUTE_NAME;

case RRD_ALGORITHM_INCREMENTAL:
return RRD_ALGORITHM_INCREMENTAL_NAME;

case RRD_ALGORITHM_PCENT_OVER_ROW_TOTAL:
return RRD_ALGORITHM_PCENT_OVER_ROW_TOTAL_NAME;

case RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL:
return RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL_NAME;
}
}
26 changes: 26 additions & 0 deletions src/database/rrd-algorithm.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// SPDX-License-Identifier: GPL-3.0-or-later

#ifndef NETDATA_RRD_ALGORITHM_H
#define NETDATA_RRD_ALGORITHM_H

#include "libnetdata/libnetdata.h"

typedef enum __attribute__ ((__packed__)) rrd_algorithm {
RRD_ALGORITHM_ABSOLUTE = 0,
RRD_ALGORITHM_INCREMENTAL = 1,
RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL = 2,
RRD_ALGORITHM_PCENT_OVER_ROW_TOTAL = 3,

// this is 8-bit
} RRD_ALGORITHM;

#define RRD_ALGORITHM_ABSOLUTE_NAME "absolute"
#define RRD_ALGORITHM_INCREMENTAL_NAME "incremental"
#define RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL_NAME "percentage-of-incremental-row"
#define RRD_ALGORITHM_PCENT_OVER_ROW_TOTAL_NAME "percentage-of-absolute-row"

RRD_ALGORITHM rrd_algorithm_id(const char *name);
const char *rrd_algorithm_name(RRD_ALGORITHM algorithm);


#endif //NETDATA_RRD_ALGORITHM_H
24 changes: 12 additions & 12 deletions src/database/rrd-database-mode.c
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@

#include "rrd.h"

inline const char *rrd_memory_mode_name(RRD_MEMORY_MODE id) {
inline const char *rrd_memory_mode_name(RRD_DB_MODE id) {
switch(id) {
case RRD_MEMORY_MODE_RAM:
return RRD_MEMORY_MODE_RAM_NAME;
case RRD_DB_MODE_RAM:
return RRD_DB_MODE_RAM_NAME;

case RRD_MEMORY_MODE_NONE:
return RRD_MEMORY_MODE_NONE_NAME;
case RRD_DB_MODE_NONE:
return RRD_DB_MODE_NONE_NAME;

case RRD_MEMORY_MODE_ALLOC:
return RRD_MEMORY_MODE_ALLOC_NAME;
case RRD_DB_MODE_ALLOC:
return RRD_DB_MODE_ALLOC_NAME;

case RRD_MEMORY_MODE_DBENGINE:
return RRD_MEMORY_MODE_DBENGINE_NAME;
case RRD_DB_MODE_DBENGINE:
return RRD_DB_MODE_DBENGINE_NAME;
}

STORAGE_ENGINE* eng = storage_engine_get(id);
if (eng) {
return eng->name;
}

return RRD_MEMORY_MODE_RAM_NAME;
return RRD_DB_MODE_RAM_NAME;
}

RRD_MEMORY_MODE rrd_memory_mode_id(const char *name) {
RRD_DB_MODE rrd_memory_mode_id(const char *name) {
STORAGE_ENGINE* eng = storage_engine_find(name);
if (eng) {
return eng->id;
}

return RRD_MEMORY_MODE_RAM;
return RRD_DB_MODE_RAM;
}
24 changes: 12 additions & 12 deletions src/database/rrd-database-mode.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@
#define NETDATA_RRD_DATABASE_MODE_H

typedef enum __attribute__ ((__packed__)) rrd_memory_mode {
RRD_MEMORY_MODE_NONE = 0,
RRD_MEMORY_MODE_RAM = 1,
RRD_MEMORY_MODE_ALLOC = 4,
RRD_MEMORY_MODE_DBENGINE = 5,
RRD_DB_MODE_NONE = 0,
RRD_DB_MODE_RAM = 1,
RRD_DB_MODE_ALLOC = 4,
RRD_DB_MODE_DBENGINE = 5,

// this is 8-bit
} RRD_MEMORY_MODE;
} RRD_DB_MODE;

#define RRD_MEMORY_MODE_NONE_NAME "none"
#define RRD_MEMORY_MODE_RAM_NAME "ram"
#define RRD_MEMORY_MODE_ALLOC_NAME "alloc"
#define RRD_MEMORY_MODE_DBENGINE_NAME "dbengine"
#define RRD_DB_MODE_NONE_NAME "none"
#define RRD_DB_MODE_RAM_NAME "ram"
#define RRD_DB_MODE_ALLOC_NAME "alloc"
#define RRD_DB_MODE_DBENGINE_NAME "dbengine"

extern RRD_MEMORY_MODE default_rrd_memory_mode;
extern RRD_DB_MODE default_rrd_memory_mode;

const char *rrd_memory_mode_name(RRD_MEMORY_MODE id);
RRD_MEMORY_MODE rrd_memory_mode_id(const char *name);
const char *rrd_memory_mode_name(RRD_DB_MODE id);
RRD_DB_MODE rrd_memory_mode_id(const char *name);

#endif //NETDATA_RRD_DATABASE_MODE_H
Loading

0 comments on commit 78e27a8

Please sign in to comment.