diff options
author | Stelios Fragkakis <52996999+stelfrag@users.noreply.github.com> | 2021-11-17 11:19:07 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-17 11:19:07 +0200 |
commit | 577f8c0e43d15238f9cdecf036fa889605136d66 (patch) | |
tree | 01832805ff79f4f1d6e80ec1445bbae0d04ff57b /database | |
parent | 5471894ac2a4732748ca3133e4d0b3bf3b4fe50e (diff) |
Use correct hop count if host is already in memory (#11785)
* Use correct hop count if host in memory
* Add locking to be safe when using host lookup
* Update the live state correctly
Diffstat (limited to 'database')
-rw-r--r-- | database/sqlite/sqlite_functions.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/database/sqlite/sqlite_functions.c b/database/sqlite/sqlite_functions.c index 0cb69aceee..4bee8d382e 100644 --- a/database/sqlite/sqlite_functions.c +++ b/database/sqlite/sqlite_functions.c @@ -1791,6 +1791,7 @@ struct node_instance_list *get_node_list(void) node_list = callocz(row + 1, sizeof(*node_list)); int max_rows = row; row = 0; + rrd_wrlock(); while (sqlite3_step(res) == SQLITE_ROW) { if (sqlite3_column_bytes(res, 0) == sizeof(uuid_t)) uuid_copy(node_list[row].node_id, *((uuid_t *)sqlite3_column_blob(res, 0))); @@ -1799,8 +1800,10 @@ struct node_instance_list *get_node_list(void) uuid_copy(node_list[row].host_id, *host_id); node_list[row].queryable = 1; uuid_unparse_lower(*host_id, host_guid); - node_list[row].live = rrdhost_find_by_guid(host_guid, 0) ? 1 : 0; - node_list[row].hops = uuid_compare(*host_id, localhost->host_uuid) ? 1 : 0; + RRDHOST *host = rrdhost_find_by_guid(host_guid, 0); + node_list[row].live = host && (host == localhost || host->receiver) ? 1 : 0; + node_list[row].hops = (host && host->system_info) ? host->system_info->hops : + uuid_compare(*host_id, localhost->host_uuid) ? 1 : 0; node_list[row].hostname = sqlite3_column_bytes(res, 2) ? strdupz((char *)sqlite3_column_text(res, 2)) : NULL; } @@ -1808,6 +1811,7 @@ struct node_instance_list *get_node_list(void) if (row == max_rows) break; } + rrd_unlock(); failed: if (unlikely(sqlite3_finalize(res) != SQLITE_OK)) |