diff options
author | Stelios Fragkakis <52996999+stelfrag@users.noreply.github.com> | 2022-10-26 12:19:57 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-26 12:19:57 +0300 |
commit | 9e89ac73077e269df5662b2b56cb39843a03d4fa (patch) | |
tree | 09649b7d62cb9515ee666850e44cf6123464c029 /database/rrdcontext.c | |
parent | b1bc23db0d2f0a2402dcb57aaedebfdc768223a5 (diff) |
Find the chart and dimension UUID from the context (#13868)
* Add functions to find chart uuid and dimension UUIDs from context
* Remove old functions that access the sqlite database directly
* Use new functions to fetch the UUIDs for chart and dimensions
* Remove unused function
Diffstat (limited to 'database/rrdcontext.c')
-rw-r--r-- | database/rrdcontext.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/database/rrdcontext.c b/database/rrdcontext.c index b003efd7d1..b71a7a387d 100644 --- a/database/rrdcontext.c +++ b/database/rrdcontext.c @@ -1486,6 +1486,63 @@ void rrdcontext_host_child_connected(RRDHOST *host) { ; } +int rrdcontext_find_dimension_uuid(RRDSET *st, const char *id, uuid_t *store_uuid) { + if(!st->rrdhost) return 1; + if(!st->context) return 2; + + RRDCONTEXT_ACQUIRED *rca = (RRDCONTEXT_ACQUIRED *)dictionary_get_and_acquire_item((DICTIONARY *)st->rrdhost->rrdctx, string2str(st->context)); + if(!rca) return 3; + + RRDCONTEXT *rc = rrdcontext_acquired_value(rca); + + RRDINSTANCE_ACQUIRED *ria = (RRDINSTANCE_ACQUIRED *)dictionary_get_and_acquire_item(rc->rrdinstances, string2str(st->id)); + if(!ria) { + rrdcontext_release(rca); + return 4; + } + + RRDINSTANCE *ri = rrdinstance_acquired_value(ria); + + RRDMETRIC_ACQUIRED *rma = (RRDMETRIC_ACQUIRED *)dictionary_get_and_acquire_item(ri->rrdmetrics, id); + if(!rma) { + rrdinstance_release(ria); + rrdcontext_release(rca); + return 5; + } + + RRDMETRIC *rm = rrdmetric_acquired_value(rma); + + uuid_copy(*store_uuid, rm->uuid); + + rrdmetric_release(rma); + rrdinstance_release(ria); + rrdcontext_release(rca); + return 0; +} + +int rrdcontext_find_chart_uuid(RRDSET *st, uuid_t *store_uuid) { + if(!st->rrdhost) return 1; + if(!st->context) return 2; + + RRDCONTEXT_ACQUIRED *rca = (RRDCONTEXT_ACQUIRED *)dictionary_get_and_acquire_item((DICTIONARY *)st->rrdhost->rrdctx, string2str(st->context)); + if(!rca) return 3; + + RRDCONTEXT *rc = rrdcontext_acquired_value(rca); + + RRDINSTANCE_ACQUIRED *ria = (RRDINSTANCE_ACQUIRED *)dictionary_get_and_acquire_item(rc->rrdinstances, string2str(st->id)); + if(!ria) { + rrdcontext_release(rca); + return 4; + } + + RRDINSTANCE *ri = rrdinstance_acquired_value(ria); + uuid_copy(*store_uuid, ri->uuid); + + rrdinstance_release(ria); + rrdcontext_release(rca); + return 0; +} + void rrdcontext_host_child_disconnected(RRDHOST *host) { rrdcontext_recalculate_host_retention(host, RRD_FLAG_UPDATE_REASON_DISCONNECTED_CHILD, false); } |