mirror of
https://github.com/netdata/netdata.git
synced 2025-04-30 07:30:04 +00:00
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
This commit is contained in:
parent
5471894ac2
commit
577f8c0e43
1 changed files with 6 additions and 2 deletions
|
@ -1791,6 +1791,7 @@ struct node_instance_list *get_node_list(void)
|
||||||
node_list = callocz(row + 1, sizeof(*node_list));
|
node_list = callocz(row + 1, sizeof(*node_list));
|
||||||
int max_rows = row;
|
int max_rows = row;
|
||||||
row = 0;
|
row = 0;
|
||||||
|
rrd_wrlock();
|
||||||
while (sqlite3_step(res) == SQLITE_ROW) {
|
while (sqlite3_step(res) == SQLITE_ROW) {
|
||||||
if (sqlite3_column_bytes(res, 0) == sizeof(uuid_t))
|
if (sqlite3_column_bytes(res, 0) == sizeof(uuid_t))
|
||||||
uuid_copy(node_list[row].node_id, *((uuid_t *)sqlite3_column_blob(res, 0)));
|
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);
|
uuid_copy(node_list[row].host_id, *host_id);
|
||||||
node_list[row].queryable = 1;
|
node_list[row].queryable = 1;
|
||||||
uuid_unparse_lower(*host_id, host_guid);
|
uuid_unparse_lower(*host_id, host_guid);
|
||||||
node_list[row].live = rrdhost_find_by_guid(host_guid, 0) ? 1 : 0;
|
RRDHOST *host = rrdhost_find_by_guid(host_guid, 0);
|
||||||
node_list[row].hops = uuid_compare(*host_id, localhost->host_uuid) ? 1 : 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 =
|
node_list[row].hostname =
|
||||||
sqlite3_column_bytes(res, 2) ? strdupz((char *)sqlite3_column_text(res, 2)) : NULL;
|
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)
|
if (row == max_rows)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
rrd_unlock();
|
||||||
|
|
||||||
failed:
|
failed:
|
||||||
if (unlikely(sqlite3_finalize(res) != SQLITE_OK))
|
if (unlikely(sqlite3_finalize(res) != SQLITE_OK))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue