From ab1bb5b7f1c3c3a7b240ab7fc8661459ecd7decb Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Thu, 20 Jul 2023 06:49:55 +0200 Subject: Adding upstream version 1.41.0. Signed-off-by: Daniel Baumann --- database/rrdset.c | 335 +++++++++++++++++++++++++++--------------------------- 1 file changed, 168 insertions(+), 167 deletions(-) (limited to 'database/rrdset.c') diff --git a/database/rrdset.c b/database/rrdset.c index 3177f43ff..1e00d5c8a 100644 --- a/database/rrdset.c +++ b/database/rrdset.c @@ -55,7 +55,7 @@ static STRING *rrdset_fix_name(RRDHOST *host, const char *chart_full_id, const c strncpyz(new_name, sanitized_name, CONFIG_MAX_VALUE); if(rrdset_index_find_name(host, new_name)) { - debug(D_RRD_CALLS, "RRDSET: chart name '%s' on host '%s' already exists.", new_name, rrdhost_hostname(host)); + netdata_log_debug(D_RRD_CALLS, "RRDSET: chart name '%s' on host '%s' already exists.", new_name, rrdhost_hostname(host)); if(!strcmp(chart_full_id, full_name) && (!current_name || !*current_name)) { unsigned i = 1; @@ -64,7 +64,7 @@ static STRING *rrdset_fix_name(RRDHOST *host, const char *chart_full_id, const c i++; } while (rrdset_index_find_name(host, new_name)); - info("RRDSET: using name '%s' for chart '%s' on host '%s'.", new_name, full_name, rrdhost_hostname(host)); + netdata_log_info("RRDSET: using name '%s' for chart '%s' on host '%s'.", new_name, full_name, rrdhost_hostname(host)); } else return NULL; @@ -128,14 +128,14 @@ static void rrdset_insert_callback(const DICTIONARY_ITEM *item __maybe_unused, v st->module_name = rrd_string_strdupz(ctr->module); st->priority = ctr->priority; - st->entries = (ctr->memory_mode != RRD_MEMORY_MODE_DBENGINE) ? align_entries_to_pagesize(ctr->memory_mode, ctr->history_entries) : 5; + st->db.entries = (ctr->memory_mode != RRD_MEMORY_MODE_DBENGINE) ? align_entries_to_pagesize(ctr->memory_mode, ctr->history_entries) : 5; st->update_every = ctr->update_every; st->rrd_memory_mode = ctr->memory_mode; st->chart_type = ctr->chart_type; st->rrdhost = host; - netdata_spinlock_init(&st->data_collection_lock); + spinlock_init(&st->data_collection_lock); st->flags = RRDSET_FLAG_SYNC_CLOCK | RRDSET_FLAG_INDEXED_ID @@ -143,11 +143,11 @@ static void rrdset_insert_callback(const DICTIONARY_ITEM *item __maybe_unused, v | RRDSET_FLAG_SENDER_REPLICATION_FINISHED ; - netdata_rwlock_init(&st->alerts.rwlock); + rw_spinlock_init(&st->alerts.spinlock); if(st->rrd_memory_mode == RRD_MEMORY_MODE_SAVE || st->rrd_memory_mode == RRD_MEMORY_MODE_MAP) { if(!rrdset_memory_load_or_create_map_save(st, st->rrd_memory_mode)) { - info("Failed to use db mode %s for chart '%s', falling back to ram mode.", (st->rrd_memory_mode == RRD_MEMORY_MODE_MAP)?"map":"save", rrdset_name(st)); + netdata_log_info("Failed to use db mode %s for chart '%s', falling back to ram mode.", (st->rrd_memory_mode == RRD_MEMORY_MODE_MAP)?"map":"save", rrdset_name(st)); st->rrd_memory_mode = RRD_MEMORY_MODE_RAM; } } @@ -263,8 +263,6 @@ static void rrdset_delete_callback(const DICTIONARY_ITEM *item __maybe_unused, v // ------------------------------------------------------------------------ // free it - netdata_rwlock_destroy(&st->alerts.rwlock); - string_freez(st->id); string_freez(st->name); string_freez(st->parts.id); @@ -278,7 +276,7 @@ static void rrdset_delete_callback(const DICTIONARY_ITEM *item __maybe_unused, v string_freez(st->module_name); freez(st->exporting_flags); - freez(st->cache_dir); + freez(st->db.cache_dir); } // the item to be inserted, is already in the dictionary @@ -452,7 +450,7 @@ static RRDSET *rrdset_index_find(RRDHOST *host, const char *id) { // RRDSET - find charts inline RRDSET *rrdset_find(RRDHOST *host, const char *id) { - debug(D_RRD_CALLS, "rrdset_find() for chart '%s' in host '%s'", id, rrdhost_hostname(host)); + netdata_log_debug(D_RRD_CALLS, "rrdset_find() for chart '%s' in host '%s'", id, rrdhost_hostname(host)); RRDSET *st = rrdset_index_find(host, id); if(st) @@ -462,7 +460,7 @@ inline RRDSET *rrdset_find(RRDHOST *host, const char *id) { } inline RRDSET *rrdset_find_bytype(RRDHOST *host, const char *type, const char *id) { - debug(D_RRD_CALLS, "rrdset_find_bytype() for chart '%s.%s' in host '%s'", type, id, rrdhost_hostname(host)); + netdata_log_debug(D_RRD_CALLS, "rrdset_find_bytype() for chart '%s.%s' in host '%s'", type, id, rrdhost_hostname(host)); char buf[RRD_ID_LENGTH_MAX + 1]; strncpyz(buf, type, RRD_ID_LENGTH_MAX - 1); @@ -474,13 +472,13 @@ inline RRDSET *rrdset_find_bytype(RRDHOST *host, const char *type, const char *i } inline RRDSET *rrdset_find_byname(RRDHOST *host, const char *name) { - debug(D_RRD_CALLS, "rrdset_find_byname() for chart '%s' in host '%s'", name, rrdhost_hostname(host)); + netdata_log_debug(D_RRD_CALLS, "rrdset_find_byname() for chart '%s' in host '%s'", name, rrdhost_hostname(host)); RRDSET *st = rrdset_index_find_name(host, name); return(st); } RRDSET_ACQUIRED *rrdset_find_and_acquire(RRDHOST *host, const char *id) { - debug(D_RRD_CALLS, "rrdset_find_and_acquire() for host %s, chart %s", rrdhost_hostname(host), id); + netdata_log_debug(D_RRD_CALLS, "rrdset_find_and_acquire() for host %s, chart %s", rrdhost_hostname(host), id); return (RRDSET_ACQUIRED *)dictionary_get_and_acquire_item(host->rrdset_root_index, id); } @@ -524,7 +522,7 @@ int rrdset_reset_name(RRDSET *st, const char *name) { RRDHOST *host = st->rrdhost; - debug(D_RRD_CALLS, "rrdset_reset_name() old: '%s', new: '%s'", rrdset_name(st), name); + netdata_log_debug(D_RRD_CALLS, "rrdset_reset_name() old: '%s', new: '%s'", rrdset_name(st), name); STRING *name_string = rrdset_fix_name(host, rrdset_id(st), rrdset_parts_type(st), string2str(st->name), name); if(!name_string) return 0; @@ -660,7 +658,7 @@ void rrdset_get_retention_of_tier_for_collected_chart(RRDSET *st, time_t *first_ inline void rrdset_is_obsolete(RRDSET *st) { if(unlikely(rrdset_flag_check(st, RRDSET_FLAG_ARCHIVED))) { - info("Cannot obsolete already archived chart %s", rrdset_name(st)); + netdata_log_info("Cannot obsolete already archived chart %s", rrdset_name(st)); return; } @@ -702,8 +700,8 @@ inline void rrdset_update_heterogeneous_flag(RRDSET *st) { bool init = false, is_heterogeneous = false; RRD_ALGORITHM algorithm; - collected_number multiplier; - collected_number divisor; + int32_t multiplier; + int32_t divisor; rrddim_foreach_read(rd, st) { if(!init) { @@ -717,7 +715,9 @@ inline void rrdset_update_heterogeneous_flag(RRDSET *st) { if(algorithm != rd->algorithm || multiplier != ABS(rd->multiplier) || divisor != ABS(rd->divisor)) { if(!rrdset_flag_check(st, RRDSET_FLAG_HETEROGENEOUS)) { #ifdef NETDATA_INTERNAL_CHECKS - info("Dimension '%s' added on chart '%s' of host '%s' is not homogeneous to other dimensions already present (algorithm is '%s' vs '%s', multiplier is " COLLECTED_NUMBER_FORMAT " vs " COLLECTED_NUMBER_FORMAT ", divisor is " COLLECTED_NUMBER_FORMAT " vs " COLLECTED_NUMBER_FORMAT ").", + netdata_log_info("Dimension '%s' added on chart '%s' of host '%s' is not homogeneous to other dimensions already present " + "(algorithm is '%s' vs '%s', multiplier is %d vs %d, " + "divisor is %d vs %d).", rrddim_name(rd), rrdset_name(st), rrdhost_hostname(host), @@ -745,21 +745,21 @@ inline void rrdset_update_heterogeneous_flag(RRDSET *st) { // RRDSET - reset a chart void rrdset_reset(RRDSET *st) { - debug(D_RRD_CALLS, "rrdset_reset() %s", rrdset_name(st)); + netdata_log_debug(D_RRD_CALLS, "rrdset_reset() %s", rrdset_name(st)); st->last_collected_time.tv_sec = 0; st->last_collected_time.tv_usec = 0; st->last_updated.tv_sec = 0; st->last_updated.tv_usec = 0; - st->current_entry = 0; + st->db.current_entry = 0; st->counter = 0; st->counter_done = 0; RRDDIM *rd; rrddim_foreach_read(rd, st) { - rd->last_collected_time.tv_sec = 0; - rd->last_collected_time.tv_usec = 0; - rd->collections_counter = 0; + rd->collector.last_collected_time.tv_sec = 0; + rd->collector.last_collected_time.tv_usec = 0; + rd->collector.counter = 0; if(!rrddim_flag_check(rd, RRDDIM_FLAG_ARCHIVED)) { for(size_t tier = 0; tier < storage_tiers ;tier++) @@ -833,45 +833,45 @@ void rrdset_save(RRDSET *st) { void rrdset_delete_files(RRDSET *st) { RRDDIM *rd; - info("Deleting chart '%s' ('%s') from disk...", rrdset_id(st), rrdset_name(st)); + netdata_log_info("Deleting chart '%s' ('%s') from disk...", rrdset_id(st), rrdset_name(st)); if(st->rrd_memory_mode == RRD_MEMORY_MODE_SAVE || st->rrd_memory_mode == RRD_MEMORY_MODE_MAP) { const char *cache_filename = rrdset_cache_filename(st); if(cache_filename) { - info("Deleting chart header file '%s'.", cache_filename); + netdata_log_info("Deleting chart header file '%s'.", cache_filename); if (unlikely(unlink(cache_filename) == -1)) - error("Cannot delete chart header file '%s'", cache_filename); + netdata_log_error("Cannot delete chart header file '%s'", cache_filename); } else - error("Cannot find the cache filename of chart '%s'", rrdset_id(st)); + netdata_log_error("Cannot find the cache filename of chart '%s'", rrdset_id(st)); } rrddim_foreach_read(rd, st) { const char *cache_filename = rrddim_cache_filename(rd); if(!cache_filename) continue; - info("Deleting dimension file '%s'.", cache_filename); + netdata_log_info("Deleting dimension file '%s'.", cache_filename); if(unlikely(unlink(cache_filename) == -1)) - error("Cannot delete dimension file '%s'", cache_filename); + netdata_log_error("Cannot delete dimension file '%s'", cache_filename); } rrddim_foreach_done(rd); - if(st->cache_dir) - recursively_delete_dir(st->cache_dir, "left-over chart"); + if(st->db.cache_dir) + recursively_delete_dir(st->db.cache_dir, "left-over chart"); } void rrdset_delete_obsolete_dimensions(RRDSET *st) { RRDDIM *rd; - info("Deleting dimensions of chart '%s' ('%s') from disk...", rrdset_id(st), rrdset_name(st)); + netdata_log_info("Deleting dimensions of chart '%s' ('%s') from disk...", rrdset_id(st), rrdset_name(st)); rrddim_foreach_read(rd, st) { if(rrddim_flag_check(rd, RRDDIM_FLAG_OBSOLETE)) { const char *cache_filename = rrddim_cache_filename(rd); if(!cache_filename) continue; - info("Deleting dimension file '%s'.", cache_filename); + netdata_log_info("Deleting dimension file '%s'.", cache_filename); if(unlikely(unlink(cache_filename) == -1)) - error("Cannot delete dimension file '%s'", cache_filename); + netdata_log_error("Cannot delete dimension file '%s'", cache_filename); } } rrddim_foreach_done(rd); @@ -933,7 +933,7 @@ RRDSET *rrdset_create_custom( // ------------------------------------------------------------------------ // allocate it - debug(D_RRD_CALLS, "Creating RRD_STATS for '%s.%s'.", type, id); + netdata_log_debug(D_RRD_CALLS, "Creating RRD_STATS for '%s.%s'.", type, id); struct rrdset_constructor tmp = { .host = host, @@ -999,8 +999,8 @@ void rrdset_timed_next(RRDSET *st, struct timeval now, usec_t duration_since_las if(unlikely(since_last_usec < 0)) { // oops! the database is in the future #ifdef NETDATA_INTERNAL_CHECKS - info("RRD database for chart '%s' on host '%s' is %0.5" NETDATA_DOUBLE_MODIFIER - " secs in the future (counter #%zu, update #%zu). Adjusting it to current time." + netdata_log_info("RRD database for chart '%s' on host '%s' is %0.5" NETDATA_DOUBLE_MODIFIER + " secs in the future (counter #%u, update #%u). Adjusting it to current time." , rrdset_id(st) , rrdhost_hostname(st->rrdhost) , (NETDATA_DOUBLE)-since_last_usec / USEC_PER_SEC @@ -1018,8 +1018,10 @@ void rrdset_timed_next(RRDSET *st, struct timeval now, usec_t duration_since_las else if(unlikely((usec_t)since_last_usec > (usec_t)(st->update_every * 5 * USEC_PER_SEC))) { // oops! the database is too far behind #ifdef NETDATA_INTERNAL_CHECKS - info("RRD database for chart '%s' on host '%s' is %0.5" NETDATA_DOUBLE_MODIFIER - " secs in the past (counter #%zu, update #%zu). Adjusting it to current time.", rrdset_id(st), rrdhost_hostname(st->rrdhost), (NETDATA_DOUBLE)since_last_usec / USEC_PER_SEC, st->counter, st->counter_done); + netdata_log_info("RRD database for chart '%s' on host '%s' is %0.5" NETDATA_DOUBLE_MODIFIER + " secs in the past (counter #%u, update #%u). Adjusting it to current time.", + rrdset_id(st), rrdhost_hostname(st->rrdhost), (NETDATA_DOUBLE)since_last_usec / USEC_PER_SEC, + st->counter, st->counter_done); #endif duration_since_last_update = (usec_t)since_last_usec; @@ -1044,7 +1046,7 @@ void rrdset_timed_next(RRDSET *st, struct timeval now, usec_t duration_since_las last_time_s = now.tv_sec; if(min_delta > permanent_min_delta) { - info("MINIMUM MICROSECONDS DELTA of thread %d increased from %lld to %lld (+%lld)", gettid(), permanent_min_delta, min_delta, min_delta - permanent_min_delta); + netdata_log_info("MINIMUM MICROSECONDS DELTA of thread %d increased from %lld to %lld (+%lld)", gettid(), permanent_min_delta, min_delta, min_delta - permanent_min_delta); permanent_min_delta = min_delta; } @@ -1054,7 +1056,7 @@ void rrdset_timed_next(RRDSET *st, struct timeval now, usec_t duration_since_las #endif } - debug(D_RRD_CALLS, "rrdset_timed_next() for chart %s with duration since last update %llu usec", rrdset_name(st), duration_since_last_update); + netdata_log_debug(D_RRD_CALLS, "rrdset_timed_next() for chart %s with duration since last update %llu usec", rrdset_name(st), duration_since_last_update); rrdset_debug(st, "NEXT: %llu microseconds", duration_since_last_update); internal_error(discarded && discarded != duration_since_last_update, @@ -1126,7 +1128,7 @@ static inline void rrdset_init_last_updated_time(RRDSET *st) { static __thread size_t rrdset_done_statistics_points_stored_per_tier[RRD_STORAGE_TIERS]; static inline time_t tier_next_point_time_s(RRDDIM *rd, struct rrddim_tier *t, time_t now_s) { - time_t loop = (time_t)rd->update_every * (time_t)t->tier_grouping; + time_t loop = (time_t)rd->rrdset->update_every * (time_t)t->tier_grouping; return now_s + loop - ((now_s + loop) % loop); } @@ -1231,7 +1233,7 @@ void rrddim_store_metric(RRDDIM *rd, usec_t point_end_time_ut, NETDATA_DOUBLE n, time_t now_s = (time_t)(point_end_time_ut / USEC_PER_SEC); STORAGE_POINT sp = { - .start_time_s = now_s - rd->update_every, + .start_time_s = now_s - rd->rrdset->update_every, .end_time_s = now_s, .min = n, .max = n, @@ -1320,7 +1322,7 @@ static inline size_t rrdset_done_interpolate( if((now_collect_ut % (update_every_ut)) == 0) iterations++; size_t counter = st->counter; - long current_entry = st->current_entry; + long current_entry = st->db.current_entry; SN_FLAGS storage_flags = SN_DEFAULT_FLAGS; @@ -1357,7 +1359,7 @@ static inline size_t rrdset_done_interpolate( switch(rd->algorithm) { case RRD_ALGORITHM_INCREMENTAL: new_value = (NETDATA_DOUBLE) - ( rd->calculated_value + ( rd->collector.calculated_value * (NETDATA_DOUBLE)(next_store_ut - last_collect_ut) / (NETDATA_DOUBLE)(now_collect_ut - last_collect_ut) ); @@ -1368,14 +1370,14 @@ static inline size_t rrdset_done_interpolate( " / (%llu - %llu)" , rrddim_name(rd) , new_value - , rd->calculated_value + , rd->collector.calculated_value , next_store_ut, last_collect_ut , now_collect_ut, last_collect_ut ); - rd->calculated_value -= new_value; - new_value += rd->last_calculated_value; - rd->last_calculated_value = 0; + rd->collector.calculated_value -= new_value; + new_value += rd->collector.last_calculated_value; + rd->collector.last_calculated_value = 0; new_value /= (NETDATA_DOUBLE)st->update_every; if(unlikely(next_store_ut - last_stored_ut < update_every_ut)) { @@ -1398,18 +1400,18 @@ static inline size_t rrdset_done_interpolate( // do not interpolate // just show the calculated value - new_value = rd->calculated_value; + new_value = rd->collector.calculated_value; } else { // we have missed an update // interpolate in the middle values new_value = (NETDATA_DOUBLE) - ( ( (rd->calculated_value - rd->last_calculated_value) + ( ( (rd->collector.calculated_value - rd->collector.last_calculated_value) * (NETDATA_DOUBLE)(next_store_ut - last_collect_ut) / (NETDATA_DOUBLE)(now_collect_ut - last_collect_ut) ) - + rd->last_calculated_value + + rd->collector.last_calculated_value ); rrdset_debug(st, "%s: CALC2 DEF " NETDATA_DOUBLE_FORMAT " = (((" @@ -1417,9 +1419,9 @@ static inline size_t rrdset_done_interpolate( " * %llu" " / %llu) + " NETDATA_DOUBLE_FORMAT, rrddim_name(rd) , new_value - , rd->calculated_value, rd->last_calculated_value + , rd->collector.calculated_value, rd->collector.last_calculated_value , (next_store_ut - first_ut) - , (now_collect_ut - first_ut), rd->last_calculated_value + , (now_collect_ut - first_ut), rd->collector.last_calculated_value ); } break; @@ -1437,7 +1439,7 @@ static inline size_t rrdset_done_interpolate( continue; } - if(likely(rd->updated && rd->collections_counter > 1 && iterations < gap_when_lost_iterations_above)) { + if(likely(rrddim_check_updated(rd) && rd->collector.counter > 1 && iterations < gap_when_lost_iterations_above)) { uint32_t dim_storage_flags = storage_flags; if (ml_dimension_is_anomalous(rd, current_time_s, new_value, true)) { @@ -1449,7 +1451,7 @@ static inline size_t rrdset_done_interpolate( rrddim_push_metrics_v2(rsb, rd, next_store_ut, new_value, dim_storage_flags); rrddim_store_metric(rd, next_store_ut, new_value, dim_storage_flags); - rd->last_stored_value = new_value; + rd->collector.last_stored_value = new_value; } else { (void) ml_dimension_is_anomalous(rd, current_time_s, 0, false); @@ -1460,7 +1462,7 @@ static inline size_t rrdset_done_interpolate( rrddim_push_metrics_v2(rsb, rd, next_store_ut, NAN, SN_FLAG_NONE); rrddim_store_metric(rd, next_store_ut, NAN, SN_FLAG_NONE); - rd->last_stored_value = NAN; + rd->collector.last_stored_value = NAN; } stored_entries++; @@ -1472,7 +1474,7 @@ static inline size_t rrdset_done_interpolate( storage_flags = SN_DEFAULT_FLAGS; st->counter = ++counter; - st->current_entry = current_entry = ((current_entry + 1) >= st->entries) ? 0 : current_entry + 1; + st->db.current_entry = current_entry = ((current_entry + 1) >= st->db.entries) ? 0 : current_entry + 1; st->last_updated.tv_sec = (time_t) (last_ut / USEC_PER_SEC); st->last_updated.tv_usec = 0; @@ -1507,12 +1509,12 @@ void rrdset_timed_done(RRDSET *st, struct timeval now, bool pending_rrdset_next) if(unlikely(rrdhost_has_rrdpush_sender_enabled(st->rrdhost))) stream_buffer = rrdset_push_metric_initialize(st, now.tv_sec); - netdata_spinlock_lock(&st->data_collection_lock); + spinlock_lock(&st->data_collection_lock); if (pending_rrdset_next) rrdset_timed_next(st, now, 0ULL); - debug(D_RRD_CALLS, "rrdset_done() for chart '%s'", rrdset_name(st)); + netdata_log_debug(D_RRD_CALLS, "rrdset_done() for chart '%s'", rrdset_name(st)); RRDDIM *rd; @@ -1529,19 +1531,20 @@ void rrdset_timed_done(RRDSET *st, struct timeval now, bool pending_rrdset_next) RRDSET_FLAGS rrdset_flags = rrdset_flag_check(st, ~0); if(unlikely(rrdset_flags & RRDSET_FLAG_COLLECTION_FINISHED)) { - netdata_spinlock_unlock(&st->data_collection_lock); + spinlock_unlock(&st->data_collection_lock); return; } if (unlikely(rrdset_flags & RRDSET_FLAG_OBSOLETE)) { - error("Chart '%s' has the OBSOLETE flag set, but it is collected.", rrdset_id(st)); + netdata_log_error("Chart '%s' has the OBSOLETE flag set, but it is collected.", rrdset_id(st)); rrdset_isnot_obsolete(st); } // check if the chart has a long time to be updated - if(unlikely(st->usec_since_last_update > MAX(st->entries, 60) * update_every_ut)) { - info("host '%s', chart '%s': took too long to be updated (counter #%zu, update #%zu, %0.3" NETDATA_DOUBLE_MODIFIER - " secs). Resetting it.", rrdhost_hostname(st->rrdhost), rrdset_id(st), st->counter, st->counter_done, (NETDATA_DOUBLE)st->usec_since_last_update / USEC_PER_SEC); + if(unlikely(st->usec_since_last_update > MAX(st->db.entries, 60) * update_every_ut)) { + netdata_log_info("host '%s', chart '%s': took too long to be updated (counter #%u, update #%u, %0.3" NETDATA_DOUBLE_MODIFIER + " secs). Resetting it.", rrdhost_hostname(st->rrdhost), rrdset_id(st), st->counter, st->counter_done, + (NETDATA_DOUBLE)st->usec_since_last_update / USEC_PER_SEC); rrdset_reset(st); st->usec_since_last_update = update_every_ut; store_this_entry = 0; @@ -1579,9 +1582,9 @@ void rrdset_timed_done(RRDSET *st, struct timeval now, bool pending_rrdset_next) } // check if we will re-write the entire data set - if(unlikely(dt_usec(&st->last_collected_time, &st->last_updated) > st->entries * update_every_ut && + if(unlikely(dt_usec(&st->last_collected_time, &st->last_updated) > st->db.entries * update_every_ut && st->rrd_memory_mode != RRD_MEMORY_MODE_DBENGINE)) { - info( + netdata_log_info( "'%s': too old data (last updated at %"PRId64".%"PRId64", last collected at %"PRId64".%"PRId64"). " "Resetting it. Will not store the next entry.", rrdset_id(st), @@ -1659,28 +1662,28 @@ void rrdset_timed_done(RRDSET *st, struct timeval now, bool pending_rrdset_next) rda->rd = dictionary_acquired_item_value(rda->item); // calculate totals - if(likely(rd->updated)) { + if(likely(rrddim_check_updated(rd))) { // if the new is smaller than the old (an overflow, or reset), set the old equal to the new // to reset the calculation (it will give zero as the calculation for this second) - if(unlikely(rd->algorithm == RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL && rd->last_collected_value > rd->collected_value)) { - debug(D_RRD_STATS, "'%s' / '%s': RESET or OVERFLOW. Last collected value = " COLLECTED_NUMBER_FORMAT ", current = " COLLECTED_NUMBER_FORMAT + if(unlikely(rd->algorithm == RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL && rd->collector.last_collected_value > rd->collector.collected_value)) { + netdata_log_debug(D_RRD_STATS, "'%s' / '%s': RESET or OVERFLOW. Last collected value = " COLLECTED_NUMBER_FORMAT ", current = " COLLECTED_NUMBER_FORMAT , rrdset_id(st) , rrddim_name(rd) - , rd->last_collected_value - , rd->collected_value + , rd->collector.last_collected_value + , rd->collector.collected_value ); if(!(rrddim_option_check(rd, RRDDIM_OPTION_DONT_DETECT_RESETS_OR_OVERFLOWS))) has_reset_value = 1; - rd->last_collected_value = rd->collected_value; + rd->collector.last_collected_value = rd->collector.collected_value; } - last_collected_total += rd->last_collected_value; - collected_total += rd->collected_value; + last_collected_total += rd->collector.last_collected_value; + collected_total += rd->collector.collected_value; if(unlikely(rrddim_flag_check(rd, RRDDIM_FLAG_OBSOLETE))) { - error("Dimension %s in chart '%s' has the OBSOLETE flag set, but it is collected.", rrddim_name(rd), rrdset_id(st)); + netdata_log_error("Dimension %s in chart '%s' has the OBSOLETE flag set, but it is collected.", rrddim_name(rd), rrdset_id(st)); rrddim_isnot_obsolete(st, rd); } } @@ -1700,8 +1703,8 @@ void rrdset_timed_done(RRDSET *st, struct timeval now, bool pending_rrdset_next) rd = rda->rd; if(unlikely(!rd)) continue; - if(unlikely(!rd->updated)) { - rd->calculated_value = 0; + if(unlikely(!rrddim_check_updated(rd))) { + rd->collector.calculated_value = 0; continue; } @@ -1711,25 +1714,25 @@ void rrdset_timed_done(RRDSET *st, struct timeval now, bool pending_rrdset_next) " last_calculated_value = " NETDATA_DOUBLE_FORMAT " calculated_value = " NETDATA_DOUBLE_FORMAT , rrddim_name(rd) - , rd->last_collected_value - , rd->collected_value - , rd->last_calculated_value - , rd->calculated_value + , rd->collector.last_collected_value + , rd->collector.collected_value + , rd->collector.last_calculated_value + , rd->collector.calculated_value ); switch(rd->algorithm) { case RRD_ALGORITHM_ABSOLUTE: - rd->calculated_value = (NETDATA_DOUBLE)rd->collected_value - * (NETDATA_DOUBLE)rd->multiplier - / (NETDATA_DOUBLE)rd->divisor; + rd->collector.calculated_value = (NETDATA_DOUBLE)rd->collector.collected_value + * (NETDATA_DOUBLE)rd->multiplier + / (NETDATA_DOUBLE)rd->divisor; rrdset_debug(st, "%s: CALC ABS/ABS-NO-IN " NETDATA_DOUBLE_FORMAT " = " COLLECTED_NUMBER_FORMAT " * " NETDATA_DOUBLE_FORMAT " / " NETDATA_DOUBLE_FORMAT , rrddim_name(rd) - , rd->calculated_value - , rd->collected_value + , rd->collector.calculated_value + , rd->collector.collected_value , (NETDATA_DOUBLE)rd->multiplier , (NETDATA_DOUBLE)rd->divisor ); @@ -1737,28 +1740,28 @@ void rrdset_timed_done(RRDSET *st, struct timeval now, bool pending_rrdset_next) case RRD_ALGORITHM_PCENT_OVER_ROW_TOTAL: if(unlikely(!collected_total)) - rd->calculated_value = 0; + rd->collector.calculated_value = 0; else // the percentage of the current value // over the total of all dimensions - rd->calculated_value = + rd->collector.calculated_value = (NETDATA_DOUBLE)100 - * (NETDATA_DOUBLE)rd->collected_value + * (NETDATA_DOUBLE)rd->collector.collected_value / (NETDATA_DOUBLE)collected_total; rrdset_debug(st, "%s: CALC PCENT-ROW " NETDATA_DOUBLE_FORMAT " = 100" " * " COLLECTED_NUMBER_FORMAT " / " COLLECTED_NUMBER_FORMAT , rrddim_name(rd) - , rd->calculated_value - , rd->collected_value + , rd->collector.calculated_value + , rd->collector.collected_value , collected_total ); break; case RRD_ALGORITHM_INCREMENTAL: - if(unlikely(rd->collections_counter <= 1)) { - rd->calculated_value = 0; + if(unlikely(rd->collector.counter <= 1)) { + rd->collector.calculated_value = 0; continue; } @@ -1766,19 +1769,19 @@ void rrdset_timed_done(RRDSET *st, struct timeval now, bool pending_rrdset_next) // to reset the calculation (it will give zero as the calculation for this second). // It is imperative to set the comparison to uint64_t since type collected_number is signed and // produces wrong results as far as incremental counters are concerned. - if(unlikely((uint64_t)rd->last_collected_value > (uint64_t)rd->collected_value)) { - debug(D_RRD_STATS, "'%s' / '%s': RESET or OVERFLOW. Last collected value = " COLLECTED_NUMBER_FORMAT ", current = " COLLECTED_NUMBER_FORMAT + if(unlikely((uint64_t)rd->collector.last_collected_value > (uint64_t)rd->collector.collected_value)) { + netdata_log_debug(D_RRD_STATS, "'%s' / '%s': RESET or OVERFLOW. Last collected value = " COLLECTED_NUMBER_FORMAT ", current = " COLLECTED_NUMBER_FORMAT , rrdset_id(st) , rrddim_name(rd) - , rd->last_collected_value - , rd->collected_value); + , rd->collector.last_collected_value + , rd->collector.collected_value); if(!(rrddim_option_check(rd, RRDDIM_OPTION_DONT_DETECT_RESETS_OR_OVERFLOWS))) has_reset_value = 1; - uint64_t last = (uint64_t)rd->last_collected_value; - uint64_t new = (uint64_t)rd->collected_value; - uint64_t max = (uint64_t)rd->collected_value_max; + uint64_t last = (uint64_t)rd->collector.last_collected_value; + uint64_t new = (uint64_t)rd->collector.collected_value; + uint64_t max = (uint64_t)rd->collector.collected_value_max; uint64_t cap = 0; // Signed values are handled by exploiting two's complement which will produce positive deltas @@ -1795,19 +1798,19 @@ void rrdset_timed_done(RRDSET *st, struct timeval now, bool pending_rrdset_next) // overflow. // TODO: remember recent history of rates and compare with current rate to reduce this chance. if (delta < max_acceptable_rate) { - rd->calculated_value += + rd->collector.calculated_value += (NETDATA_DOUBLE) delta * (NETDATA_DOUBLE) rd->multiplier / (NETDATA_DOUBLE) rd->divisor; } else { // This is a reset. Any overflow with a rate greater than MAX_INCREMENTAL_PERCENT_RATE will also // be detected as a reset instead. - rd->calculated_value += (NETDATA_DOUBLE)0; + rd->collector.calculated_value += (NETDATA_DOUBLE)0; } } else { - rd->calculated_value += - (NETDATA_DOUBLE) (rd->collected_value - rd->last_collected_value) + rd->collector.calculated_value += + (NETDATA_DOUBLE) (rd->collector.collected_value - rd->collector.last_collected_value) * (NETDATA_DOUBLE) rd->multiplier / (NETDATA_DOUBLE) rd->divisor; } @@ -1818,35 +1821,35 @@ void rrdset_timed_done(RRDSET *st, struct timeval now, bool pending_rrdset_next) " * " NETDATA_DOUBLE_FORMAT " / " NETDATA_DOUBLE_FORMAT , rrddim_name(rd) - , rd->calculated_value - , rd->collected_value, rd->last_collected_value + , rd->collector.calculated_value + , rd->collector.collected_value, rd->collector.last_collected_value , (NETDATA_DOUBLE)rd->multiplier , (NETDATA_DOUBLE)rd->divisor ); break; case RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL: - if(unlikely(rd->collections_counter <= 1)) { - rd->calculated_value = 0; + if(unlikely(rd->collector.counter <= 1)) { + rd->collector.calculated_value = 0; continue; } // the percentage of the current increment // over the increment of all dimensions together if(unlikely(collected_total == last_collected_total)) - rd->calculated_value = 0; + rd->collector.calculated_value = 0; else - rd->calculated_value = + rd->collector.calculated_value = (NETDATA_DOUBLE)100 - * (NETDATA_DOUBLE)(rd->collected_value - rd->last_collected_value) + * (NETDATA_DOUBLE)(rd->collector.collected_value - rd->collector.last_collected_value) / (NETDATA_DOUBLE)(collected_total - last_collected_total); rrdset_debug(st, "%s: CALC PCENT-DIFF " NETDATA_DOUBLE_FORMAT " = 100" " * (" COLLECTED_NUMBER_FORMAT " - " COLLECTED_NUMBER_FORMAT ")" " / (" COLLECTED_NUMBER_FORMAT " - " COLLECTED_NUMBER_FORMAT ")" , rrddim_name(rd) - , rd->calculated_value - , rd->collected_value, rd->last_collected_value + , rd->collector.calculated_value + , rd->collector.collected_value, rd->collector.last_collected_value , collected_total, last_collected_total ); break; @@ -1854,11 +1857,11 @@ void rrdset_timed_done(RRDSET *st, struct timeval now, bool pending_rrdset_next) default: // make the default zero, to make sure // it gets noticed when we add new types - rd->calculated_value = 0; + rd->collector.calculated_value = 0; rrdset_debug(st, "%s: CALC " NETDATA_DOUBLE_FORMAT " = 0" , rrddim_name(rd) - , rd->calculated_value + , rd->collector.calculated_value ); break; } @@ -1869,10 +1872,10 @@ void rrdset_timed_done(RRDSET *st, struct timeval now, bool pending_rrdset_next) " last_calculated_value = " NETDATA_DOUBLE_FORMAT " calculated_value = " NETDATA_DOUBLE_FORMAT , rrddim_name(rd) - , rd->last_collected_value - , rd->collected_value - , rd->last_calculated_value - , rd->calculated_value + , rd->collector.last_collected_value + , rd->collector.collected_value + , rd->collector.last_calculated_value + , rd->collector.calculated_value ); } @@ -1883,7 +1886,7 @@ void rrdset_timed_done(RRDSET *st, struct timeval now, bool pending_rrdset_next) // if(unlikely(now_collect_ut < next_store_ut && st->counter_done > 1)) { // // this is collected in the same interpolation point // rrdset_debug(st, "THIS IS IN THE SAME INTERPOLATION POINT"); -// info("INTERNAL CHECK: host '%s', chart '%s' collection %zu is in the same interpolation point: short by %llu microseconds", st->rrdhost->hostname, rrdset_name(st), st->counter_done, next_store_ut - now_collect_ut); +// netdata_log_info("INTERNAL CHECK: host '%s', chart '%s' collection %zu is in the same interpolation point: short by %llu microseconds", st->rrdhost->hostname, rrdset_name(st), st->counter_done, next_store_ut - now_collect_ut); // } // #endif @@ -1905,12 +1908,12 @@ void rrdset_timed_done(RRDSET *st, struct timeval now, bool pending_rrdset_next) rd = rda->rd; if(unlikely(!rd)) continue; - if(unlikely(!rd->updated)) + if(unlikely(!rrddim_check_updated(rd))) continue; - rrdset_debug(st, "%s: setting last_collected_value (old: " COLLECTED_NUMBER_FORMAT ") to last_collected_value (new: " COLLECTED_NUMBER_FORMAT ")", rrddim_name(rd), rd->last_collected_value, rd->collected_value); + rrdset_debug(st, "%s: setting last_collected_value (old: " COLLECTED_NUMBER_FORMAT ") to last_collected_value (new: " COLLECTED_NUMBER_FORMAT ")", rrddim_name(rd), rd->collector.last_collected_value, rd->collector.collected_value); - rd->last_collected_value = rd->collected_value; + rd->collector.last_collected_value = rd->collector.collected_value; switch(rd->algorithm) { case RRD_ALGORITHM_INCREMENTAL: @@ -1918,10 +1921,10 @@ void rrdset_timed_done(RRDSET *st, struct timeval now, bool pending_rrdset_next) rrdset_debug(st, "%s: setting last_calculated_value (old: " NETDATA_DOUBLE_FORMAT ") to " "last_calculated_value (new: " NETDATA_DOUBLE_FORMAT ")" , rrddim_name(rd) - , rd->last_calculated_value + rd->calculated_value - , rd->calculated_value); + , rd->collector.last_calculated_value + rd->collector.calculated_value + , rd->collector.calculated_value); - rd->last_calculated_value += rd->calculated_value; + rd->collector.last_calculated_value += rd->collector.calculated_value; } else { rrdset_debug(st, "THIS IS THE FIRST POINT"); @@ -1934,16 +1937,16 @@ void rrdset_timed_done(RRDSET *st, struct timeval now, bool pending_rrdset_next) rrdset_debug(st, "%s: setting last_calculated_value (old: " NETDATA_DOUBLE_FORMAT ") to " "last_calculated_value (new: " NETDATA_DOUBLE_FORMAT ")" , rrddim_name(rd) - , rd->last_calculated_value - , rd->calculated_value); + , rd->collector.last_calculated_value + , rd->collector.calculated_value); - rd->last_calculated_value = rd->calculated_value; + rd->collector.last_calculated_value = rd->collector.calculated_value; break; } - rd->calculated_value = 0; - rd->collected_value = 0; - rd->updated = 0; + rd->collector.calculated_value = 0; + rd->collector.collected_value = 0; + rrddim_clear_updated(rd); rrdset_debug(st, "%s: END " " last_collected_value = " COLLECTED_NUMBER_FORMAT @@ -1951,14 +1954,14 @@ void rrdset_timed_done(RRDSET *st, struct timeval now, bool pending_rrdset_next) " last_calculated_value = " NETDATA_DOUBLE_FORMAT " calculated_value = " NETDATA_DOUBLE_FORMAT , rrddim_name(rd) - , rd->last_collected_value - , rd->collected_value - , rd->last_calculated_value - , rd->calculated_value + , rd->collector.last_collected_value + , rd->collector.collected_value + , rd->collector.last_calculated_value + , rd->collector.calculated_value ); } - netdata_spinlock_unlock(&st->data_collection_lock); + spinlock_unlock(&st->data_collection_lock); rrdset_push_metrics_finished(&stream_buffer, st); // ALL DONE ABOUT THE DATA UPDATE @@ -1991,6 +1994,8 @@ void rrdset_timed_done(RRDSET *st, struct timeval now, bool pending_rrdset_next) } time_t rrdset_set_update_every_s(RRDSET *st, time_t update_every_s) { + if(unlikely(update_every_s == st->update_every)) + return st->update_every; internal_error(true, "RRDSET '%s' switching update every from %d to %d", rrdset_id(st), (int)st->update_every, (int)update_every_s); @@ -2007,10 +2012,6 @@ time_t rrdset_set_update_every_s(RRDSET *st, time_t update_every_s) { rd->tiers[tier].db_collection_handle, (int)(st->rrdhost->db[tier].tier_grouping * st->update_every)); } - - assert(rd->update_every == (int) prev_update_every_s && - "chart's update every differs from the update every of its dimensions"); - rd->update_every = st->update_every; } rrddim_foreach_done(rd); @@ -2094,10 +2095,10 @@ struct rrdset_map_save_v019 { }; void rrdset_memory_file_update(RRDSET *st) { - if(!st->st_on_file) return; - struct rrdset_map_save_v019 *st_on_file = st->st_on_file; + if(!st->db.st_on_file) return; + struct rrdset_map_save_v019 *st_on_file = st->db.st_on_file; - st_on_file->current_entry = st->current_entry; + st_on_file->current_entry = st->db.current_entry; st_on_file->counter = st->counter; st_on_file->usec_since_last_update = st->usec_since_last_update; st_on_file->last_updated.tv_sec = st->last_updated.tv_sec; @@ -2105,41 +2106,41 @@ void rrdset_memory_file_update(RRDSET *st) { } const char *rrdset_cache_filename(RRDSET *st) { - if(!st->st_on_file) return NULL; - struct rrdset_map_save_v019 *st_on_file = st->st_on_file; + if(!st->db.st_on_file) return NULL; + struct rrdset_map_save_v019 *st_on_file = st->db.st_on_file; return st_on_file->cache_filename; } const char *rrdset_cache_dir(RRDSET *st) { - if(!st->cache_dir) - st->cache_dir = rrdhost_cache_dir_for_rrdset_alloc(st->rrdhost, rrdset_id(st)); + if(!st->db.cache_dir) + st->db.cache_dir = rrdhost_cache_dir_for_rrdset_alloc(st->rrdhost, rrdset_id(st)); - return st->cache_dir; + return st->db.cache_dir; } void rrdset_memory_file_free(RRDSET *st) { - if(!st->st_on_file) return; + if(!st->db.st_on_file) return; // needed for memory mode map, to save the latest state rrdset_memory_file_update(st); - struct rrdset_map_save_v019 *st_on_file = st->st_on_file; + struct rrdset_map_save_v019 *st_on_file = st->db.st_on_file; __atomic_sub_fetch(&rrddim_db_memory_size, st_on_file->memsize, __ATOMIC_RELAXED); netdata_munmap(st_on_file, st_on_file->memsize); // remove the pointers from the RRDDIM - st->st_on_file = NULL; + st->db.st_on_file = NULL; } void rrdset_memory_file_save(RRDSET *st) { - if(!st->st_on_file) return; + if(!st->db.st_on_file) return; rrdset_memory_file_update(st); - struct rrdset_map_save_v019 *st_on_file = st->st_on_file; + struct rrdset_map_save_v019 *st_on_file = st->db.st_on_file; if(st_on_file->rrd_memory_mode != RRD_MEMORY_MODE_SAVE) return; - memory_file_save(st_on_file->cache_filename, st->st_on_file, st_on_file->memsize); + memory_file_save(st_on_file->cache_filename, st->db.st_on_file, st_on_file->memsize); } bool rrdset_memory_load_or_create_map_save(RRDSET *st, RRD_MEMORY_MODE memory_mode) { @@ -2159,27 +2160,27 @@ bool rrdset_memory_load_or_create_map_save(RRDSET *st, RRD_MEMORY_MODE memory_mo st_on_file->magic[sizeof(RRDSET_MAGIC_V019)] = '\0'; if(strcmp(st_on_file->magic, RRDSET_MAGIC_V019) != 0) { - info("Initializing file '%s'.", fullfilename); + netdata_log_info("Initializing file '%s'.", fullfilename); memset(st_on_file, 0, size); } else if(strncmp(st_on_file->id, rrdset_id(st), RRD_ID_LENGTH_MAX_V019) != 0) { - error("File '%s' contents are not for chart '%s'. Clearing it.", fullfilename, rrdset_id(st)); + netdata_log_error("File '%s' contents are not for chart '%s'. Clearing it.", fullfilename, rrdset_id(st)); memset(st_on_file, 0, size); } - else if(st_on_file->memsize != size || st_on_file->entries != st->entries) { - error("File '%s' does not have the desired size. Clearing it.", fullfilename); + else if(st_on_file->memsize != size || st_on_file->entries != st->db.entries) { + netdata_log_error("File '%s' does not have the desired size. Clearing it.", fullfilename); memset(st_on_file, 0, size); } else if(st_on_file->update_every != st->update_every) { - error("File '%s' does not have the desired granularity. Clearing it.", fullfilename); + netdata_log_error("File '%s' does not have the desired granularity. Clearing it.", fullfilename); memset(st_on_file, 0, size); } - else if((now_s - st_on_file->last_updated.tv_sec) > st->update_every * st->entries) { - info("File '%s' is too old. Clearing it.", fullfilename); + else if((now_s - st_on_file->last_updated.tv_sec) > (long)st->update_every * (long)st->db.entries) { + netdata_log_info("File '%s' is too old. Clearing it.", fullfilename); memset(st_on_file, 0, size); } else if(st_on_file->last_updated.tv_sec > now_s + st->update_every) { - error("File '%s' refers to the future by %zd secs. Resetting it to now.", fullfilename, (ssize_t)(st_on_file->last_updated.tv_sec - now_s)); + netdata_log_error("File '%s' refers to the future by %zd secs. Resetting it to now.", fullfilename, (ssize_t)(st_on_file->last_updated.tv_sec - now_s)); st_on_file->last_updated.tv_sec = now_s; } @@ -2194,14 +2195,14 @@ bool rrdset_memory_load_or_create_map_save(RRDSET *st, RRD_MEMORY_MODE memory_mo } // copy the useful values to st - st->current_entry = st_on_file->current_entry; + st->db.current_entry = st_on_file->current_entry; st->counter = st_on_file->counter; st->usec_since_last_update = st_on_file->usec_since_last_update; st->last_updated.tv_sec = st_on_file->last_updated.tv_sec; st->last_updated.tv_usec = st_on_file->last_updated.tv_usec; // link it to st - st->st_on_file = st_on_file; + st->db.st_on_file = st_on_file; // clear everything memset(st_on_file, 0, size); @@ -2211,7 +2212,7 @@ bool rrdset_memory_load_or_create_map_save(RRDSET *st, RRD_MEMORY_MODE memory_mo strcpy(st_on_file->cache_filename, fullfilename); strcpy(st_on_file->magic, RRDSET_MAGIC_V019); st_on_file->memsize = size; - st_on_file->entries = st->entries; + st_on_file->entries = st->db.entries; st_on_file->update_every = st->update_every; st_on_file->rrd_memory_mode = memory_mode; -- cgit v1.2.3