summaryrefslogtreecommitdiffstats
path: root/database
diff options
context:
space:
mode:
authorCosta Tsaousis <costa@netdata.cloud>2022-09-05 19:31:06 +0300
committerGitHub <noreply@github.com>2022-09-05 19:31:06 +0300
commit5e1b95cf92168c4df74586fb4430dc284806da82 (patch)
treef42077d8b02eaf316683453a7474bd1f599a833d /database
parent544aef1fde6e79ac57d2dea85d3f063076d7f885 (diff)
Deduplicate all netdata strings (#13570)
* rrdfamily * rrddim * rrdset plugin and module names * rrdset units * rrdset type * rrdset family * rrdset title * rrdset title more * rrdset context * rrdcalctemplate context and removal of context hash from rrdset * strings statistics * rrdset name * rearranged members of rrdset * eliminate rrdset name hash; rrdcalc chart converted to STRING * rrdset id, eliminated rrdset hash * rrdcalc, alarm_entry, alert_config and some of rrdcalctemplate * rrdcalctemplate * rrdvar * eval_variable * rrddimvar and rrdsetvar * rrdhost hostname, os and tags * fix master commits * added thread cache; implemented string_dup without locks * faster thread cache * rrdset and rrddim now use dictionaries for indexing * rrdhost now uses dictionary * rrdfamily now uses DICTIONARY * rrdvar using dictionary instead of AVL * allocate the right size to rrdvar flag members * rrdhost remaining char * members to STRING * * better error handling on indexing * strings now use a read/write lock to allow parallel searches to the index * removed AVL support from dictionaries; implemented STRING with native Judy calls * string releases should be negative * only 31 bits are allowed for enum flags * proper locking on strings * string threading unittest and fixes * fix lgtm finding * fixed naming * stream chart/dimension definitions at the beginning of a streaming session * thread stack variable is undefined on thread cancel * rrdcontext garbage collect per host on startup * worker control in garbage collection * relaxed deletion of rrdmetrics * type checking on dictfe * netdata chart to monitor rrdcontext triggers * Group chart label updates * rrdcontext better handling of collected rrdsets * rrdpush incremental transmition of definitions should use as much buffer as possible * require 1MB per chart * empty the sender buffer before enabling metrics streaming * fill up to 50% of buffer * reset signaling metrics sending * use the shared variable for status * use separate host flag for enabling streaming of metrics * make sure the flag is clear * add logging for streaming * add logging for streaming on buffer overflow * circular_buffer proper sizing * removed obsolete logs * do not execute worker jobs if not necessary * better messages about compression disabling * proper use of flags and updating rrdset last access time every time the obsoletion flag is flipped * monitor stream sender used buffer ratio * Update exporting unit tests * no need to compare label value with strcmp * streaming send workers now monitor bandwidth * workers now use strings * streaming receiver monitors incoming bandwidth * parser shift of worker ids * minor fixes * Group chart label updates * Populate context with dimensions that have data * Fix chart id * better shift of parser worker ids * fix for streaming compression * properly count received bytes * ensure LZ4 compression ring buffer does not wrap prematurely * do not stream empty charts; do not process empty instances in rrdcontext * need_to_send_chart_definition() does not need an rrdset lock any more * rrdcontext objects are collected, after data have been written to the db * better logging of RRDCONTEXT transitions * always set all variables needed by the worker utilization charts * implemented double linked list for most objects; eliminated alarm indexes from rrdhost; and many more fixes * lockless strings design - string_dup() and string_freez() are totally lockless when they dont need to touch Judy - only Judy is protected with a read/write lock * STRING code re-organization for clarity * thread_cache improvements; double numbers precision on worker threads * STRING_ENTRY now shadown STRING, so no duplicate definition is required; string_length() renamed to string_strlen() to follow the paradigm of all other functions, STRING internal statistics are now only compiled with NETDATA_INTERNAL_CHECKS * rrdhost index by hostname now cleans up; aclk queries of archieved hosts do not index hosts * Add index to speed up database context searches * Removed last_updated optimization (was also buggy after latest merge with master) Co-authored-by: Stelios Fragkakis <52996999+stelfrag@users.noreply.github.com> Co-authored-by: Vladimir Kobal <vlad@prokk.net>
Diffstat (limited to 'database')
-rwxr-xr-xdatabase/engine/metadata_log/metalogpluginsd.c4
-rwxr-xr-xdatabase/engine/rrdengineapi.c5
-rw-r--r--database/ram/rrddim_mem.c8
-rw-r--r--database/rrd.c12
-rw-r--r--database/rrd.h349
-rw-r--r--database/rrdcalc.c454
-rw-r--r--database/rrdcalc.h142
-rw-r--r--database/rrdcalctemplate.c75
-rw-r--r--database/rrdcalctemplate.h58
-rw-r--r--database/rrdcontext.c444
-rw-r--r--database/rrddim.c183
-rw-r--r--database/rrddimvar.c119
-rw-r--r--database/rrddimvar.h23
-rw-r--r--database/rrdfamily.c46
-rw-r--r--database/rrdhost.c425
-rw-r--r--database/rrdlabels.c24
-rw-r--r--database/rrdset.c449
-rw-r--r--database/rrdsetvar.c74
-rw-r--r--database/rrdsetvar.h8
-rw-r--r--database/rrdvar.c150
-rw-r--r--database/rrdvar.h27
-rw-r--r--database/sqlite/sqlite_aclk.c26
-rw-r--r--database/sqlite/sqlite_aclk.h16
-rw-r--r--database/sqlite/sqlite_aclk_alert.c56
-rw-r--r--database/sqlite/sqlite_aclk_chart.c55
-rw-r--r--database/sqlite/sqlite_aclk_node.c16
-rw-r--r--database/sqlite/sqlite_context.c1
-rw-r--r--database/sqlite/sqlite_functions.c169
-rw-r--r--database/sqlite/sqlite_health.c195
29 files changed, 1698 insertions, 1915 deletions
diff --git a/database/engine/metadata_log/metalogpluginsd.c b/database/engine/metadata_log/metalogpluginsd.c
index a5301bc108..dcf2deb7d2 100755
--- a/database/engine/metadata_log/metalogpluginsd.c
+++ b/database/engine/metadata_log/metalogpluginsd.c
@@ -12,11 +12,11 @@ PARSER_RC metalog_pluginsd_host_action(
{
struct metalog_pluginsd_state *state = ((PARSER_USER_OBJECT *)user)->private;
- RRDHOST *host = rrdhost_find_by_guid(machine_guid, 0);
+ RRDHOST *host = rrdhost_find_by_guid(machine_guid);
if (host) {
if (unlikely(host->rrd_memory_mode != RRD_MEMORY_MODE_DBENGINE)) {
error("Archived host '%s' has memory mode '%s', but the archived one is '%s'. Ignoring archived state.",
- host->hostname, rrd_memory_mode_name(host->rrd_memory_mode),
+ rrdhost_hostname(host), rrd_memory_mode_name(host->rrd_memory_mode),
rrd_memory_mode_name(RRD_MEMORY_MODE_DBENGINE));
((PARSER_USER_OBJECT *) user)->host = NULL; /* Ignore objects if memory mode is not dbengine */
}
diff --git a/database/engine/rrdengineapi.c b/database/engine/rrdengineapi.c
index f4da294079..5acab14d3b 100755
--- a/database/engine/rrdengineapi.c
+++ b/database/engine/rrdengineapi.c
@@ -98,7 +98,7 @@ STORAGE_METRIC_HANDLE *rrdeng_metric_init(RRDDIM *rd, STORAGE_INSTANCE *db_insta
pg_cache = &ctx->pg_cache;
- rrdeng_generate_legacy_uuid(rd->id, rd->rrdset->id, &legacy_uuid);
+ rrdeng_generate_legacy_uuid(rrddim_id(rd), (char *)rrdset_id(rd->rrdset), &legacy_uuid);
if (host != localhost && is_storage_engine_shared((STORAGE_INSTANCE *)ctx))
is_multihost_child = 1;
@@ -138,8 +138,7 @@ STORAGE_METRIC_HANDLE *rrdeng_metric_init(RRDDIM *rd, STORAGE_INSTANCE *db_insta
uuid_copy(rd->metric_uuid, multihost_legacy_uuid);
if (unlikely(need_to_store && !ctx->tier))
- (void)sql_store_dimension(&rd->metric_uuid, rd->rrdset->chart_uuid, rd->id, rd->name, rd->multiplier, rd->divisor,
- rd->algorithm);
+ (void)sql_store_dimension(&rd->metric_uuid, rd->rrdset->chart_uuid, rrddim_id(rd), rrddim_name(rd), rd->multiplier, rd->divisor, rd->algorithm);
}
struct rrdeng_metric_handle *mh = mallocz(sizeof(struct rrdeng_metric_handle));
diff --git a/database/ram/rrddim_mem.c b/database/ram/rrddim_mem.c
index 3226d3c0de..139f997c93 100644
--- a/database/ram/rrddim_mem.c
+++ b/database/ram/rrddim_mem.c
@@ -91,7 +91,7 @@ static inline size_t rrddim_time2slot(RRDDIM *rd, time_t t) {
}
if(unlikely(ret >= entries)) {
- error("INTERNAL ERROR: rrddim_time2slot() on %s returns values outside entries", rd->name);
+ error("INTERNAL ERROR: rrddim_time2slot() on %s returns values outside entries", rrddim_name(rd));
ret = entries - 1;
}
@@ -119,12 +119,12 @@ static inline time_t rrddim_slot2time(RRDDIM *rd, size_t slot) {
ret = last_entry_t - (time_t)(update_every * (last_slot - slot));
if(unlikely(ret < first_entry_t)) {
- error("INTERNAL ERROR: rrddim_slot2time() on %s returns time too far in the past", rd->name);
+ error("INTERNAL ERROR: rrddim_slot2time() on %s returns time too far in the past", rrddim_name(rd));
ret = first_entry_t;
}
if(unlikely(ret > last_entry_t)) {
- error("INTERNAL ERROR: rrddim_slot2time() on %s returns time into the future", rd->name);
+ error("INTERNAL ERROR: rrddim_slot2time() on %s returns time into the future", rrddim_name(rd));
ret = last_entry_t;
}
@@ -206,7 +206,7 @@ int rrddim_query_is_finished(struct rrddim_query_handle *handle) {
void rrddim_query_finalize(struct rrddim_query_handle *handle) {
#ifdef NETDATA_INTERNAL_CHECKS
if(!rrddim_query_is_finished(handle))
- error("QUERY: query for chart '%s' dimension '%s' has been stopped unfinished", handle->rd->rrdset->id, handle->rd->name);
+ error("QUERY: query for chart '%s' dimension '%s' has been stopped unfinished", rrdset_id(handle->rd->rrdset), rrddim_name(handle->rd));
#endif
freez(handle->handle);
}
diff --git a/database/rrd.c b/database/rrd.c
index f91039ea57..df364419ea 100644
--- a/database/rrd.c
+++ b/database/rrd.c
@@ -154,3 +154,15 @@ char *rrdset_cache_dir(RRDHOST *host, const char *id) {
return ret;
}
+// ----------------------------------------------------------------------------
+// RRD - string management
+
+STRING *rrd_string_strdupz(const char *s) {
+ if(unlikely(!s || !*s)) return string_strdupz(s);
+
+ char *tmp = strdupz(s);
+ json_fix_string(tmp);
+ STRING *ret = string_strdupz(tmp);
+ freez(tmp);
+ return ret;
+}
diff --git a/database/rrd.h b/database/rrd.h
index f8919e83a5..36c4e5d58f 100644
--- a/database/rrd.h
+++ b/database/rrd.h
@@ -160,14 +160,10 @@ extern const char *rrd_algorithm_name(RRD_ALGORITHM algorithm);
// RRD FAMILY
struct rrdfamily {
- avl_t avl;
-
- const char *family;
- uint32_t hash_family;
+ STRING *family;
+ DICTIONARY *rrdvar_root_index;
size_t use_count;
-
- avl_tree_lock rrdvar_root_index;
};
typedef struct rrdfamily RRDFAMILY;
@@ -190,6 +186,7 @@ typedef enum rrddim_flags {
RRDDIM_FLAG_PENDING_FOREACH_ALARM = (1 << 5), // set when foreach alarm has not been initialized yet
RRDDIM_FLAG_META_HIDDEN = (1 << 6), // Status of hidden option in the metadata database
+ RRDDIM_FLAG_INDEXED_ID = (1 << 7),
} RRDDIM_FLAGS;
#define rrddim_flag_check(rd, flag) (__atomic_load_n(&((rd)->flags), __ATOMIC_SEQ_CST) & (flag))
@@ -244,27 +241,13 @@ extern bool exporting_labels_filter_callback(const char *name, const char *value
// RRD DIMENSION - this is a metric
struct rrddim {
- // ------------------------------------------------------------------------
- // binary indexing structures
-
- avl_t avl; // the binary index - this has to be first member!
-
uuid_t metric_uuid; // global UUID for this metric (unique_across hosts)
// ------------------------------------------------------------------------
// the dimension definition
- const char *id; // the id of this dimension (for internal identification)
- const char *name; // the name of this dimension (as presented to user)
- // this is a pointer to the config structure
- // since the config always has a higher priority
- // (the user overwrites the name of the charts)
- uint32_t hash; // a simple hash of the id, to speed up searching / indexing
- // instead of strcmp() every item in the binary index
- // we first compare the hashes
- uint32_t hash_name; // a simple hash of the name
-
-
+ STRING *id; // the id of this dimension (for internal identification)
+ STRING *name; // the name of this dimension (as presented to user)
RRD_ALGORITHM algorithm; // the algorithm that is applied to add new collected values
RRD_MEMORY_MODE rrd_memory_mode; // the memory mode for this dimension
RRDDIM_FLAGS flags; // configuration flags for the dimension
@@ -305,6 +288,8 @@ struct rrddim {
NETDATA_DOUBLE stored_volume; // the sum of all stored values so far
struct rrddim *next; // linking of dimensions within the same data set
+ struct rrddim *prev; // linking of dimensions within the same data set
+
struct rrdset *rrdset;
RRDMETRIC_ACQUIRED *rrdmetric; // the rrdmetric of this dimension
@@ -328,6 +313,9 @@ struct rrddim {
storage_number *db; // the array of values
};
+#define rrddim_id(rd) string2str((rd)->id)
+#define rrddim_name(rd) string2str((rd) ->name)
+
// returns the RRDDIM cache filename, or NULL if it does not exist
extern const char *rrddim_cache_filename(RRDDIM *rd);
@@ -459,9 +447,6 @@ extern void rrdr_fill_tier_gap_from_smaller_tiers(RRDDIM *rd, int tier, time_t n
// ----------------------------------------------------------------------------
// volatile state per chart
struct rrdset_volatile {
- char *old_title;
- char *old_units;
- char *old_context;
uuid_t hash_id;
DICTIONARY *chart_labels;
bool is_ar_chart;
@@ -485,88 +470,75 @@ struct rrdset_volatile {
// and may lead to missing information.
typedef enum rrdset_flags {
- RRDSET_FLAG_DETAIL = 1 << 1, // if set, the data set should be considered as a detail of another
- // (the master data set should be the one that has the same family and is not detail)
- RRDSET_FLAG_DEBUG = 1 << 2, // enables or disables debugging for a chart
- RRDSET_FLAG_OBSOLETE = 1 << 3, // this is marked by the collector/module as obsolete
- RRDSET_FLAG_EXPORTING_SEND = 1 << 4, // if set, this chart should be sent to Prometheus web API and external databases
- RRDSET_FLAG_EXPORTING_IGNORE = 1 << 5, // if set, this chart should not be sent to Prometheus web API and external databases
- RRDSET_FLAG_UPSTREAM_SEND = 1 << 6, // if set, this chart should be sent upstream (streaming)
- RRDSET_FLAG_UPSTREAM_IGNORE = 1 << 7, // if set, this chart should not be sent upstream (streaming)
- RRDSET_FLAG_UPSTREAM_EXPOSED = 1 << 8, // if set, we have sent this chart definition to netdata parent (streaming)
- RRDSET_FLAG_STORE_FIRST = 1 << 9, // if set, do not eliminate the first collection during interpolation
- RRDSET_FLAG_HETEROGENEOUS = 1 << 10, // if set, the chart is not homogeneous (dimensions in it have multiple algorithms, multipliers or dividers)
- RRDSET_FLAG_HOMOGENEOUS_CHECK = 1 << 11, // if set, the chart should be checked to determine if the dimensions are homogeneous
- RRDSET_FLAG_HIDDEN = 1 << 12, // if set, do not show this chart on the dashboard, but use it for exporting
- RRDSET_FLAG_SYNC_CLOCK = 1 << 13, // if set, microseconds on next data collection will be ignored (the chart will be synced to now)
- RRDSET_FLAG_OBSOLETE_DIMENSIONS = 1 << 14, // this is marked by the collector/module when a chart has obsolete dimensions
- // No new values have been collected for this chart since agent start or it was marked RRDSET_FLAG_OBSOLETE at
- // least rrdset_free_obsolete_time seconds ago.
- RRDSET_FLAG_ARCHIVED = 1 << 15,
- RRDSET_FLAG_ACLK = 1 << 16,
- RRDSET_FLAG_PENDING_FOREACH_ALARMS = 1 << 17, // contains dims with uninitialized foreach alarms
- RRDSET_FLAG_ANOMALY_DETECTION = 1 << 18 // flag to identify anomaly detection charts.
+ RRDSET_FLAG_DETAIL = (1 << 1), // if set, the data set should be considered as a detail of another
+ // (the master data set should be the one that has the same family and is not detail)
+ RRDSET_FLAG_DEBUG = (1 << 2), // enables or disables debugging for a chart
+ RRDSET_FLAG_OBSOLETE = (1 << 3), // this is marked by the collector/module as obsolete
+ RRDSET_FLAG_EXPORTING_SEND = (1 << 4), // if set, this chart should be sent to Prometheus web API and external databases
+ RRDSET_FLAG_EXPORTING_IGNORE = (1 << 5), // if set, this chart should not be sent to Prometheus web API and external databases
+ RRDSET_FLAG_UPSTREAM_SEND = (1 << 6), // if set, this chart should be sent upstream (streaming)
+ RRDSET_FLAG_UPSTREAM_IGNORE = (1 << 7), // if set, this chart should not be sent upstream (streaming)
+ RRDSET_FLAG_UPSTREAM_EXPOSED = (1 << 8), // if set, we have sent this chart definition to netdata parent (streaming)
+ RRDSET_FLAG_STORE_FIRST = (1 << 9), // if set, do not eliminate the first collection during interpolation
+ RRDSET_FLAG_HETEROGENEOUS = (1 << 10), // if set, the chart is not homogeneous (dimensions in it have multiple algorithms, multipliers or dividers)
+ RRDSET_FLAG_HOMOGENEOUS_CHECK = (1 << 11), // if set, the chart should be checked to determine if the dimensions are homogeneous
+ RRDSET_FLAG_HIDDEN = (1 << 12), // if set, do not show this chart on the dashboard, but use it for exporting
+ RRDSET_FLAG_SYNC_CLOCK = (1 << 13), // if set, microseconds on next data collection will be ignored (the chart will be synced to now)
+ RRDSET_FLAG_OBSOLETE_DIMENSIONS = (1 << 14), // this is marked by the collector/module when a chart has obsolete dimensions
+ // No new values have been collected for this chart since agent start or it was marked RRDSET_FLAG_OBSOLETE at
+ // least rrdset_free_obsolete_time seconds ago.
+ RRDSET_FLAG_ARCHIVED = (1 << 15),
+ RRDSET_FLAG_ACLK = (1 << 16),
+ RRDSET_FLAG_PENDING_FOREACH_ALARMS = (1 << 17), // contains dims with uninitialized foreach alarms
+ RRDSET_FLAG_ANOMALY_DETECTION = (1 << 18), // flag to identify anomaly detection charts.
+ RRDSET_FLAG_INDEXED_ID = (1 << 19),
+ RRDSET_FLAG_INDEXED_NAME = (1 << 20),
} RRDSET_FLAGS;
#define rrdset_flag_check(st, flag) (__atomic_load_n(&((st)->flags), __ATOMIC_SEQ_CST) & (flag))
#define rrdset_flag_set(st, flag) __atomic_or_fetch(&((st)->flags), flag, __ATOMIC_SEQ_CST)
-#define rrdset_flag_clear(st, flag) __atomic_and_fetch(&((st)->flags), ~flag, __ATOMIC_SEQ_CST)
+#define rrdset_flag_clear(st, flag) __atomic_and_fetch(&((st)->flags), ~(flag), __ATOMIC_SEQ_CST)
struct rrdset {
// ------------------------------------------------------------------------
- // binary indexing structures
-
- avl_t avl; // the index, with key the id - this has to be first!
- avl_t avlname; // the index, with key the name
-
- // ------------------------------------------------------------------------
// the set configuration
- char id[RRD_ID_LENGTH_MAX + 1]; // id of the data set
-
- const char *name; // the name of this dimension (as presented to user)
- // this is a pointer to the config structure
- // since the config always has a higher priority
- // (the user overwrites the name of the charts)
-
- char *type; // the type of graph RRD_TYPE_* (a category, for determining graphing options)
- char *family; // grouping sets under the same family
- char *title; // title shown to user
- char *units; // units of measurement
-
- char *context; // the template of this data set
- uint32_t hash_context; // the hash of the chart's context
+ STRING *id; // the ID of the data set
+ STRING *name; // the name of this dimension (as presented to user)
+ STRING *type; // the type of graph RRD_TYPE_* (a category, for determining graphing options)
+ STRING *family; // grouping sets under the same family
+ STRING *title; // title shown to user
+ STRING *units; // units of measurement
+ STRING *context; // the template of this data set
+ STRING *plugin_name; // the name of the plugin that generated this
+ STRING *module_name; // the name of the plugin module that generated this
RRDINSTANCE_ACQUIRED *rrdinstance; // the rrdinstance of this chart
RRDCONTEXT_ACQUIRED *rrdcontext; // the rrdcontext this chart belongs to
+ RRD_MEMORY_MODE rrd_memory_mode; // the db mode of this rrdset
RRDSET_TYPE chart_type; // line, area, stacked
+ RRDSET_FLAGS flags; // configuration flags
+ RRDSET_FLAGS *exporting_flags; // array of flags for exporting connector instances
int update_every; // every how many seconds is this updated?
+ int gap_when_lost_iterations_above; // after how many lost iterations a gap should be stored
+ // netdata will interpolate values for gaps lower than this
+
long entries; // total number of entries in the data set
long current_entry; // the entry that is currently being updated
// it goes around in a round-robin fashion
- RRDSET_FLAGS flags; // configuration flags
- RRDSET_FLAGS *exporting_flags; // array of flags for exporting connector instances
-
- int gap_when_lost_iterations_above; // after how many lost iterations a gap should be stored
- // netdata will interpolate values for gaps lower than this
-
long priority; // the sorting priority of this chart
// ------------------------------------------------------------------------
// members for temporary data we need for calculations
- RRD_MEMORY_MODE rrd_memory_mode; // if set to 1, this is memory mapped
-
char *cache_dir; // the directory to store dimensions
- netdata_rwlock_t rrdset_rwlock; // protects dimensions linked list
-
size_t counter; // the number of times we added values to this database
size_t counter_done; // the number of times rrdset_done() has been called
@@ -576,19 +548,12 @@ struct rrdset {
};
time_t upstream_resync_time; // the timestamp up to which we should resync clock upstream
- char *plugin_name; // the name of the plugin that generated this
- char *module_name; // the name of the plugin module that generated this
uuid_t *chart_uuid; // Store the global GUID for this chart
// this object.
struct rrdset_volatile *state; // volatile state that is not persistently stored
size_t rrddim_page_alignment; // keeps metric pages in alignment when using dbengine
- uint32_t hash; // a simple hash on the id, to speed up searching
- // we first compare hashes, and only if the hashes are equal we do string comparisons
-
- uint32_t hash_name; // a simple hash on the name
-
usec_t usec_since_last_update; // the time in microseconds since the last collection of data
struct timeval last_updated; // when this data set was last updated (updated every time the rrd_stats_done() function)
@@ -601,14 +566,15 @@ struct rrdset {
RRDHOST *rrdhost; // pointer to RRDHOST this chart belongs to
struct rrdset *next; // linking of rrdsets
+ struct rrdset *prev; // linking of rrdsets
// ------------------------------------------------------------------------
// local variables
- NETDATA_DOUBLE green; // green threshold for this chart
- NETDATA_DOUBLE red; // red threshold for this chart
+ NETDATA_DOUBLE green; // green threshold for this chart
+ NETDATA_DOUBLE red; // red threshold for this chart
- avl_tree_lock rrdvar_root_index; // RRDVAR index for this chart
+ DICTIONARY *rrdvar_root_index; // RRDVAR index for this chart
RRDSETVAR *variables; // RRDSETVAR linked list for this chart (one RRDSETVAR, many RRDVARs)
RRDCALC *alarms; // RRDCALC linked list for this chart
@@ -621,14 +587,27 @@ struct rrdset {
// ------------------------------------------------------------------------
// the dimensions
- avl_tree_lock dimensions_index; // the root of the dimensions index
+ DICTIONARY *rrddim_root_index; // the root of the dimensions index
+
+ netdata_rwlock_t rrdset_rwlock; // protects dimensions linked list
RRDDIM *dimensions; // the actual data for every dimension
};
+#define rrdset_plugin_name(st) string2str((st)->plugin_name)
+#define rrdset_module_name(st) string2str((st)->module_name)
+#define rrdset_units(st) string2str((st)->units)
+#define rrdset_type(st) string2str((st)->type)
+#define rrdset_family(st) string2str((st)->family)
+#define rrdset_title(st) string2str((st)->title)
+#define rrdset_context(st) string2str((st)->context)
+#define rrdset_name(st) string2str((st)->name)
+#define rrdset_id(st) string2str((st)->id)
+
#define rrdset_rdlock(st) netdata_rwlock_rdlock(&((st)->rrdset_rwlock))
#define rrdset_wrlock(st) netdata_rwlock_wrlock(&((st)->rrdset_rwlock))
#define rrdset_unlock(st) netdata_rwlock_unlock(&((st)->rrdset_rwlock))
+extern STRING *rrd_string_strdupz(const char *s);
// ----------------------------------------------------------------------------
// these loop macros make sure the linked list is accessed with the right lock
@@ -653,26 +632,29 @@ extern bool rrdset_memory_load_or_create_map_save(RRDSET *st_on_file, RRD_MEMORY
// and may lead to missing information.
typedef enum rrdhost_flags {
- RRDHOST_FLAG_ORPHAN = (1 << 0), // this host is orphan (not receiving data)
- RRDHOST_FLAG_DELETE_OBSOLETE_CHARTS = (1 << 1), // delete files of obsolete charts
- RRDHOST_FLAG_DELETE_ORPHAN_HOST = (1 << 2), // delete the entire host when orphan
- RRDHOST_FLAG_EXPORTING_SEND = (1 << 3), // send it to external databases
- RRDHOST_FLAG_EXPORTING_DONT_SEND = (1 << 4), // don't send it to external databases
- RRDHOST_FLAG_ARCHIVED = (1 << 5), // The host is archived, no collected charts yet
- RRDHOST_FLAG_MULTIHOST = (1 << 6), // Host belongs to localhost/megadb
- RRDHOST_FLAG_PENDING_FOREACH_ALARMS = (1 << 7), // contains dims with uninitialized foreach alarms
- RRDHOST_FLAG_STREAM_LABELS_UPDATE = (1 << 8),
- RRDHOST_FLAG_STREAM_LABELS_STOP = (1 << 9),
- RRDHOST_FLAG_ACLK_STREAM_CONTEXTS = (1 << 10), // when set, we should send ACLK stream context updates
+ RRDHOST_FLAG_ORPHAN = (1 << 0), // this host is orphan (not receiving data)
+ RRDHOST_FLAG_DELETE_OBSOLETE_CHARTS = (1 << 1), // delete files of obsolete charts
+ RRDHOST_FLAG_DELETE_ORPHAN_HOST = (1 << 2), // delete the entire host when orphan
+ RRDHOST_FLAG_EXPORTING_SEND = (1 << 3), // send it to external databases
+ RRDHOST_FLAG_EXPORTING_DONT_SEND = (1 << 4), // don't send it to external databases
+ RRDHOST_FLAG_ARCHIVED = (1 << 5), // The host is archived, no collected charts yet
+ RRDHOST_FLAG_MULTIHOST = (1 << 6), // Host belongs to localhost/megadb
+ RRDHOST_FLAG_PENDING_FOREACH_ALARMS = (1 << 7), // contains dims with uninitialized foreach alarms
+ RRDHOST_FLAG_STREAM_LABELS_UPDATE = (1 << 8),
+ RRDHOST_FLAG_STREAM_LABELS_STOP = (1 << 9),
+ RRDHOST_FLAG_ACLK_STREAM_CONTEXTS = (1 << 10), // when set, we should send ACLK stream context updates
+ RRDHOST_FLAG_INDEXED_MACHINE_GUID = (1 << 11), // when set, we have indexed its machine guid
+ RRDHOST_FLAG_INDEXED_HOSTNAME = (1 << 12), // when set, we have indexed its hostname
+ RRDHOST_FLAG_STREAM_COLLECTED_METRICS = (1 << 13), // when set, rrdset_done() should push metrics to parent
} RRDHOST_FLAGS;
#define rrdhost_flag_check(host, flag) (__atomic_load_n(&((host)->flags), __ATOMIC_SEQ_CST) & (flag))
#define rrdhost_flag_set(host, flag) __atomic_or_fetch(&((host)->flags), flag, __ATOMIC_SEQ_CST)
-#define rrdhost_flag_clear(host, flag) __atomic_and_fetch(&((host)->flags), ~flag, __ATOMIC_SEQ_CST)
+#define rrdhost_flag_clear(host, flag) __atomic_and_fetch(&((host)->flags), ~(flag), __ATOMIC_SEQ_CST)
#ifdef NETDATA_INTERNAL_CHECKS
#define rrdset_debug(st, fmt, args...) do { if(unlikely(debug_flags & D_RRD_STATS && rrdset_flag_check(st, RRDSET_FLAG_DEBUG))) \
- debug_int(__FILE__, __FUNCTION__, __LINE__, "%s: " fmt, st->name, ##args); } while(0)
+ debug_int(__FILE__, __FUNCTION__, __LINE__, "%s: " fmt, rrdset_name(st), ##args); } while(0)
#else
#define rrdset_debug(st, fmt, args...) debug_dummy()
#endif
@@ -690,34 +672,30 @@ struct alarm_entry {
time_t duration;
time_t non_clear_duration;
- char *name;
- uint32_t hash_name;
-
- char *chart;
- uint32_t hash_chart;
- char *chart_context;
+ STRING *name;
+ STRING *chart;
+ STRING *chart_context;
+ STRING *family;
- char *family;
+ STRING *classification;
+ STRING *component;
+ STRING *type;
- char *classification;
- char *component;
- char *type;
-
- char *exec;
- char *recipient;
+ STRING *exec;
+ STRING *recipient;
time_t exec_run_timestamp;
int exec_code;
uint64_t exec_spawn_serial;
- char *source;
- char *units;
- char *info;
+ STRING *source;
+ STRING *units;
+ STRING *info;
NETDATA_DOUBLE old_value;
NETDATA_DOUBLE new_value;
- char *old_value_string;
- char *new_value_string;
+ STRING *old_value_string;
+ STRING *new_value_string;
RRDCALC_STATUS old_status;
RRDCALC_STATUS new_status;
@@ -737,6 +715,20 @@ struct alarm_entry {
struct alarm_entry *prev_in_progress;
};
+#define ae_name(ae) string2str((ae)->name)
+#define ae_chart_name(ae) string2str((ae)->chart)
+#define ae_chart_context(ae) string2str((ae)->chart_context)
+#define ae_family(ae) string2str((ae)->family)
+#define ae_classification(ae) string2str((ae)->classification)
+#define ae_component(ae) string2str((ae)->component)
+#define ae_type(ae) string2str((ae)->type)<