From ab1bb5b7f1c3c3a7b240ab7fc8661459ecd7decb Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Thu, 20 Jul 2023 06:49:55 +0200 Subject: Adding upstream version 1.41.0. Signed-off-by: Daniel Baumann --- registry/registry_machine.c | 65 +++++++++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 29 deletions(-) (limited to 'registry/registry_machine.c') diff --git a/registry/registry_machine.c b/registry/registry_machine.c index 414cd16d9..a94fb8ea4 100644 --- a/registry/registry_machine.c +++ b/registry/registry_machine.c @@ -7,52 +7,59 @@ // MACHINE REGISTRY_MACHINE *registry_machine_find(const char *machine_guid) { - debug(D_REGISTRY, "Registry: registry_machine_find('%s')", machine_guid); + netdata_log_debug(D_REGISTRY, "REGISTRY: registry_machine_find('%s')", machine_guid); return dictionary_get(registry.machines, machine_guid); } -REGISTRY_MACHINE_URL *registry_machine_url_allocate(REGISTRY_MACHINE *m, REGISTRY_URL *u, time_t when) { - debug(D_REGISTRY, "registry_machine_url_allocate('%s', '%s'): allocating %zu bytes", m->guid, u->url, sizeof(REGISTRY_MACHINE_URL)); +REGISTRY_MACHINE_URL *registry_machine_url_find(REGISTRY_MACHINE *m, STRING *url) { + REGISTRY_MACHINE_URL *mu; - REGISTRY_MACHINE_URL *mu = mallocz(sizeof(REGISTRY_MACHINE_URL)); + for(mu = m->machine_urls; mu ;mu = mu->next) + if(mu->url == url) + break; + + return mu; +} + +void registry_machine_url_unlink_from_machine_and_free(REGISTRY_MACHINE *m, REGISTRY_MACHINE_URL *mu) { + DOUBLE_LINKED_LIST_REMOVE_ITEM_UNSAFE(m->machine_urls, mu, prev, next); + string_freez(mu->url); + aral_freez(registry.machine_urls_aral, mu); +} + +REGISTRY_MACHINE_URL *registry_machine_url_allocate(REGISTRY_MACHINE *m, STRING *u, time_t when) { + netdata_log_debug(D_REGISTRY, "REGISTRY: registry_machine_url_allocate('%s', '%s'): allocating %zu bytes", m->guid, string2str(u), sizeof(REGISTRY_MACHINE_URL)); + + REGISTRY_MACHINE_URL *mu = aral_mallocz(registry.machine_urls_aral); mu->first_t = mu->last_t = (uint32_t)when; mu->usages = 1; - mu->url = u; + mu->url = string_dup(u); mu->flags = REGISTRY_URL_FLAGS_DEFAULT; - registry.machines_urls_memory += sizeof(REGISTRY_MACHINE_URL); - - debug(D_REGISTRY, "registry_machine_url_allocate('%s', '%s'): indexing URL in machine", m->guid, u->url); - - registry.machines_urls_memory -= dictionary_stats_for_registry(m->machine_urls); - dictionary_set(m->machine_urls, u->url, mu, sizeof(REGISTRY_MACHINE_URL)); - registry.machines_urls_memory += dictionary_stats_for_registry(m->machine_urls); + netdata_log_debug(D_REGISTRY, "REGISTRY: registry_machine_url_allocate('%s', '%s'): indexing URL in machine", m->guid, string2str(u)); - registry_url_link(u); + DOUBLE_LINKED_LIST_PREPEND_ITEM_UNSAFE(m->machine_urls, mu, prev, next); return mu; } REGISTRY_MACHINE *registry_machine_allocate(const char *machine_guid, time_t when) { - debug(D_REGISTRY, "Registry: registry_machine_allocate('%s'): creating new machine, sizeof(MACHINE)=%zu", machine_guid, sizeof(REGISTRY_MACHINE)); + netdata_log_debug(D_REGISTRY, "REGISTRY: registry_machine_allocate('%s'): creating new machine, sizeof(MACHINE)=%zu", machine_guid, sizeof(REGISTRY_MACHINE)); - REGISTRY_MACHINE *m = mallocz(sizeof(REGISTRY_MACHINE)); + REGISTRY_MACHINE *m = aral_mallocz(registry.machines_aral); strncpyz(m->guid, machine_guid, GUID_LEN); - debug(D_REGISTRY, "Registry: registry_machine_allocate('%s'): creating dictionary of urls", machine_guid); - m->machine_urls = dictionary_create(REGISTRY_DICTIONARY_OPTIONS); + m->machine_urls = NULL; m->first_t = m->last_t = (uint32_t)when; m->usages = 0; + m->links = 0; - registry.machines_memory += sizeof(REGISTRY_MACHINE); registry.machines_count++; - registry.machines_urls_memory -= dictionary_stats_for_registry(m->machine_urls); dictionary_set(registry.machines, m->guid, m, sizeof(REGISTRY_MACHINE)); - registry.machines_urls_memory += dictionary_stats_for_registry(m->machine_urls); return m; } @@ -60,14 +67,14 @@ REGISTRY_MACHINE *registry_machine_allocate(const char *machine_guid, time_t whe // 1. validate machine GUID // 2. if it is valid, find it or create it and return it // 3. if it is not valid, return NULL -REGISTRY_MACHINE *registry_machine_get(const char *machine_guid, time_t when) { +REGISTRY_MACHINE *registry_machine_find_or_create(const char *machine_guid, time_t when, bool is_dummy __maybe_unused) { REGISTRY_MACHINE *m = NULL; if(likely(machine_guid && *machine_guid)) { // validate it is a GUID char buf[GUID_LEN + 1]; if(unlikely(regenerate_guid(machine_guid, buf) == -1)) - info("Registry: machine guid '%s' is not a valid guid. Ignoring it.", machine_guid); + netdata_log_info("REGISTRY: machine guid '%s' is not a valid guid. Ignoring it.", machine_guid); else { machine_guid = buf; m = registry_machine_find(machine_guid); @@ -82,17 +89,17 @@ REGISTRY_MACHINE *registry_machine_get(const char *machine_guid, time_t when) { // ---------------------------------------------------------------------------- // LINKING OF OBJECTS -REGISTRY_MACHINE_URL *registry_machine_link_to_url(REGISTRY_MACHINE *m, REGISTRY_URL *u, time_t when) { - debug(D_REGISTRY, "registry_machine_link_to_url('%s', '%s'): searching for URL in machine", m->guid, u->url); +REGISTRY_MACHINE_URL *registry_machine_link_to_url(REGISTRY_MACHINE *m, STRING *url, time_t when) { + netdata_log_debug(D_REGISTRY, "REGISTRY: registry_machine_link_to_url('%s', '%s'): searching for URL in machine", m->guid, string2str(url)); - REGISTRY_MACHINE_URL *mu = dictionary_get(m->machine_urls, u->url); + REGISTRY_MACHINE_URL *mu = registry_machine_url_find(m, url); if(!mu) { - debug(D_REGISTRY, "registry_machine_link_to_url('%s', '%s'): not found", m->guid, u->url); - mu = registry_machine_url_allocate(m, u, when); + netdata_log_debug(D_REGISTRY, "REGISTRY: registry_machine_link_to_url('%s', '%s'): not found", m->guid, string2str(url)); + mu = registry_machine_url_allocate(m, url, when); registry.machines_urls_count++; } else { - debug(D_REGISTRY, "registry_machine_link_to_url('%s', '%s'): found", m->guid, u->url); + netdata_log_debug(D_REGISTRY, "REGISTRY: registry_machine_link_to_url('%s', '%s'): found", m->guid, string2str(url)); mu->usages++; if(likely(mu->last_t < (uint32_t)when)) mu->last_t = (uint32_t)when; } @@ -101,7 +108,7 @@ REGISTRY_MACHINE_URL *registry_machine_link_to_url(REGISTRY_MACHINE *m, REGISTRY if(likely(m->last_t < (uint32_t)when)) m->last_t = (uint32_t)when; if(mu->flags & REGISTRY_URL_FLAGS_EXPIRED) { - debug(D_REGISTRY, "registry_machine_link_to_url('%s', '%s'): accessing an expired URL.", m->guid, u->url); + netdata_log_debug(D_REGISTRY, "REGISTRY: registry_machine_link_to_url('%s', '%s'): accessing an expired URL.", m->guid, string2str(url)); mu->flags &= ~REGISTRY_URL_FLAGS_EXPIRED; } -- cgit v1.2.3