Fix cleanup of obsolete charts (#9985)
* Archive dimensions as well when switching from obsolete charts to archived charts.
Markos Fountoulakis committed
Sep 25, 2020 at 15:45 UTC
2035343d16f3106ad6f6ce5b2fcb7384bc511668
1 file changed
+34
-2
database/rrdhost.c
+34
-2
@@ -1521,9 +1521,41 @@ restart_after_removal:
1521
)) {
1522
#ifdef ENABLE_DBENGINE
1523
if(st->rrd_memory_mode == RRD_MEMORY_MODE_DBENGINE) {
1524
+ RRDDIM *rd, *last;
1525
+
1526
rrdset_flag_set(st, RRDSET_FLAG_ARCHIVED);
1525
- while(st->variables) rrdsetvar_free(st->variables);
1526
- while(st->alarms) rrdsetcalc_unlink(st->alarms);
1527
+ while (st->variables) rrdsetvar_free(st->variables);
1528
+ while (st->alarms) rrdsetcalc_unlink(st->alarms);
1529
+ rrdset_wrlock(st);
1530
+ for (rd = st->dimensions, last = NULL ; likely(rd) ; ) {
1531
+ if (rrddim_flag_check(rd, RRDDIM_FLAG_ARCHIVED))
1532
+ continue;
1533
+
1534
+ rrddim_flag_set(rd, RRDDIM_FLAG_ARCHIVED);
1535
+ while (rd->variables)
1536
+ rrddimvar_free(rd->variables);
1537
+
1538
+ if (rrddim_flag_check(rd, RRDDIM_FLAG_OBSOLETE)) {
1539
+ rrddim_flag_clear(rd, RRDDIM_FLAG_OBSOLETE);
1540
+ /* only a collector can mark a chart as obsolete, so we must remove the reference */
1541
+ uint8_t can_delete_metric = rd->state->collect_ops.finalize(rd);
1542
+ if (can_delete_metric) {
1543
+ /* This metric has no data and no references */
1544
+ metalog_commit_delete_dimension(rd);
1545
+ rrddim_free(st, rd);
1546
+ if (unlikely(!last)) {
1547
+ rd = st->dimensions;
1548
+ }
1549
+ else {
1550
+ rd = last->next;
1551
+ }
1552
+ continue;
1553
+ }
1554
+ }
1555
+ last = rd;
1556
+ rd = rd->next;
1557
+ }
1558
+ rrdset_unlock(st);
1559
1560
debug(D_RRD_CALLS, "RRDSET: Cleaning up remaining chart variables for host '%s', chart '%s'", host->hostname, st->id);
1561
rrdvar_free_remaining_variables(host, &st->rrdvar_root_index);