Revert "fix rrdset name crash on rrdset obsoletion" (#19828)
Revert "fix rrdset name crash on rrdset obsoletion (#19449)" This reverts commit c625dc4fdf82b15e2d8389812a71591947e5bc64.
Costa Tsaousis committed
Mar 12, 2025 at 09:37 UTC
b9bf7632f205378d7104cd5be1a1a3aea2229b2c
3 files changed
+27
-20
src/database/rrdset-index-id.c
+1
-2
@@ -70,6 +70,7 @@ 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);
74
75
st->collection_modulo = rrdset_collection_modulo_init();
76
@@ -290,8 +291,6 @@ static void rrdset_react_callback(const DICTIONARY_ITEM *item __maybe_unused, vo
291
if (ctr->react_action & RRDSET_REACT_NEW) {
292
if(unlikely(rrdcontext_find_chart_uuid(st, &st->chart_uuid)))
293
uuid_generate(st->chart_uuid);
293
-
294
- rrdset_index_add_name(host, st);
294
}
295
rrdset_flag_set(st, RRDSET_FLAG_METADATA_UPDATE);
296
rrdhost_flag_set(host, RRDHOST_FLAG_METADATA_UPDATE);
src/database/rrdset-index-name.c
+25
-17
@@ -57,13 +57,25 @@ 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|RRDSET_FLAG_EXPORTING_IGNORE|RRDSET_FLAG_UPSTREAM_SEND|RRDSET_FLAG_UPSTREAM_IGNORE);
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);
64
rrdset_metadata_updated(st);
65
66
rrdcontext_updated_rrdset_name(st);
67
return 2;
68
}
69
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
+
79
static RRDSET *rrdset_index_find_name(RRDHOST *host, const char *name) {
80
if (unlikely(!host->rrdset_root_index_name))
81
return NULL;
@@ -71,32 +83,28 @@ static RRDSET *rrdset_index_find_name(RRDHOST *host, const char *name) {
83
}
84
85
void rrdset_index_byname_init(RRDHOST *host) {
74
- if(!host->rrdset_root_index_name)
75
- host->rrdset_root_index_name = dictionary_create_view(host->rrdset_root_index);
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
+ }
94
}
95
96
void rrdset_index_add_name(RRDHOST *host, RRDSET *st) {
97
if(!st->name) return;
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
- }
98
+ dictionary_set(host->rrdset_root_index_name, rrdset_name(st), st, sizeof(RRDSET));
99
}
100
101
void rrdset_index_del_name(RRDHOST *host, RRDSET *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
- }
102
+ if(rrdset_flag_check(st, RRDSET_FLAG_INDEXED_NAME))
103
+ dictionary_del(host->rrdset_root_index_name, rrdset_name(st));
104
}
105
106
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));
108
RRDSET *st = rrdset_index_find_name(host, name);
109
return(st);
110
}
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, DICT_ITEM_CONST 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, 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