diff options
author | Costa Tsaousis <costa@netdata.cloud> | 2022-06-28 17:48:11 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-28 17:48:11 +0300 |
commit | aa3be2f0647ace385e5ffb475a3e145f38458e6e (patch) | |
tree | 23ad01136e8ccf855483a91c4881dd0ca5a85830 /database/rrdlabels.c | |
parent | c3dfbe52a61dd0d1995bc420b0e0576cf058fd74 (diff) |
Dictionaries with reference counters and full deletion support during traversal (#13195)
* dont use atomic operations when not needed; detect misuse of the the unsafe functions
* use relaxed atomic operations for statistics
* use relaxed atomic operations for statistics
* dictionaries now use reference counters, allowing deletetions of any item while traversing it
* added acquire/release interface to dictionaries
* added unittest for reference counters
* added NETDATA_INTERNAL_CHECKS logs to detect non-exclusive access to crusial parts of the dictionaries
* dictionaries cannot be deleted while there are referenced items in them - they will be deleted once the last item gets unreferenced
* cleanup
* properly cleanup released items
* maintain counters for readers and writers; defer all deletes on sorted walkthrough; cleaner internal_error();
* somewhat faster reference counters on single threaded dictionaries
* minor optimizations; allow compiling without internal checks
Diffstat (limited to 'database/rrdlabels.c')
-rw-r--r-- | database/rrdlabels.c | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/database/rrdlabels.c b/database/rrdlabels.c index 7032df70d4..4a610b1587 100644 --- a/database/rrdlabels.c +++ b/database/rrdlabels.c @@ -611,20 +611,15 @@ void rrdlabels_add_pair(DICTIONARY *dict, const char *string, RRDLABEL_SRC ls) { // rrdlabels_get_to_buffer_or_null() void rrdlabels_get_value_to_buffer_or_null(DICTIONARY *labels, BUFFER *wb, const char *key, const char *quote, const char *null) { - // Get a read lock on the dictionary - // to copy the value into the buffer - void *v; - dfe_start_read(labels, v) { - RRDLABEL *lb = dictionary_get_having_read_lock(labels, key); - - if(lb && lb->value) - buffer_sprintf(wb, "%s%s%s", quote, lb->value, quote); - else - buffer_strcat(wb, null); - - break; - } - dfe_done(v); + void *acquired_item = dictionary_acquire_item(labels, key); + RRDLABEL *lb = dictionary_acquired_item_value(labels, acquired_item); + + if(lb && lb->value) + buffer_sprintf(wb, "%s%s%s", quote, lb->value, quote); + else + buffer_strcat(wb, null); + + dictionary_acquired_item_release(labels, acquired_item); } |