@cryptotaxi247 / netdata-1 / commits / 766e65288

make sure alerts are concurrently altered by dyncfg (#19854)

Costa Tsaousis committed Mar 13, 2025 at 17:16 UTC 766e65288c2ea25e684156fac4d524fdf3e345c6
1 file changed +8 -17
src/health/rrdcalc.c
+8 -17
@@ -250,13 +250,6 @@ static void rrdcalc_link_to_rrdset(RRDCALC *rc) {
250 static void rrdcalc_unlink_from_rrdset(RRDCALC *rc, bool having_ll_wrlock) {
251 RRDSET *st = rc->rrdset;
252
253 - if(!st) {
254 - netdata_log_error(
255 - "Requested to unlink RRDCALC '%s.%s' which is not linked to any RRDSET",
256 - rrdcalc_chart_name(rc), rrdcalc_name(rc));
257 - return;
258 - }
259 -
253 if (!exit_initiated) {
254 RRDHOST *host = st->rrdhost;
255
@@ -280,17 +273,14 @@ static void rrdcalc_unlink_from_rrdset(RRDCALC *rc, bool having_ll_wrlock) {
273 }
274 }
275
283 - // unlink it
284 -
276 if(!having_ll_wrlock)
277 rw_spinlock_write_lock(&st->alerts.spinlock);
278
288 - DOUBLE_LINKED_LIST_REMOVE_ITEM_UNSAFE(st->alerts.base, rc, prev, next);
279 + if(rc->prev)
280 + DOUBLE_LINKED_LIST_REMOVE_ITEM_UNSAFE(st->alerts.base, rc, prev, next);
281
282 if(!having_ll_wrlock)
283 rw_spinlock_write_unlock(&st->alerts.spinlock);
292 -
293 - rc->rrdset = NULL;
284 }
285
286 // ----------------------------------------------------------------------------
@@ -385,12 +375,13 @@ static void rrdcalc_free_internals(RRDCALC *rc) {
375 string_freez(rc->summary);
376 }
377
378 +static __thread bool thread_having_ll_wrlock = false;
379 +
380 static void rrdcalc_rrdhost_delete_callback(const DICTIONARY_ITEM *item __maybe_unused, void *rrdcalc, void *rrdhost __maybe_unused) {
381 RRDCALC *rc = rrdcalc;
382 //RRDHOST *host = rrdhost;
383
392 - if(unlikely(rc->rrdset))
393 - rrdcalc_unlink_from_rrdset(rc, false);
384 + rrdcalc_unlink_from_rrdset(rc, thread_having_ll_wrlock);
385
386 // any destruction actions that require other locks
387 // have to be placed in rrdcalc_del(), because the object is actually locked for deletion
@@ -441,13 +432,13 @@ bool rrdcalc_add_from_prototype(RRDHOST *host, RRDSET *st, RRD_ALERT_PROTOTYPE *
432 }
433
434 void rrdcalc_unlink_and_delete(RRDHOST *host, RRDCALC *rc, bool having_ll_wrlock) {
444 - if(rc->rrdset)
445 - rrdcalc_unlink_from_rrdset(rc, having_ll_wrlock);
435 + rrdcalc_unlink_from_rrdset(rc, having_ll_wrlock);
436
437 + thread_having_ll_wrlock = having_ll_wrlock;
438 dictionary_del_advanced(host->rrdcalc_root_index, string2str(rc->key), (ssize_t)string_strlen(rc->key));
439 + thread_having_ll_wrlock = false;
440 }
441
450 -
442 // ----------------------------------------------------------------------------
443 // RRDCALC cleanup API functions
444