Optimize the dimensions option store to the metadata database (#12952)
* Add a flag to "cache" the latest hidden status written in the database * rrddim hide and unhide will check "cached" state, update the database if needed and set the cache flag accordingly * Check the dimension option and only do the database update if the cached state is different
Stelios Fragkakis committed
May 18, 2022 at 20:10 UTC
77b30d25d8d4a82272b4e010dd674bd69db0c929
3 files changed
+26
-11
collectors/plugins.d/pluginsd_parser.c
+19
-9
@@ -125,26 +125,36 @@ PARSER_RC pluginsd_dimension_action(void *user, RRDSET *st, char *id, char *name
125
UNUSED(algorithm);
126
127
RRDDIM *rd = rrddim_add(st, id, name, multiplier, divisor, algorithm_type);
128
- rrddim_flag_clear(rd, RRDDIM_FLAG_HIDDEN);
128
+ int unhide_dimension = 1;
129
+
130
rrddim_flag_clear(rd, RRDDIM_FLAG_DONT_DETECT_RESETS_OR_OVERFLOWS);
131
if (options && *options) {
132
if (strstr(options, "obsolete") != NULL)
133
rrddim_is_obsolete(st, rd);
134
else
135
rrddim_isnot_obsolete(st, rd);
135
- if (strstr(options, "hidden") != NULL) {
136
- rrddim_flag_set(rd, RRDDIM_FLAG_HIDDEN);
137
- (void) sql_set_dimension_option(&rd->state->metric_uuid, "hidden");
138
- }
139
- else
140
- (void) sql_set_dimension_option(&rd->state->metric_uuid, NULL);
136
+
137
+ unhide_dimension = !strstr(options, "hidden");
138
+
139
if (strstr(options, "noreset") != NULL)
140
rrddim_flag_set(rd, RRDDIM_FLAG_DONT_DETECT_RESETS_OR_OVERFLOWS);
141
if (strstr(options, "nooverflow") != NULL)
142
rrddim_flag_set(rd, RRDDIM_FLAG_DONT_DETECT_RESETS_OR_OVERFLOWS);
145
- } else {
146
- (void) sql_set_dimension_option(&rd->state->metric_uuid, NULL);
143
+ } else
144
rrddim_isnot_obsolete(st, rd);
145
+
146
+ if (likely(unhide_dimension)) {
147
+ rrddim_flag_clear(rd, RRDDIM_FLAG_HIDDEN);
148
+ if (rrddim_flag_check(rd, RRDDIM_FLAG_META_HIDDEN)) {
149
+ (void)sql_set_dimension_option(&rd->state->metric_uuid, NULL);
150
+ rrddim_flag_clear(rd, RRDDIM_FLAG_META_HIDDEN);
151
+ }
152
+ } else {
153
+ rrddim_flag_set(rd, RRDDIM_FLAG_HIDDEN);
154
+ if (!rrddim_flag_check(rd, RRDDIM_FLAG_META_HIDDEN)) {
155
+ (void)sql_set_dimension_option(&rd->state->metric_uuid, "hidden");
156
+ rrddim_flag_set(rd, RRDDIM_FLAG_META_HIDDEN);
157
+ }
158
}
159
return PARSER_RC_OK;
160
}
database/rrd.h
+1
@@ -170,6 +170,7 @@ typedef enum rrddim_flags {
170
RRDDIM_FLAG_ACLK = (1 << 4),
171
172
RRDDIM_FLAG_PENDING_FOREACH_ALARM = (1 << 5), // set when foreach alarm has not been initialized yet
173
+ RRDDIM_FLAG_META_HIDDEN = (1 << 6), // Status of hidden option in the metadata database
174
} RRDDIM_FLAGS;
175
176
#define rrddim_flag_check(rd, flag) (__atomic_load_n(&((rd)->flags), __ATOMIC_SEQ_CST) & (flag))
database/rrddim.c
+6
-2
@@ -472,9 +472,11 @@ int rrddim_hide(RRDSET *st, const char *id) {
472
error("Cannot find dimension with id '%s' on stats '%s' (%s) on host '%s'.", id, st->name, st->id, host->hostname);
473
return 1;
474
}
475
- (void) sql_set_dimension_option(&rd->state->metric_uuid, "hidden");
475
+ if (!rrddim_flag_check(rd, RRDDIM_FLAG_META_HIDDEN))
476
+ (void)sql_set_dimension_option(&rd->state->metric_uuid, "hidden");
477
478
rrddim_flag_set(rd, RRDDIM_FLAG_HIDDEN);
479
+ rrddim_flag_set(rd, RRDDIM_FLAG_META_HIDDEN);
480
return 0;
481
}
482
@@ -487,9 +489,11 @@ int rrddim_unhide(RRDSET *st, const char *id) {
489
error("Cannot find dimension with id '%s' on stats '%s' (%s) on host '%s'.", id, st->name, st->id, host->hostname);
490
return 1;
491
}
490
- (void) sql_set_dimension_option(&rd->state->metric_uuid, NULL);
492
+ if (rrddim_flag_check(rd, RRDDIM_FLAG_META_HIDDEN))
493
+ (void)sql_set_dimension_option(&rd->state->metric_uuid, NULL);
494
495
rrddim_flag_clear(rd, RRDDIM_FLAG_HIDDEN);
496
+ rrddim_flag_clear(rd, RRDDIM_FLAG_META_HIDDEN);
497
return 0;
498
}
499