summaryrefslogtreecommitdiffstats
path: root/registry
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2022-06-09 04:52:47 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2022-06-09 04:52:57 +0000
commit00151562145df50cc65e9902d52d5fa77f89fe50 (patch)
tree2737716802f6725a5074d606ec8fe5422c58a83c /registry
parentReleasing debian version 1.34.1-1. (diff)
downloadnetdata-00151562145df50cc65e9902d52d5fa77f89fe50.tar.xz
netdata-00151562145df50cc65e9902d52d5fa77f89fe50.zip
Merging upstream version 1.35.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'registry')
-rw-r--r--registry/registry.c12
-rw-r--r--registry/registry_db.c22
-rw-r--r--registry/registry_init.c77
-rw-r--r--registry/registry_internals.c4
-rw-r--r--registry/registry_internals.h2
-rw-r--r--registry/registry_machine.c9
-rw-r--r--registry/registry_person.c13
-rw-r--r--registry/registry_person.h1
8 files changed, 73 insertions, 67 deletions
diff --git a/registry/registry.c b/registry/registry.c
index 64053fe25..a4f9c6de3 100644
--- a/registry/registry.c
+++ b/registry/registry.c
@@ -108,7 +108,9 @@ static int registry_json_person_url_callback(void *entry, void *data) {
}
// callback for rendering MACHINE_URLs
-static int registry_json_machine_url_callback(void *entry, void *data) {
+static int registry_json_machine_url_callback(const char *name, void *entry, void *data) {
+ (void)name;
+
REGISTRY_MACHINE_URL *mu = (REGISTRY_MACHINE_URL *)entry;
struct registry_json_walk_person_urls_callback *c = (struct registry_json_walk_person_urls_callback *)data;
struct web_client *w = c->w;
@@ -272,7 +274,7 @@ int registry_request_search_json(RRDHOST *host, struct web_client *w, char *pers
buffer_strcat(w->response.data, ",\n\t\"urls\": [");
struct registry_json_walk_person_urls_callback c = { NULL, m, w, 0 };
- dictionary_get_all(m->machine_urls, registry_json_machine_url_callback, &c);
+ dictionary_walkthrough_read(m->machine_urls, registry_json_machine_url_callback, &c);
buffer_strcat(w->response.data, "\n\t]\n");
registry_json_footer(w);
@@ -441,10 +443,10 @@ void registry_statistics(void) {
}
else rrdset_next(stm);
- rrddim_set(stm, "persons", registry.persons_memory + registry.persons_count * sizeof(NAME_VALUE) + sizeof(DICTIONARY));
- rrddim_set(stm, "machines", registry.machines_memory + registry.machines_count * sizeof(NAME_VALUE) + sizeof(DICTIONARY));
+ rrddim_set(stm, "persons", registry.persons_memory + dictionary_stats_allocated_memory(registry.persons));
+ rrddim_set(stm, "machines", registry.machines_memory + dictionary_stats_allocated_memory(registry.machines));
rrddim_set(stm, "urls", registry.urls_memory);
rrddim_set(stm, "persons_urls", registry.persons_urls_memory);
- rrddim_set(stm, "machines_urls", registry.machines_urls_memory + registry.machines_count * sizeof(DICTIONARY) + registry.machines_urls_count * sizeof(NAME_VALUE));
+ rrddim_set(stm, "machines_urls", registry.machines_urls_memory);
rrdset_done(stm);
}
diff --git a/registry/registry_db.c b/registry/registry_db.c
index c61a225cc..db53ff7e0 100644
--- a/registry/registry_db.c
+++ b/registry/registry_db.c
@@ -11,7 +11,9 @@ int registry_db_should_be_saved(void) {
// ----------------------------------------------------------------------------
// INTERNAL FUNCTIONS FOR SAVING REGISTRY OBJECTS
-static int registry_machine_save_url(void *entry, void *file) {
+static int registry_machine_save_url(const char *name, void *entry, void *file) {
+ (void)name;
+
REGISTRY_MACHINE_URL *mu = entry;
FILE *fp = file;
@@ -30,7 +32,9 @@ static int registry_machine_save_url(void *entry, void *file) {
return ret;
}
-static int registry_machine_save(void *entry, void *file) {
+static int registry_machine_save(const char *name, void *entry, void *file) {
+ (void)name;
+
REGISTRY_MACHINE *m = entry;
FILE *fp = file;
@@ -44,7 +48,7 @@ static int registry_machine_save(void *entry, void *file) {
);
if(ret >= 0) {
- int ret2 = dictionary_get_all(m->machine_urls, registry_machine_save_url, fp);
+ int ret2 = dictionary_walkthrough_read(m->machine_urls, registry_machine_save_url, fp);
if(ret2 < 0) return ret2;
ret += ret2;
}
@@ -75,7 +79,9 @@ static inline int registry_person_save_url(void *entry, void *file) {
return ret;
}
-static inline int registry_person_save(void *entry, void *file) {
+static inline int registry_person_save(const char *name, void *entry, void *file) {
+ (void)name;
+
REGISTRY_PERSON *p = entry;
FILE *fp = file;
@@ -89,7 +95,7 @@ static inline int registry_person_save(void *entry, void *file) {
);
if(ret >= 0) {
- //int ret2 = dictionary_get_all(p->person_urls, registry_person_save_url, fp);
+ //int ret2 = dictionary_walkthrough_read(p->person_urls, registry_person_save_url, fp);
int ret2 = avl_traverse(&p->person_urls, registry_person_save_url, fp);
if (ret2 < 0) return ret2;
ret += ret2;
@@ -126,10 +132,10 @@ int registry_db_save(void) {
return -1;
}
- // dictionary_get_all() has its own locking, so this is safe to do
+ // dictionary_walkthrough_read() has its own locking, so this is safe to do
debug(D_REGISTRY, "Saving all machines");
- int bytes1 = dictionary_get_all(registry.machines, registry_machine_save, fp);
+ int bytes1 = dictionary_walkthrough_read(registry.machines, registry_machine_save, fp);
if(bytes1 < 0) {
error("Registry: Cannot save registry machines - return value %d", bytes1);
fclose(fp);
@@ -139,7 +145,7 @@ int registry_db_save(void) {
debug(D_REGISTRY, "Registry: saving machines took %d bytes", bytes1);
debug(D_REGISTRY, "Saving all persons");
- int bytes2 = dictionary_get_all(registry.persons, registry_person_save, fp);
+ int bytes2 = dictionary_walkthrough_read(registry.persons, registry_person_save, fp);
if(bytes2 < 0) {
error("Registry: Cannot save registry persons - return value %d", bytes2);
fclose(fp);
diff --git a/registry/registry_init.c b/registry/registry_init.c
index d07daefa5..bae2ac5c5 100644
--- a/registry/registry_init.c
+++ b/registry/registry_init.c
@@ -18,7 +18,7 @@ int registry_init(void) {
// pathnames
snprintfz(filename, FILENAME_MAX, "%s/registry", netdata_configured_varlib_dir);
- registry.pathname = config_get(CONFIG_SECTION_REGISTRY, "registry db directory", filename);
+ registry.pathname = config_get(CONFIG_SECTION_DIRECTORIES, "registry", filename);
if(mkdir(registry.pathname, 0770) == -1 && errno != EEXIST)
fatal("Cannot create directory '%s'.", registry.pathname);
@@ -76,8 +76,8 @@ int registry_init(void) {
netdata_mutex_init(&registry.lock);
// create dictionaries
- registry.persons = dictionary_create(DICTIONARY_FLAGS);
- registry.machines = dictionary_create(DICTIONARY_FLAGS);
+ registry.persons = dictionary_create(REGISTRY_DICTIONARY_FLAGS);
+ registry.machines = dictionary_create(REGISTRY_DICTIONARY_FLAGS);
avl_init(&registry.registry_urls_root_index, registry_url_compare);
// load the registry database
@@ -93,56 +93,63 @@ int registry_init(void) {
return 0;
}
-void registry_free(void) {
- if(!registry.enabled) return;
+static int machine_urls_delete_callback(const char *name, void *entry, void *data) {
+ (void)name;
- // we need to destroy the dictionaries ourselves
- // since the dictionaries use memory we allocated
+ REGISTRY_MACHINE *m = (REGISTRY_MACHINE *)data;
+ (void)m;
- while(registry.persons->values_index.root) {
- REGISTRY_PERSON *p = ((NAME_VALUE *)registry.persons->values_index.root)->value;
- registry_person_del(p);
- }
+ REGISTRY_MACHINE_URL *mu = (REGISTRY_MACHINE_URL *)entry;
- while(registry.machines->values_index.root) {
- REGISTRY_MACHINE *m = ((NAME_VALUE *)registry.machines->values_index.root)->value;
+ debug(D_REGISTRY, "Registry: unlinking url '%s' from machine", mu->url->url);
+ registry_url_unlink(mu->url);
- // fprintf(stderr, "\nMACHINE: '%s', first: %u, last: %u, usages: %u\n", m->guid, m->first_t, m->last_t, m->usages);
+ debug(D_REGISTRY, "Registry: freeing machine url");
+ freez(mu);
- while(m->machine_urls->values_index.root) {
- REGISTRY_MACHINE_URL *mu = ((NAME_VALUE *)m->machine_urls->values_index.root)->value;
+ return 1;
+}
- // fprintf(stderr, "\tURL: '%s', first: %u, last: %u, usages: %u, flags: 0x%02x\n", mu->url->url, mu->first_t, mu->last_t, mu->usages, mu->flags);
+static int machine_delete_callback(const char *name, void *entry, void *data) {
+ (void)name;
+ (void)data;
- //debug(D_REGISTRY, "Registry: destroying persons dictionary from url '%s'", mu->url->url);
- //dictionary_destroy(mu->persons);
+ REGISTRY_MACHINE *m = (REGISTRY_MACHINE *)entry;
+ int ret = dictionary_walkthrough_read(m->machine_urls, machine_urls_delete_callback, m);
- debug(D_REGISTRY, "Registry: deleting url '%s' from person '%s'", mu->url->url, m->guid);
- dictionary_del(m->machine_urls, mu->url->url);
+ dictionary_destroy(m->machine_urls);
+ freez(m);
- debug(D_REGISTRY, "Registry: unlinking url '%s' from machine", mu->url->url);
- registry_url_unlink(mu->url);
+ return ret + 1;
+}
+static int registry_person_del_callback(const char *name, void *entry, void *d) {
+ (void)name;
+ (void)d;
- debug(D_REGISTRY, "Registry: freeing machine url");
- freez(mu);
- }
+ REGISTRY_PERSON *p = (REGISTRY_PERSON *)entry;
- debug(D_REGISTRY, "Registry: deleting machine '%s' from machines registry", m->guid);
- dictionary_del(registry.machines, m->guid);
+ debug(D_REGISTRY, "Registry: registry_person_del('%s'): deleting person", p->guid);
- debug(D_REGISTRY, "Registry: destroying URL dictionary of machine '%s'", m->guid);
- dictionary_destroy(m->machine_urls);
+ while(p->person_urls.root)
+ registry_person_unlink_from_url(p, (REGISTRY_PERSON_URL *)p->person_urls.root);
- debug(D_REGISTRY, "Registry: freeing machine '%s'", m->guid);
- freez(m);
- }
+ //debug(D_REGISTRY, "Registry: deleting person '%s' from persons registry", p->guid);
+ //dictionary_del(registry.persons, p->guid);
- // and free the memory of remaining dictionary structures
+ debug(D_REGISTRY, "Registry: freeing person '%s'", p->guid);
+ freez(p);
+
+ return 1;
+}
+
+void registry_free(void) {
+ if(!registry.enabled) return;
debug(D_REGISTRY, "Registry: destroying persons dictionary");
+ dictionary_walkthrough_read(registry.persons, registry_person_del_callback, NULL);
dictionary_destroy(registry.persons);
debug(D_REGISTRY, "Registry: destroying machines dictionary");
+ dictionary_walkthrough_read(registry.machines, machine_delete_callback, NULL);
dictionary_destroy(registry.machines);
}
-
diff --git a/registry/registry_internals.c b/registry/registry_internals.c
index cffe3f21d..fe4d2dac5 100644
--- a/registry/registry_internals.c
+++ b/registry/registry_internals.c
@@ -198,7 +198,7 @@ REGISTRY_PERSON *registry_request_delete(char *person_guid, char *machine_guid,
}
-// a structure to pass to the dictionary_get_all() callback handler
+// a structure to pass to the dictionary_walkthrough_read() callback handler
struct machine_request_callback_data {
REGISTRY_MACHINE *find_this_machine;
REGISTRY_PERSON_URL *result;
@@ -246,7 +246,7 @@ REGISTRY_MACHINE *registry_request_machine(char *person_guid, char *machine_guid
// We will walk through the PERSON_URLs to find the machine
// linking to our machine
- // a structure to pass to the dictionary_get_all() callback handler
+ // a structure to pass to the dictionary_walkthrough_read() callback handler
struct machine_request_callback_data rdata = { m, NULL };
// request a walk through on the dictionary
diff --git a/registry/registry_internals.h b/registry/registry_internals.h
index 3caf0aad8..94d028964 100644
--- a/registry/registry_internals.h
+++ b/registry/registry_internals.h
@@ -8,7 +8,7 @@
#define REGISTRY_URL_FLAGS_DEFAULT 0x00
#define REGISTRY_URL_FLAGS_EXPIRED 0x01
-#define DICTIONARY_FLAGS (DICTIONARY_FLAG_VALUE_LINK_DONT_CLONE | DICTIONARY_FLAG_NAME_LINK_DONT_CLONE | DICTIONARY_FLAG_SINGLE_THREADED)
+#define REGISTRY_DICTIONARY_FLAGS (DICTIONARY_FLAG_VALUE_LINK_DONT_CLONE | DICTIONARY_FLAG_NAME_LINK_DONT_CLONE | DICTIONARY_FLAG_SINGLE_THREADED | DICTIONARY_FLAG_WITH_STATISTICS)
// ----------------------------------------------------------------------------
// COMMON structures
diff --git a/registry/registry_machine.c b/registry/registry_machine.c
index bd1d243a0..fb345aea2 100644
--- a/registry/registry_machine.c
+++ b/registry/registry_machine.c
@@ -24,7 +24,10 @@ REGISTRY_MACHINE_URL *registry_machine_url_allocate(REGISTRY_MACHINE *m, REGISTR
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_allocated_memory(m->machine_urls);
dictionary_set(m->machine_urls, u->url, mu, sizeof(REGISTRY_MACHINE_URL));
+ registry.machines_urls_memory += dictionary_stats_allocated_memory(m->machine_urls);
registry_url_link(u);
@@ -39,15 +42,17 @@ REGISTRY_MACHINE *registry_machine_allocate(const char *machine_guid, time_t whe
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(DICTIONARY_FLAGS);
+ m->machine_urls = dictionary_create(REGISTRY_DICTIONARY_FLAGS);
m->first_t = m->last_t = (uint32_t)when;
m->usages = 0;
registry.machines_memory += sizeof(REGISTRY_MACHINE);
-
registry.machines_count++;
+
+ registry.machines_urls_memory -= dictionary_stats_allocated_memory(m->machine_urls);
dictionary_set(registry.machines, m->guid, m, sizeof(REGISTRY_MACHINE));
+ registry.machines_urls_memory += dictionary_stats_allocated_memory(m->machine_urls);
return m;
}
diff --git a/registry/registry_person.c b/registry/registry_person.c
index acf9d4da2..2f55e99d3 100644
--- a/registry/registry_person.c
+++ b/registry/registry_person.c
@@ -199,19 +199,6 @@ REGISTRY_PERSON *registry_person_get(const char *person_guid, time_t when) {
return p;
}
-void registry_person_del(REGISTRY_PERSON *p) {
- debug(D_REGISTRY, "Registry: registry_person_del('%s'): creating dictionary of urls", p->guid);
-
- while(p->person_urls.root)
- registry_person_unlink_from_url(p, (REGISTRY_PERSON_URL *)p->person_urls.root);
-
- debug(D_REGISTRY, "Registry: deleting person '%s' from persons registry", p->guid);
- dictionary_del(registry.persons, p->guid);
-
- debug(D_REGISTRY, "Registry: freeing person '%s'", p->guid);
- freez(p);
-}
-
// ----------------------------------------------------------------------------
// LINKING OF OBJECTS
diff --git a/registry/registry_person.h b/registry/registry_person.h
index 42419bfe9..556c426f7 100644
--- a/registry/registry_person.h
+++ b/registry/registry_person.h
@@ -53,7 +53,6 @@ extern REGISTRY_PERSON_URL *registry_person_url_reallocate(REGISTRY_PERSON *p, R
extern REGISTRY_PERSON *registry_person_find(const char *person_guid);
extern REGISTRY_PERSON *registry_person_allocate(const char *person_guid, time_t when);
extern REGISTRY_PERSON *registry_person_get(const char *person_guid, time_t when);
-extern void registry_person_del(REGISTRY_PERSON *p);
// LINKING PERSON -> PERSON_URL
extern REGISTRY_PERSON_URL *registry_person_link_to_url(REGISTRY_PERSON *p, REGISTRY_MACHINE *m, REGISTRY_URL *u, char *name, size_t namelen, time_t when);