rrd metadata search fix (#20203)
rrdset/rrddim find calls now have an extra option to enable/disable searching for obsolete metadata
Costa Tsaousis committed
Apr 29, 2025 at 13:03 UTC
97e4d505156938ad09a9201c072cdf5a54677b19
17 files changed
+47
-52
src/collectors/proc.plugin/proc_loadavg.c
+1
-1
@@ -12,7 +12,7 @@ static const RRDVAR_ACQUIRED *rd_pidmax = NULL;
12
13
void proc_loadavg_plugin_cleanup(void) {
14
// Cleanup any acquired RRDVARs
15
- RRDSET *st = rrdset_find_localhost("system.active_processes");
15
+ RRDSET *st = rrdset_find(localhost, "system.active_processes", true);
16
if (st && rd_pidmax) {
17
rrdvar_chart_variable_release(st, rd_pidmax);
18
rd_pidmax = NULL;
src/daemon/pulse/pulse-workers.c
+3
-3
@@ -184,7 +184,7 @@ static void workers_total_spinlock_contention_chart(void) {
184
wusp;
185
wusp = SPINLOCKS_NEXT(&ALL_SPINLOCKS, &idx)) {
186
const char *func = (const char *)idx;
187
- RRDDIM *rd = rrddim_find(st, func);
187
+ RRDDIM *rd = rrddim_find(st, func, false);
188
if(!rd) rd = rrddim_add(st, func, NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
189
rrddim_set_by_pointer(st, rd, (collected_number)wusp->locks);
190
}
@@ -216,7 +216,7 @@ static void workers_total_spinlock_contention_chart(void) {
216
wusp;
217
wusp = SPINLOCKS_NEXT(&ALL_SPINLOCKS, &idx)) {
218
const char *func = (const char *)idx;
219
- RRDDIM *rd = rrddim_find(st, func);
219
+ RRDDIM *rd = rrddim_find(st, func, false);
220
if(!rd) rd = rrddim_add(st, func, NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
221
rrddim_set_by_pointer(st, rd, (collected_number)wusp->spins);
222
}
@@ -248,7 +248,7 @@ static void workers_total_spinlock_contention_chart(void) {
248
wusp;
249
wusp = SPINLOCKS_NEXT(&ALL_SPINLOCKS, &idx)) {
250
const char *func = (const char *)idx;
251
- RRDDIM *rd = rrddim_find(st, func);
251
+ RRDDIM *rd = rrddim_find(st, func, false);
252
if(!rd) rd = rrddim_add(st, func, NULL, 1, 10000, RRD_ALGORITHM_ABSOLUTE);
253
if(!wusp->locks)
254
rrddim_set_by_pointer(st, rd, 0);
src/database/rrddim.c
+7
-12
@@ -331,12 +331,12 @@ static inline RRDDIM *rrddim_index_find(RRDSET *st, const char *id) {
331
// ----------------------------------------------------------------------------
332
// RRDDIM - find a dimension
333
334
-inline RRDDIM *rrddim_find(RRDSET *st, const char *id) {
334
+inline RRDDIM *rrddim_find(RRDSET *st, const char *id, bool include_obsolete) {
335
netdata_log_debug(D_RRD_CALLS, "rrddim_find() for chart %s, dimension %s", rrdset_name(st), id);
336
337
RRDDIM *rd = rrddim_index_find(st, id);
338
if(rd) {
339
- if(rrddim_flag_check(rd, RRDDIM_FLAG_OBSOLETE) && !rrdset_is_discoverable(st))
339
+ if(!include_obsolete && rrddim_flag_check(rd, RRDDIM_FLAG_OBSOLETE) && !rrdset_is_discoverable(st))
340
return NULL;
341
342
rd->rrdset->last_accessed_time_s = now_realtime_sec();
@@ -345,13 +345,13 @@ inline RRDDIM *rrddim_find(RRDSET *st, const char *id) {
345
return rd;
346
}
347
348
-inline RRDDIM_ACQUIRED *rrddim_find_and_acquire(RRDSET *st, const char *id) {
348
+inline RRDDIM_ACQUIRED *rrddim_find_and_acquire(RRDSET *st, const char *id, bool include_obsolete) {
349
netdata_log_debug(D_RRD_CALLS, "rrddim_find_and_acquire() for chart %s, dimension %s", rrdset_name(st), id);
350
351
RRDDIM_ACQUIRED *rda = (RRDDIM_ACQUIRED *)dictionary_get_and_acquire_item(st->rrddim_root_index, id);
352
if(rda) {
353
- RRDDIM *rd = (RRDDIM *) dictionary_acquired_item_value((const DICTIONARY_ITEM *)rda);
354
- if(rrddim_flag_check(rd, RRDDIM_FLAG_OBSOLETE) && !rrdset_is_discoverable(st)) {
353
+ RRDDIM *rd = dictionary_acquired_item_value((const DICTIONARY_ITEM *)rda);
354
+ if(!include_obsolete && rrddim_flag_check(rd, RRDDIM_FLAG_OBSOLETE) && !rrdset_is_discoverable(st)) {
355
dictionary_acquired_item_release(st->rrddim_root_index, (const DICTIONARY_ITEM *)rda);
356
return NULL;
357
}
@@ -377,11 +377,6 @@ void rrddim_acquired_release(RRDDIM_ACQUIRED *rda) {
377
dictionary_acquired_item_release(rd->rrdset->rrddim_root_index, (const DICTIONARY_ITEM *)rda);
378
}
379
380
-// This will not return dimensions that are archived
381
-RRDDIM *rrddim_find_active(RRDSET *st, const char *id) {
382
- return rrddim_find(st, id);
383
-}
384
-
380
// ----------------------------------------------------------------------------
381
// RRDDIM rename a dimension
382
@@ -550,7 +545,7 @@ int rrddim_hide(RRDSET *st, const char *id) {
545
546
RRDHOST *host = st->rrdhost;
547
553
- RRDDIM *rd = rrddim_find(st, id);
548
+ RRDDIM *rd = rrddim_find(st, id, true);
549
if(unlikely(!rd)) {
550
netdata_log_error("Cannot find dimension with id '%s' on stats '%s' (%s) on host '%s'.", id, rrdset_name(st), rrdset_id(st), rrdhost_hostname(host));
551
return 1;
@@ -570,7 +565,7 @@ int rrddim_unhide(RRDSET *st, const char *id) {
565
netdata_log_debug(D_RRD_CALLS, "rrddim_unhide() for chart %s, dimension %s", rrdset_name(st), id);
566
567
RRDHOST *host = st->rrdhost;
573
- RRDDIM *rd = rrddim_find(st, id);
568
+ RRDDIM *rd = rrddim_find(st, id, true);
569
if(unlikely(!rd)) {
570
netdata_log_error("Cannot find dimension with id '%s' on stats '%s' (%s) on host '%s'.", id, rrdset_name(st), rrdset_id(st), rrdhost_hostname(host));
571
return 1;
src/database/rrddim.h
+3
-3
@@ -214,11 +214,11 @@ int rrddim_set_algorithm(RRDSET *st, RRDDIM *rd, RRD_ALGORITHM algorithm);
214
int rrddim_set_multiplier(RRDSET *st, RRDDIM *rd, int32_t multiplier);
215
int rrddim_set_divisor(RRDSET *st, RRDDIM *rd, int32_t divisor);
216
217
-RRDDIM *rrddim_find(RRDSET *st, const char *id);
218
-RRDDIM_ACQUIRED *rrddim_find_and_acquire(RRDSET *st, const char *id);
217
+RRDDIM *rrddim_find(RRDSET *st, const char *id, bool include_obsolete);
218
+RRDDIM_ACQUIRED *rrddim_find_and_acquire(RRDSET *st, const char *id, bool include_obsolete);
219
RRDDIM *rrddim_acquired_to_rrddim(RRDDIM_ACQUIRED *rda);
220
void rrddim_acquired_release(RRDDIM_ACQUIRED *rda);
221
-RRDDIM *rrddim_find_active(RRDSET *st, const char *id);
221
+#define rrddim_find_active(st, id) rrddim_find(st, id, false)
222
223
int rrddim_hide(RRDSET *st, const char *id);
224
int rrddim_unhide(RRDSET *st, const char *id);
src/database/rrdset-index-id.c
+7
-7
@@ -333,12 +333,12 @@ static RRDSET *rrdset_index_find(RRDHOST *host, const char *id) {
333
return dictionary_get(host->rrdset_root_index, id);
334
}
335
336
-RRDSET *rrdset_find(RRDHOST *host, const char *id) {
336
+RRDSET *rrdset_find(RRDHOST *host, const char *id, bool include_obsolete) {
337
netdata_log_debug(D_RRD_CALLS, "rrdset_find() for chart '%s' in host '%s'", id, rrdhost_hostname(host));
338
RRDSET *st = rrdset_index_find(host, id);
339
340
if(st) {
341
- if(!rrdset_is_discoverable(st))
341
+ if(!include_obsolete && !rrdset_is_discoverable(st))
342
return NULL;
343
344
st->last_accessed_time_s = now_realtime_sec();
@@ -347,7 +347,7 @@ RRDSET *rrdset_find(RRDHOST *host, const char *id) {
347
return(st);
348
}
349
350
-RRDSET *rrdset_find_bytype(RRDHOST *host, const char *type, const char *id) {
350
+RRDSET *rrdset_find_bytype(RRDHOST *host, const char *type, const char *id, bool include_obsolete) {
351
netdata_log_debug(D_RRD_CALLS, "rrdset_find_bytype() for chart '%s.%s' in host '%s'", type, id, rrdhost_hostname(host));
352
353
char buf[RRD_ID_LENGTH_MAX + 1];
@@ -356,17 +356,17 @@ RRDSET *rrdset_find_bytype(RRDHOST *host, const char *type, const char *id) {
356
int len = (int) strlen(buf);
357
strncpyz(&buf[len], id, (size_t) (RRD_ID_LENGTH_MAX - len));
358
359
- return(rrdset_find(host, buf));
359
+ return rrdset_find(host, buf, include_obsolete);
360
}
361
362
-RRDSET_ACQUIRED *rrdset_find_and_acquire(RRDHOST *host, const char *id) {
362
+RRDSET_ACQUIRED *rrdset_find_and_acquire(RRDHOST *host, const char *id, bool include_obsolete) {
363
netdata_log_debug(D_RRD_CALLS, "rrdset_find_and_acquire() for host %s, chart %s", rrdhost_hostname(host), id);
364
365
RRDSET_ACQUIRED *sta = (RRDSET_ACQUIRED *)dictionary_get_and_acquire_item(host->rrdset_root_index, id);
366
if(sta) {
367
- RRDSET *st = (RRDSET *) dictionary_acquired_item_value((const DICTIONARY_ITEM *)sta);
367
+ RRDSET *st = dictionary_acquired_item_value((const DICTIONARY_ITEM *)sta);
368
if(st) {
369
- if(!rrdset_is_discoverable(st)) {
369
+ if(!include_obsolete && !rrdset_is_discoverable(st)) {
370
dictionary_acquired_item_release(host->rrdset_root_index, (const DICTIONARY_ITEM *)sta);
371
return NULL;
372
}
src/database/rrdset-index-id.h
+11
-11
@@ -65,27 +65,27 @@ void rrdset_index_destroy(RRDHOST *host);
65
66
void rrdset_free(RRDSET *st);
67
68
-RRDSET *rrdset_find(RRDHOST *host, const char *id);
69
-RRDSET *rrdset_find_bytype(RRDHOST *host, const char *type, const char *id);
68
+RRDSET *rrdset_find(RRDHOST *host, const char *id, bool include_obsolete);
69
+RRDSET *rrdset_find_bytype(RRDHOST *host, const char *type, const char *id, bool include_obsolete);
70
71
-RRDSET_ACQUIRED *rrdset_find_and_acquire(RRDHOST *host, const char *id);
71
+RRDSET_ACQUIRED *rrdset_find_and_acquire(RRDHOST *host, const char *id, bool include_obsolete);
72
73
void rrdset_acquired_release(RRDSET_ACQUIRED *rsa);
74
RRDSET *rrdset_acquired_to_rrdset(RRDSET_ACQUIRED *rsa);
75
76
uint16_t rrddim_collection_modulo(RRDSET *st, uint32_t spread);
77
78
-#define rrdset_find_localhost(id) rrdset_find(localhost, id)
79
-/* This will not return charts that are archived */
80
-static inline RRDSET *rrdset_find_active_localhost(const char *id) {
81
- RRDSET *st = rrdset_find_localhost(id);
78
+/* This will not return charts that are obsolete */
79
+ALWAYS_INLINE
80
+static RRDSET *rrdset_find_active_localhost(const char *id) {
81
+ RRDSET *st = rrdset_find(localhost, id, false);
82
return st;
83
}
84
85
-#define rrdset_find_bytype_localhost(type, id) rrdset_find_bytype(localhost, type, id)
86
-/* This will not return charts that are archived */
87
-static inline RRDSET *rrdset_find_active_bytype_localhost(const char *type, const char *id) {
88
- RRDSET *st = rrdset_find_bytype_localhost(type, id);
85
+/* This will not return charts that are obsolete */
86
+ALWAYS_INLINE
87
+static RRDSET *rrdset_find_active_bytype_localhost(const char *type, const char *id) {
88
+ RRDSET *st = rrdset_find_bytype(localhost, type, id, false);
89
return st;
90
}
91
src/health/health_variable.c
+1
-1
@@ -118,7 +118,7 @@ static bool variable_lookup_context(struct variable_lookup_job *vbd, const char
118
119
// lookup chart in host
120
121
- RRDSET_ACQUIRED *rsa = rrdset_find_and_acquire(vbd->host, chart_or_context);
121
+ RRDSET_ACQUIRED *rsa = rrdset_find_and_acquire(vbd->host, chart_or_context, false);
122
if(rsa) {
123
if(variable_lookup_in_chart(vbd, rrdset_acquired_to_rrdset(rsa), false))
124
found = true;
src/ml/ml_dimension.h
+2
-2
@@ -83,11 +83,11 @@ public:
83
if (AcqRH) {
84
RRDHOST *RH = rrdhost_acquired_to_rrdhost(AcqRH);
85
if (RH && !rrdhost_flag_check(RH, RRDHOST_FLAG_ORPHAN | RRDHOST_FLAG_ARCHIVED)) {
86
- AcqRS = rrdset_find_and_acquire(RH, DLI.chartId());
86
+ AcqRS = rrdset_find_and_acquire(RH, DLI.chartId(), false);
87
if (AcqRS) {
88
RRDSET *RS = rrdset_acquired_to_rrdset(AcqRS);
89
if (RS && !rrdset_flag_check(RS, RRDSET_FLAG_OBSOLETE)) {
90
- AcqRD = rrddim_find_and_acquire(RS, DLI.dimensionId());
90
+ AcqRD = rrddim_find_and_acquire(RS, DLI.dimensionId(), false);
91
if (AcqRD) {
92
RRDDIM *RD = rrddim_acquired_to_rrddim(AcqRD);
93
if (RD) {
src/plugins.d/pluginsd_internals.h
+3
-3
@@ -149,7 +149,7 @@ static inline void pluginsd_rrddim_put_to_slot(PARSER *parser, RRDSET *st, RRDDI
149
struct pluginsd_rrddim *prd = &st->pluginsd.prd_array[slot - 1];
150
151
if(prd->rd != rd) {
152
- prd->rda = rrddim_find_and_acquire(st, string2str(rd->id));
152
+ prd->rda = rrddim_find_and_acquire(st, string2str(rd->id), true);
153
prd->rd = rrddim_acquired_to_rrddim(prd->rda);
154
prd->id = string2str(prd->rd->id);
155
}
@@ -235,7 +235,7 @@ static ALWAYS_INLINE RRDDIM *pluginsd_acquire_dimension(RRDHOST *host, RRDSET *s
235
236
// we need to find the dimension and set it to prd
237
238
- RRDDIM_ACQUIRED *rda = rrddim_find_and_acquire(st, dimension);
238
+ RRDDIM_ACQUIRED *rda = rrddim_find_and_acquire(st, dimension, true);
239
if (unlikely(!rda)) {
240
netdata_log_error("PLUGINSD: 'host:%s/chart:%s/dim:%s' got a %s but dimension does not exist.",
241
rrdhost_hostname(host), rrdset_id(st), dimension, cmd);
@@ -257,7 +257,7 @@ static inline RRDSET *pluginsd_find_chart(RRDHOST *host, const char *chart, cons
257
return NULL;
258
}
259
260
- RRDSET *st = rrdset_find(host, chart);
260
+ RRDSET *st = rrdset_find(host, chart, true);
261
if (unlikely(!st))
262
netdata_log_error("PLUGINSD: 'host:%s/chart:%s' got a %s but chart does not exist.",
263
rrdhost_hostname(host), chart, cmd);
src/streaming/stream-replication-sender.c
+2
-2
@@ -1194,7 +1194,7 @@ static bool replication_execute_request(struct replication_request *rq, bool wor
1194
1195
if(!rq->st) {
1196
if(likely(workers)) worker_is_busy(WORKER_JOB_FIND_CHART);
1197
- rq->st = rrdset_find(rq->sender->host, string2str(rq->chart_id));
1197
+ rq->st = rrdset_find(rq->sender->host, string2str(rq->chart_id), true);
1198
if(!rq->st) {
1199
__atomic_add_fetch(&replication_globals.atomic.error_not_found, 1, __ATOMIC_RELAXED);
1200
nd_log(NDLS_DAEMON, NDLP_ERR,
@@ -1554,7 +1554,7 @@ static int replication_pipeline_execute_next(void) {
1554
if(!rq->start_streaming) {
1555
if (!rq->st) {
1556
worker_is_busy(WORKER_JOB_FIND_CHART);
1557
- rq->st = rrdset_find(rq->sender->host, string2str(rq->chart_id));
1557
+ rq->st = rrdset_find(rq->sender->host, string2str(rq->chart_id), true);
1558
}
1559
1560
if (rq->st && !rq->q) {
src/streaming/stream-sender-execute.c
+1
-1
@@ -286,7 +286,7 @@ void stream_sender_execute_commands(struct sender_state *s) {
286
}
287
else {
288
#ifdef REPLICATION_TRACKING
289
- RRDSET *st = rrdset_find(s->host, chart_id);
289
+ RRDSET *st = rrdset_find(s->host, chart_id, true);
290
if(st)
291
st->stream.snd.who = REPLAY_WHO_ME;
292
#endif
src/web/api/queries/backfill.c
+1
-1
@@ -52,7 +52,7 @@ bool backfill_request_add(RRDSET *st, backfill_callback_t cb, struct backfill_re
52
struct backfill_request *br = aral_callocz(backfill_globals.ar_br);
53
br->data = *data;
54
br->host_state_id = object_state_id(&st->rrdhost->state_id);
55
- br->rsa = rrdset_find_and_acquire(st->rrdhost, string2str(st->id));
55
+ br->rsa = rrdset_find_and_acquire(st->rrdhost, string2str(st->id), true);
56
if(br->rsa) {
57
br->cb = cb;
58
src/web/api/v1/api_v1_alarms.c
+1
-1
@@ -128,7 +128,7 @@ int api_v1_variable(RRDHOST *host, struct web_client *w, char *url) {
128
goto cleanup;
129
}
130
131
- RRDSET *st = rrdset_find(host, chart);
131
+ RRDSET *st = rrdset_find(host, chart, false);
132
if(!st) st = rrdset_find_byname(host, chart);
133
if(!st) {
134
buffer_strcat(w->response.data, "Chart is not found: ");
src/web/api/v1/api_v1_badge/web_buffer_svg.c
+1
-1
@@ -962,7 +962,7 @@ int api_v1_badge(RRDHOST *host, struct web_client *w, char *url) {
962
963
int scale = (scale_str && *scale_str)?str2i(scale_str):100;
964
965
- st = rrdset_find(host, chart);
965
+ st = rrdset_find(host, chart, false);
966
if(!st) st = rrdset_find_byname(host, chart);
967
if(!st) {
968
buffer_no_cacheable(w->response.data);
src/web/api/v1/api_v1_charts.c
+1
-1
@@ -31,7 +31,7 @@ int api_v1_single_chart_helper(RRDHOST *host, struct web_client *w, char *url, v
31
goto cleanup;
32
}
33
34
- RRDSET *st = rrdset_find(host, chart);
34
+ RRDSET *st = rrdset_find(host, chart, false);
35
if(!st) st = rrdset_find_byname(host, chart);
36
if(!st) {
37
buffer_strcat(w->response.data, "Chart is not found: ");
src/web/api/v1/api_v1_data.c
+1
-1
@@ -137,7 +137,7 @@ int api_v1_data(RRDHOST *host, struct web_client *w, char *url) {
137
138
if(chart && !context) {
139
// check if this is a specific chart
140
- st = rrdset_find(host, chart);
140
+ st = rrdset_find(host, chart, false);
141
if (!st) st = rrdset_find_byname(host, chart);
142
}
143
src/web/server/web_client.c
+1
-1
@@ -1207,7 +1207,7 @@ static inline int web_client_process_url(RRDHOST *host, struct web_client *w, ch
1207
1208
// do we have such a data set?
1209
RRDSET *st = rrdset_find_byname(host, tok);
1210
- if(!st) st = rrdset_find(host, tok);
1210
+ if(!st) st = rrdset_find(host, tok, false);
1211
if(!st) {
1212
w->response.data->content_type = CT_TEXT_HTML;
1213
buffer_strcat(w->response.data, "Chart is not found: ");