summaryrefslogtreecommitdiffstats
path: root/database
diff options
context:
space:
mode:
authorMarkos Fountoulakis <44345837+mfundul@users.noreply.github.com>2020-09-25 15:45:25 +0300
committerGitHub <noreply@github.com>2020-09-25 15:45:25 +0300
commit2035343d16f3106ad6f6ce5b2fcb7384bc511668 (patch)
treece60aa9967addfed554ed10380a43b3be80edcd0 /database
parente97d1062e872d15a68001866ddc6f2d6971c5039 (diff)
Fix cleanup of obsolete charts (#9985)
* Archive dimensions as well when switching from obsolete charts to archived charts.
Diffstat (limited to 'database')
-rw-r--r--database/rrdhost.c36
1 files changed, 34 insertions, 2 deletions
diff --git a/database/rrdhost.c b/database/rrdhost.c
index c5e0e069cd..421acbb65d 100644
--- a/database/rrdhost.c
+++ b/database/rrdhost.c
@@ -1521,9 +1521,41 @@ restart_after_removal:
)) {
#ifdef ENABLE_DBENGINE
if(st->rrd_memory_mode == RRD_MEMORY_MODE_DBENGINE) {
+ RRDDIM *rd, *last;
+
rrdset_flag_set(st, RRDSET_FLAG_ARCHIVED);
- while(st->variables) rrdsetvar_free(st->variables);
- while(st->alarms) rrdsetcalc_unlink(st->alarms);
+ while (st->variables) rrdsetvar_free(st->variables);
+ while (st->alarms) rrdsetcalc_unlink(st->alarms);
+ rrdset_wrlock(st);
+ for (rd = st->dimensions, last = NULL ; likely(rd) ; ) {
+ if (rrddim_flag_check(rd, RRDDIM_FLAG_ARCHIVED))
+ continue;
+
+ rrddim_flag_set(rd, RRDDIM_FLAG_ARCHIVED);
+ while (rd->variables)
+ rrddimvar_free(rd->variables);
+
+ if (rrddim_flag_check(rd, RRDDIM_FLAG_OBSOLETE)) {
+ rrddim_flag_clear(rd, RRDDIM_FLAG_OBSOLETE);
+ /* only a collector can mark a chart as obsolete, so we must remove the reference */
+ uint8_t can_delete_metric = rd->state->collect_ops.finalize(rd);
+ if (can_delete_metric) {
+ /* This metric has no data and no references */
+ metalog_commit_delete_dimension(rd);
+ rrddim_free(st, rd);
+ if (unlikely(!last)) {
+ rd = st->dimensions;
+ }
+ else {
+ rd = last->next;
+ }
+ continue;
+ }
+ }
+ last = rd;
+ rd = rd->next;
+ }
+ rrdset_unlock(st);
debug(D_RRD_CALLS, "RRDSET: Cleaning up remaining chart variables for host '%s', chart '%s'", host->hostname, st->id);
rrdvar_free_remaining_variables(host, &st->rrdvar_root_index);