summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCosta Tsaousis <costa@netdata.cloud>2023-07-09 05:06:56 +0300
committerCosta Tsaousis <costa@netdata.cloud>2023-07-09 05:06:56 +0300
commit79eff56f77d12a9f840f1b30040e4123e3d9a7a2 (patch)
treee3dcc3e77d7cfd99e5c031f1e81a77a8832cbec1
parent762b3212464a2407da37a12f03a6d50442c2877c (diff)
eliminate url pointer from registry_machine_url
-rw-r--r--registry/registry.c10
-rw-r--r--registry/registry_db.c5
-rw-r--r--registry/registry_init.c3
-rw-r--r--registry/registry_machine.c23
-rw-r--r--registry/registry_machine.h6
5 files changed, 21 insertions, 26 deletions
diff --git a/registry/registry.c b/registry/registry.c
index a175c0d301..e9ff4c12b0 100644
--- a/registry/registry.c
+++ b/registry/registry.c
@@ -84,6 +84,7 @@ struct registry_json_walk_person_urls_callback {
int count;
};
+#define ASTERISKS_STR "***"
static STRING *asterisks = NULL;
// callback for rendering PERSON_URLs
@@ -110,19 +111,18 @@ static int registry_json_person_url_callback(void *entry, void *data) {
// callback for rendering MACHINE_URLs
static int registry_json_machine_url_callback(const DICTIONARY_ITEM *item __maybe_unused, void *entry, void *data) {
- if(unlikely(!asterisks))
- asterisks = string_strdupz("***");
-
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;
REGISTRY_MACHINE *m = c->m;
- if (mu->url == asterisks) return 0;
+ const char *url = dictionary_acquired_item_name(item);
+ if (!strcmp(url, ASTERISKS_STR)) return 0;
buffer_json_add_array_item_array(w->response.data);
buffer_json_add_array_item_string(w->response.data, m->guid);
- buffer_json_add_array_item_string(w->response.data, string2str(mu->url));
+ buffer_json_add_array_item_string(w->response.data, url);
buffer_json_add_array_item_uint64(w->response.data, mu->last_t * (uint64_t) 1000);
buffer_json_add_array_item_uint64(w->response.data, mu->usages);
buffer_json_array_close(w->response.data);
diff --git a/registry/registry_db.c b/registry/registry_db.c
index 53ee2404b8..3a56092d93 100644
--- a/registry/registry_db.c
+++ b/registry/registry_db.c
@@ -12,17 +12,18 @@ int registry_db_should_be_saved(void) {
// INTERNAL FUNCTIONS FOR SAVING REGISTRY OBJECTS
static int registry_machine_save_url(const DICTIONARY_ITEM *item __maybe_unused, void *entry, void *file) {
+ const char *url = dictionary_acquired_item_name(item);
REGISTRY_MACHINE_URL *mu = entry;
FILE *fp = file;
- debug(D_REGISTRY, "Registry: registry_machine_save_url('%s')", string2str(mu->url));
+ debug(D_REGISTRY, "Registry: registry_machine_save_url('%s')", url);
int ret = fprintf(fp, "V\t%08x\t%08x\t%08x\t%02x\t%s\n",
mu->first_t,
mu->last_t,
mu->usages,
mu->flags,
- string2str(mu->url)
+ url
);
// error handling is done at registry_db_save()
diff --git a/registry/registry_init.c b/registry/registry_init.c
index 4775d663f1..01a2aa26a4 100644
--- a/registry/registry_init.c
+++ b/registry/registry_init.c
@@ -98,9 +98,6 @@ static int machine_urls_delete_callback(const DICTIONARY_ITEM *item __maybe_unus
REGISTRY_MACHINE_URL *mu = (REGISTRY_MACHINE_URL *)entry;
- debug(D_REGISTRY, "Registry: unlinking url '%s' from machine", string2str(mu->url));
- string_freez(mu->url);
-
debug(D_REGISTRY, "Registry: freeing machine url");
freez(mu);
diff --git a/registry/registry_machine.c b/registry/registry_machine.c
index a11e640924..4c3b28d440 100644
--- a/registry/registry_machine.c
+++ b/registry/registry_machine.c
@@ -11,22 +11,21 @@ REGISTRY_MACHINE *registry_machine_find(const char *machine_guid) {
return dictionary_get(registry.machines, machine_guid);
}
-REGISTRY_MACHINE_URL *registry_machine_url_allocate(REGISTRY_MACHINE *m, STRING *u, time_t when) {
- debug(D_REGISTRY, "registry_machine_url_allocate('%s', '%s'): allocating %zu bytes", m->guid, string2str(u), sizeof(REGISTRY_MACHINE_URL));
+REGISTRY_MACHINE_URL *registry_machine_url_allocate(REGISTRY_MACHINE *m, STRING *url, time_t when) {
+ debug(D_REGISTRY, "registry_machine_url_allocate('%s', '%s'): allocating %zu bytes", m->guid, string2str(url), sizeof(REGISTRY_MACHINE_URL));
REGISTRY_MACHINE_URL *mu = mallocz(sizeof(REGISTRY_MACHINE_URL));
mu->first_t = mu->last_t = (uint32_t)when;
mu->usages = 1;
- 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, string2str(u));
+ debug(D_REGISTRY, "registry_machine_url_allocate('%s', '%s'): indexing URL in machine", m->guid, string2str(url));
registry.machines_urls_memory -= dictionary_stats_for_registry(m->machine_urls);
- dictionary_set(m->machine_urls, string2str(u), mu, sizeof(REGISTRY_MACHINE_URL));
+ dictionary_set(m->machine_urls, string2str(url), mu, sizeof(REGISTRY_MACHINE_URL));
registry.machines_urls_memory += dictionary_stats_for_registry(m->machine_urls);
return mu;
@@ -80,17 +79,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, STRING *u, time_t when) {
- debug(D_REGISTRY, "registry_machine_link_to_url('%s', '%s'): searching for URL in machine", m->guid, string2str(u));
+REGISTRY_MACHINE_URL *registry_machine_link_to_url(REGISTRY_MACHINE *m, STRING *url, time_t when) {
+ debug(D_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, string2str(u));
+ REGISTRY_MACHINE_URL *mu = dictionary_get(m->machine_urls, string2str(url));
if(!mu) {
- debug(D_REGISTRY, "registry_machine_link_to_url('%s', '%s'): not found", m->guid, string2str(u));
- mu = registry_machine_url_allocate(m, u, when);
+ debug(D_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, string2str(u));
+ debug(D_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;
}
@@ -99,7 +98,7 @@ REGISTRY_MACHINE_URL *registry_machine_link_to_url(REGISTRY_MACHINE *m, STRING *
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, string2str(u));
+ debug(D_REGISTRY, "registry_machine_link_to_url('%s', '%s'): accessing an expired URL.", m->guid, string2str(url));
mu->flags &= ~REGISTRY_URL_FLAGS_EXPIRED;
}
diff --git a/registry/registry_machine.h b/registry/registry_machine.h
index 9e9b31ca97..ed2e18a2be 100644
--- a/registry/registry_machine.h
+++ b/registry/registry_machine.h
@@ -10,8 +10,6 @@
// For each MACHINE-URL pair we keep this
struct registry_machine_url {
- STRING *url; // de-duplicated URL
-
uint8_t flags;
uint32_t first_t; // the first time we saw this
@@ -35,9 +33,9 @@ struct registry_machine {
typedef struct registry_machine REGISTRY_MACHINE;
REGISTRY_MACHINE *registry_machine_find(const char *machine_guid);
-REGISTRY_MACHINE_URL *registry_machine_url_allocate(REGISTRY_MACHINE *m, STRING *u, time_t when);
+REGISTRY_MACHINE_URL *registry_machine_url_allocate(REGISTRY_MACHINE *m, STRING *url, time_t when);
REGISTRY_MACHINE *registry_machine_allocate(const char *machine_guid, time_t when);
REGISTRY_MACHINE *registry_machine_get(const char *machine_guid, time_t when);
-REGISTRY_MACHINE_URL *registry_machine_link_to_url(REGISTRY_MACHINE *m, STRING *u, time_t when);
+REGISTRY_MACHINE_URL *registry_machine_link_to_url(REGISTRY_MACHINE *m, STRING *url, time_t when);
#endif //NETDATA_REGISTRY_MACHINE_H