rrdset/rrddim find function do not return obsolete metadata (#20196)
Costa Tsaousis committed
Apr 28, 2025 at 14:07 UTC
d5db211f370917af785b15e15bdb323c7cdc8446
3 files changed
+50
-11
src/database/rrddim.c
+23
-9
@@ -334,13 +334,32 @@ static inline RRDDIM *rrddim_index_find(RRDSET *st, const char *id) {
334
inline RRDDIM *rrddim_find(RRDSET *st, const char *id) {
335
netdata_log_debug(D_RRD_CALLS, "rrddim_find() for chart %s, dimension %s", rrdset_name(st), id);
336
337
- return rrddim_index_find(st, id);
337
+ RRDDIM *rd = rrddim_index_find(st, id);
338
+ if(rd) {
339
+ if(rrddim_flag_check(rd, RRDDIM_FLAG_OBSOLETE))
340
+ return NULL;
341
+
342
+ rd->rrdset->last_accessed_time_s = now_realtime_sec();
343
+ }
344
+
345
+ return rd;
346
}
347
348
inline RRDDIM_ACQUIRED *rrddim_find_and_acquire(RRDSET *st, const char *id) {
349
netdata_log_debug(D_RRD_CALLS, "rrddim_find_and_acquire() for chart %s, dimension %s", rrdset_name(st), id);
350
343
- return (RRDDIM_ACQUIRED *)dictionary_get_and_acquire_item(st->rrddim_root_index, id);
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)) {
355
+ dictionary_acquired_item_release(st->rrddim_root_index, (const DICTIONARY_ITEM *)rda);
356
+ return NULL;
357
+ }
358
+
359
+ rd->rrdset->last_accessed_time_s = now_realtime_sec();
360
+ }
361
+
362
+ return rda;
363
}
364
365
RRDDIM *rrddim_acquired_to_rrddim(RRDDIM_ACQUIRED *rda) {
@@ -360,12 +379,7 @@ void rrddim_acquired_release(RRDDIM_ACQUIRED *rda) {
379
380
// This will not return dimensions that are archived
381
RRDDIM *rrddim_find_active(RRDSET *st, const char *id) {
363
- RRDDIM *rd = rrddim_find(st, id);
364
-
365
- if(rd && rrddim_flag_check(rd, RRDDIM_FLAG_OBSOLETE))
366
- rd = NULL;
367
-
368
- return rd;
382
+ return rrddim_find(st, id);
383
}
384
385
// ----------------------------------------------------------------------------
@@ -622,7 +636,7 @@ collected_number rrddim_timed_set_by_pointer(RRDSET *st __maybe_unused, RRDDIM *
636
637
collected_number rrddim_set(RRDSET *st, const char *id, collected_number value) {
638
RRDHOST *host = st->rrdhost;
625
- RRDDIM *rd = rrddim_find(st, id);
639
+ RRDDIM *rd = rrddim_find_active(st, id);
640
if(unlikely(!rd)) {
641
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));
642
return 0;
src/database/rrdset-index-id.c
+19
-2
@@ -337,8 +337,12 @@ RRDSET *rrdset_find(RRDHOST *host, const char *id) {
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)
340
+ if(st) {
341
+ if(rrdset_flag_check(st, RRDSET_FLAG_OBSOLETE))
342
+ return NULL;
343
+
344
st->last_accessed_time_s = now_realtime_sec();
345
+ }
346
347
return(st);
348
}
@@ -358,7 +362,20 @@ RRDSET *rrdset_find_bytype(RRDHOST *host, const char *type, const char *id) {
362
RRDSET_ACQUIRED *rrdset_find_and_acquire(RRDHOST *host, const char *id) {
363
netdata_log_debug(D_RRD_CALLS, "rrdset_find_and_acquire() for host %s, chart %s", rrdhost_hostname(host), id);
364
361
- return (RRDSET_ACQUIRED *)dictionary_get_and_acquire_item(host->rrdset_root_index, id);
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);
368
+ if(st) {
369
+ if(rrdset_flag_check(st, RRDSET_FLAG_OBSOLETE)) {
370
+ dictionary_acquired_item_release(host->rrdset_root_index, (const DICTIONARY_ITEM *)sta);
371
+ return NULL;
372
+ }
373
+
374
+ st->last_accessed_time_s = now_realtime_sec();
375
+ }
376
+ }
377
+
378
+ return sta;
379
}
380
381
RRDSET *rrdset_acquired_to_rrdset(RRDSET_ACQUIRED *rsa) {
src/database/rrdset-index-name.c
+8
@@ -109,5 +109,13 @@ void rrdset_index_del_name(RRDHOST *host, RRDSET *st) {
109
110
RRDSET *rrdset_find_byname(RRDHOST *host, const char *name) {
111
RRDSET *st = rrdset_index_find_name(host, name);
112
+
113
+ if(st) {
114
+ if (rrdset_flag_check(st, RRDSET_FLAG_OBSOLETE))
115
+ return NULL;
116
+
117
+ st->last_accessed_time_s = now_realtime_sec();
118
+ }
119
+
120
return(st);
121
}