@cryptotaxi247 / netdata-1 / commits / c625dc4fd

fix rrdset name crash on rrdset obsoletion (#19449)

fix rrdset name crash on cleanup

Costa Tsaousis committed Mar 11, 2025 at 15:55 UTC c625dc4fdf82b15e2d8389812a71591947e5bc64
3 files changed +20 -27
src/database/rrdset-index-id.c
+2 -1
@@ -70,7 +70,6 @@ static void rrdset_insert_callback(const DICTIONARY_ITEM *item __maybe_unused, v
70 st->name = rrdset_fix_name(host, chart_full_id, ctr->type, NULL, ctr->name);
71 if(!st->name)
72 st->name = rrdset_fix_name(host, chart_full_id, ctr->type, NULL, ctr->id);
73 - rrdset_index_add_name(host, st);
73
74 st->collection_modulo = rrdset_collection_modulo_init();
75
@@ -291,6 +290,8 @@ static void rrdset_react_callback(const DICTIONARY_ITEM *item __maybe_unused, vo
290 if (ctr->react_action & RRDSET_REACT_NEW) {
291 if(unlikely(rrdcontext_find_chart_uuid(st, &st->chart_uuid)))
292 uuid_generate(st->chart_uuid);
293 +
294 + rrdset_index_add_name(host, st);
295 }
296 rrdset_flag_set(st, RRDSET_FLAG_METADATA_UPDATE);
297 rrdhost_flag_set(host, RRDHOST_FLAG_METADATA_UPDATE);
src/database/rrdset-index-name.c
+17 -25
@@ -57,25 +57,13 @@ int rrdset_reset_name(RRDSET *st, const char *name) {
57
58 rrdset_index_add_name(host, st);
59
60 - rrdset_flag_clear(st, RRDSET_FLAG_EXPORTING_SEND);
61 - rrdset_flag_clear(st, RRDSET_FLAG_EXPORTING_IGNORE);
62 - rrdset_flag_clear(st, RRDSET_FLAG_UPSTREAM_SEND);
63 - rrdset_flag_clear(st, RRDSET_FLAG_UPSTREAM_IGNORE);
60 + rrdset_flag_clear(st, RRDSET_FLAG_EXPORTING_SEND|RRDSET_FLAG_EXPORTING_IGNORE|RRDSET_FLAG_UPSTREAM_SEND|RRDSET_FLAG_UPSTREAM_IGNORE);
61 rrdset_metadata_updated(st);
62
63 rrdcontext_updated_rrdset_name(st);
64 return 2;
65 }
66
70 -static void rrdset_name_insert_callback(const DICTIONARY_ITEM *item __maybe_unused, void *rrdset, void *rrdhost __maybe_unused) {
71 - RRDSET *st = rrdset;
72 - rrdset_flag_set(st, RRDSET_FLAG_INDEXED_NAME);
73 -}
74 -static void rrdset_name_delete_callback(const DICTIONARY_ITEM *item __maybe_unused, void *rrdset, void *rrdhost __maybe_unused) {
75 - RRDSET *st = rrdset;
76 - rrdset_flag_clear(st, RRDSET_FLAG_INDEXED_NAME);
77 -}
78 -
67 static RRDSET *rrdset_index_find_name(RRDHOST *host, const char *name) {
68 if (unlikely(!host->rrdset_root_index_name))
69 return NULL;
@@ -83,28 +71,32 @@ static RRDSET *rrdset_index_find_name(RRDHOST *host, const char *name) {
71 }
72
73 void rrdset_index_byname_init(RRDHOST *host) {
86 - if(!host->rrdset_root_index_name) {
87 - host->rrdset_root_index_name = dictionary_create_advanced(
88 - DICT_OPTION_NAME_LINK_DONT_CLONE | DICT_OPTION_VALUE_LINK_DONT_CLONE | DICT_OPTION_DONT_OVERWRITE_VALUE,
89 - &dictionary_stats_category_rrdset, 0);
90 -
91 - dictionary_register_insert_callback(host->rrdset_root_index_name, rrdset_name_insert_callback, host);
92 - dictionary_register_delete_callback(host->rrdset_root_index_name, rrdset_name_delete_callback, host);
93 - }
74 + if(!host->rrdset_root_index_name)
75 + host->rrdset_root_index_name = dictionary_create_view(host->rrdset_root_index);
76 }
77
78 void rrdset_index_add_name(RRDHOST *host, RRDSET *st) {
79 if(!st->name) return;
98 - dictionary_set(host->rrdset_root_index_name, rrdset_name(st), st, sizeof(RRDSET));
80 + const DICTIONARY_ITEM *sta = dictionary_get_and_acquire_item(host->rrdset_root_index, rrdset_id(st));
81 + if(sta) {
82 + const DICTIONARY_ITEM *sta2 = dictionary_view_set_and_acquire_item(host->rrdset_root_index_name, rrdset_name(st), sta);
83 + if(sta2 && dictionary_acquired_item_value(sta2) == st)
84 + rrdset_flag_set(st, RRDSET_FLAG_INDEXED_NAME);
85 + }
86 }
87
88 void rrdset_index_del_name(RRDHOST *host, RRDSET *st) {
102 - if(rrdset_flag_check(st, RRDSET_FLAG_INDEXED_NAME))
103 - dictionary_del(host->rrdset_root_index_name, rrdset_name(st));
89 + if(rrdset_flag_check(st, RRDSET_FLAG_INDEXED_NAME)) {
90 + const DICTIONARY_ITEM *sta = dictionary_get_and_acquire_item(host->rrdset_root_index_name, rrdset_name(st));
91 +
92 + if(sta && dictionary_acquired_item_value(sta) == st)
93 + dictionary_del(host->rrdset_root_index_name, rrdset_name(st));
94 +
95 + rrdset_flag_clear(st, RRDSET_FLAG_INDEXED_NAME);
96 + }
97 }
98
99 RRDSET *rrdset_find_byname(RRDHOST *host, const char *name) {
107 - netdata_log_debug(D_RRD_CALLS, "rrdset_find_byname() for chart '%s' in host '%s'", name, rrdhost_hostname(host));
100 RRDSET *st = rrdset_index_find_name(host, name);
101 return(st);
102 }
src/libnetdata/dictionary/dictionary.h
+1 -1
@@ -194,7 +194,7 @@ DICT_ITEM_CONST DICTIONARY_ITEM *dictionary_set_and_acquire_item_advanced(DICTIO
194
195 // set an item in a dictionary view
196 #define dictionary_view_set_and_acquire_item(dict, name, master_item) dictionary_view_set_and_acquire_item_advanced(dict, name, -1, master_item)
197 -DICT_ITEM_CONST DICTIONARY_ITEM *dictionary_view_set_and_acquire_item_advanced(DICTIONARY *dict, const char *name, ssize_t name_len, DICTIONARY_ITEM *master_item);
197 +DICT_ITEM_CONST DICTIONARY_ITEM *dictionary_view_set_and_acquire_item_advanced(DICTIONARY *dict, const char *name, ssize_t name_len, DICT_ITEM_CONST DICTIONARY_ITEM *master_item);
198 #define dictionary_view_set(dict, name, master_item) dictionary_view_set_advanced(dict, name, -1, master_item)
199 void *dictionary_view_set_advanced(DICTIONARY *dict, const char *name, ssize_t name_len, DICT_ITEM_CONST DICTIONARY_ITEM *master_item);
200