From 128ba9501d5ef3664a4b93930c315792472bdd73 Mon Sep 17 00:00:00 2001 From: Stelios Fragkakis <52996999+stelfrag@users.noreply.github.com> Date: Sun, 11 Feb 2024 21:30:35 +0200 Subject: [PATCH 1/2] Detect machine GUID change (#16979) Detect machine guid change --- src/database/rrdhost.c | 2 +- src/database/sqlite/sqlite_metadata.c | 12 ++++-------- src/database/sqlite/sqlite_metadata.h | 2 +- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/database/rrdhost.c b/src/database/rrdhost.c index 7a5558e360bf7d..2699ca8f34dd61 100644 --- a/src/database/rrdhost.c +++ b/src/database/rrdhost.c @@ -1107,7 +1107,7 @@ int rrd_init(char *hostname, struct rrdhost_system_info *system_info, bool unitt rrdhost_function_progress); if (likely(system_info)) { - migrate_localhost(&localhost->host_uuid); + detect_machine_guid_change(&localhost->host_uuid); sql_aclk_sync_init(); web_client_api_v1_management_init(); } diff --git a/src/database/sqlite/sqlite_metadata.c b/src/database/sqlite/sqlite_metadata.c index 82fd2b22b43ce5..d074e06d79d4ef 100644 --- a/src/database/sqlite/sqlite_metadata.c +++ b/src/database/sqlite/sqlite_metadata.c @@ -51,9 +51,7 @@ "INSERT OR REPLACE INTO host_info (host_id, system_key, system_value, date_created) VALUES " \ "(@uuid, @name, @value, UNIXEPOCH())" -#define MIGRATE_LOCALHOST_TO_NEW_MACHINE_GUID \ - "UPDATE chart SET host_id = @host_id WHERE host_id in (SELECT host_id FROM host where host_id <> @host_id and hops = 0)" -#define DELETE_NON_EXISTING_LOCALHOST "DELETE FROM host WHERE hops = 0 AND host_id <> @host_id" +#define CONVERT_EXISTING_LOCALHOST "UPDATE host SET hops = 1 WHERE hops = 0 AND host_id <> @host_id" #define DELETE_MISSING_NODE_INSTANCES "DELETE FROM node_instance WHERE host_id NOT IN (SELECT host_id FROM host)" #define METADATA_MAINTENANCE_FIRST_CHECK (1800) // Maintenance first run after agent startup in seconds @@ -231,14 +229,12 @@ static int check_and_update_chart_labels(RRDSET *st, BUFFER *work_buffer, size_t return rc; } -// Migrate all hosts with hops zero to this host_uuid -void migrate_localhost(uuid_t *host_uuid) +// If the machine guid has changed, then existing one with hops 0 will be marked as hops 1 (child) +void detect_machine_guid_change(uuid_t *host_uuid) { int rc; - rc = exec_statement_with_uuid(MIGRATE_LOCALHOST_TO_NEW_MACHINE_GUID, host_uuid); - if (!rc) - rc = exec_statement_with_uuid(DELETE_NON_EXISTING_LOCALHOST, host_uuid); + rc = exec_statement_with_uuid(CONVERT_EXISTING_LOCALHOST, host_uuid); if (!rc) { if (unlikely(db_execute(db_meta, DELETE_MISSING_NODE_INSTANCES))) error_report("Failed to remove deleted hosts from node instances"); diff --git a/src/database/sqlite/sqlite_metadata.h b/src/database/sqlite/sqlite_metadata.h index 6860cfedf825ab..8441a51b392447 100644 --- a/src/database/sqlite/sqlite_metadata.h +++ b/src/database/sqlite/sqlite_metadata.h @@ -15,7 +15,7 @@ void metaqueue_delete_dimension_uuid(uuid_t *uuid); void metaqueue_store_claim_id(uuid_t *host_uuid, uuid_t *claim_uuid); void metaqueue_host_update_info(RRDHOST *host); void metaqueue_ml_load_models(RRDDIM *rd); -void migrate_localhost(uuid_t *host_uuid); +void detect_machine_guid_change(uuid_t *host_uuid); void metadata_queue_load_host_context(RRDHOST *host); void metadata_delete_host_chart_labels(char *machine_guid); void vacuum_database(sqlite3 *database, const char *db_alias, int threshold, int vacuum_pc); From d3c22fe5be75c81257e46e9073578b7e870a0f7d Mon Sep 17 00:00:00 2001 From: netdatabot Date: Mon, 12 Feb 2024 00:15:55 +0000 Subject: [PATCH 2/2] [ci skip] Update changelog and version for nightly build: v1.44.0-358-nightly. --- CHANGELOG.md | 3 +-- packaging/version | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8526401fdffead..17ddcc8ed7a21e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ - Update input skip patterns [\#16984](https://github.com/netdata/netdata/pull/16984) ([tkatsoulas](https://github.com/tkatsoulas)) - Update input paths for tj-actions/changed-files [\#16982](https://github.com/netdata/netdata/pull/16982) ([tkatsoulas](https://github.com/tkatsoulas)) - Update synology.md [\#16980](https://github.com/netdata/netdata/pull/16980) ([pschaer](https://github.com/pschaer)) +- Detect machine GUID change [\#16979](https://github.com/netdata/netdata/pull/16979) ([stelfrag](https://github.com/stelfrag)) - Regenerate integrations.js [\#16974](https://github.com/netdata/netdata/pull/16974) ([netdatabot](https://github.com/netdatabot)) - Use C++14 by default when building on systems that support it. [\#16972](https://github.com/netdata/netdata/pull/16972) ([Ferroin](https://github.com/Ferroin)) - change edac ecc errors from incremental to absolute [\#16970](https://github.com/netdata/netdata/pull/16970) ([ilyam8](https://github.com/ilyam8)) @@ -398,8 +399,6 @@ - adaptec\_raid: fix parsing PD without NCQ status [\#16400](https://github.com/netdata/netdata/pull/16400) ([ilyam8](https://github.com/ilyam8)) - eBPF apps order [\#16395](https://github.com/netdata/netdata/pull/16395) ([thiagoftsm](https://github.com/thiagoftsm)) - fix systemd-units func expiration time [\#16393](https://github.com/netdata/netdata/pull/16393) ([ilyam8](https://github.com/ilyam8)) -- docker: mount /etc/localtime [\#16392](https://github.com/netdata/netdata/pull/16392) ([ilyam8](https://github.com/ilyam8)) -- fix "differ in signedness" warn in cgroup [\#16391](https://github.com/netdata/netdata/pull/16391) ([ilyam8](https://github.com/ilyam8)) ## [v1.43.2](https://github.com/netdata/netdata/tree/v1.43.2) (2023-10-30) diff --git a/packaging/version b/packaging/version index 04edd81800fb61..32fcdfe12b44cc 100644 --- a/packaging/version +++ b/packaging/version @@ -1 +1 @@ -v1.44.0-356-nightly +v1.44.0-358-nightly