0
0
Fork 0
mirror of https://github.com/netdata/netdata.git synced 2025-04-17 11:12:42 +00:00

fix rrdset name crash on rrdset obsoletion ()

fix rrdset name crash on cleanup
This commit is contained in:
Costa Tsaousis 2025-03-11 15:55:21 +00:00 committed by GitHub
parent 272ea7cb94
commit c625dc4fdf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 20 additions and 27 deletions
src

View file

@ -70,7 +70,6 @@ static void rrdset_insert_callback(const DICTIONARY_ITEM *item __maybe_unused, v
st->name = rrdset_fix_name(host, chart_full_id, ctr->type, NULL, ctr->name);
if(!st->name)
st->name = rrdset_fix_name(host, chart_full_id, ctr->type, NULL, ctr->id);
rrdset_index_add_name(host, st);
st->collection_modulo = rrdset_collection_modulo_init();
@ -291,6 +290,8 @@ static void rrdset_react_callback(const DICTIONARY_ITEM *item __maybe_unused, vo
if (ctr->react_action & RRDSET_REACT_NEW) {
if(unlikely(rrdcontext_find_chart_uuid(st, &st->chart_uuid)))
uuid_generate(st->chart_uuid);
rrdset_index_add_name(host, st);
}
rrdset_flag_set(st, RRDSET_FLAG_METADATA_UPDATE);
rrdhost_flag_set(host, RRDHOST_FLAG_METADATA_UPDATE);

View file

@ -57,25 +57,13 @@ int rrdset_reset_name(RRDSET *st, const char *name) {
rrdset_index_add_name(host, st);
rrdset_flag_clear(st, RRDSET_FLAG_EXPORTING_SEND);
rrdset_flag_clear(st, RRDSET_FLAG_EXPORTING_IGNORE);
rrdset_flag_clear(st, RRDSET_FLAG_UPSTREAM_SEND);
rrdset_flag_clear(st, RRDSET_FLAG_UPSTREAM_IGNORE);
rrdset_flag_clear(st, RRDSET_FLAG_EXPORTING_SEND|RRDSET_FLAG_EXPORTING_IGNORE|RRDSET_FLAG_UPSTREAM_SEND|RRDSET_FLAG_UPSTREAM_IGNORE);
rrdset_metadata_updated(st);
rrdcontext_updated_rrdset_name(st);
return 2;
}
static void rrdset_name_insert_callback(const DICTIONARY_ITEM *item __maybe_unused, void *rrdset, void *rrdhost __maybe_unused) {
RRDSET *st = rrdset;
rrdset_flag_set(st, RRDSET_FLAG_INDEXED_NAME);
}
static void rrdset_name_delete_callback(const DICTIONARY_ITEM *item __maybe_unused, void *rrdset, void *rrdhost __maybe_unused) {
RRDSET *st = rrdset;
rrdset_flag_clear(st, RRDSET_FLAG_INDEXED_NAME);
}
static RRDSET *rrdset_index_find_name(RRDHOST *host, const char *name) {
if (unlikely(!host->rrdset_root_index_name))
return NULL;
@ -83,28 +71,32 @@ static RRDSET *rrdset_index_find_name(RRDHOST *host, const char *name) {
}
void rrdset_index_byname_init(RRDHOST *host) {
if(!host->rrdset_root_index_name) {
host->rrdset_root_index_name = dictionary_create_advanced(
DICT_OPTION_NAME_LINK_DONT_CLONE | DICT_OPTION_VALUE_LINK_DONT_CLONE | DICT_OPTION_DONT_OVERWRITE_VALUE,
&dictionary_stats_category_rrdset, 0);
dictionary_register_insert_callback(host->rrdset_root_index_name, rrdset_name_insert_callback, host);
dictionary_register_delete_callback(host->rrdset_root_index_name, rrdset_name_delete_callback, host);
}
if(!host->rrdset_root_index_name)
host->rrdset_root_index_name = dictionary_create_view(host->rrdset_root_index);
}
void rrdset_index_add_name(RRDHOST *host, RRDSET *st) {
if(!st->name) return;
dictionary_set(host->rrdset_root_index_name, rrdset_name(st), st, sizeof(RRDSET));
const DICTIONARY_ITEM *sta = dictionary_get_and_acquire_item(host->rrdset_root_index, rrdset_id(st));
if(sta) {
const DICTIONARY_ITEM *sta2 = dictionary_view_set_and_acquire_item(host->rrdset_root_index_name, rrdset_name(st), sta);
if(sta2 && dictionary_acquired_item_value(sta2) == st)
rrdset_flag_set(st, RRDSET_FLAG_INDEXED_NAME);
}
}
void rrdset_index_del_name(RRDHOST *host, RRDSET *st) {
if(rrdset_flag_check(st, RRDSET_FLAG_INDEXED_NAME))
dictionary_del(host->rrdset_root_index_name, rrdset_name(st));
if(rrdset_flag_check(st, RRDSET_FLAG_INDEXED_NAME)) {
const DICTIONARY_ITEM *sta = dictionary_get_and_acquire_item(host->rrdset_root_index_name, rrdset_name(st));
if(sta && dictionary_acquired_item_value(sta) == st)
dictionary_del(host->rrdset_root_index_name, rrdset_name(st));
rrdset_flag_clear(st, RRDSET_FLAG_INDEXED_NAME);
}
}
RRDSET *rrdset_find_byname(RRDHOST *host, const char *name) {
netdata_log_debug(D_RRD_CALLS, "rrdset_find_byname() for chart '%s' in host '%s'", name, rrdhost_hostname(host));
RRDSET *st = rrdset_index_find_name(host, name);
return(st);
}

View file

@ -194,7 +194,7 @@ DICT_ITEM_CONST DICTIONARY_ITEM *dictionary_set_and_acquire_item_advanced(DICTIO
// set an item in a dictionary view
#define dictionary_view_set_and_acquire_item(dict, name, master_item) dictionary_view_set_and_acquire_item_advanced(dict, name, -1, master_item)
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);
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);
#define dictionary_view_set(dict, name, master_item) dictionary_view_set_advanced(dict, name, -1, master_item)
void *dictionary_view_set_advanced(DICTIONARY *dict, const char *name, ssize_t name_len, DICT_ITEM_CONST DICTIONARY_ITEM *master_item);