diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-09-10 20:12:12 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-09-10 20:12:12 +0000 |
commit | 1b5b13047cfe151692fd3ece47bd1e01d25773e6 (patch) | |
tree | 847f1dd98d02de98b7e4bbd0ca8042a1c3e44408 /src/database | |
parent | Releasing debian version 1.47.0-1. (diff) | |
download | netdata-1b5b13047cfe151692fd3ece47bd1e01d25773e6.tar.xz netdata-1b5b13047cfe151692fd3ece47bd1e01d25773e6.zip |
Merging upstream version 1.47.1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/database')
-rw-r--r-- | src/database/sqlite/sqlite_aclk.c | 30 | ||||
-rw-r--r-- | src/database/sqlite/sqlite_aclk_alert.c | 17 | ||||
-rw-r--r-- | src/database/sqlite/sqlite_health.c | 4 |
3 files changed, 34 insertions, 17 deletions
diff --git a/src/database/sqlite/sqlite_aclk.c b/src/database/sqlite/sqlite_aclk.c index 027ee8f93..adbe4d9d3 100644 --- a/src/database/sqlite/sqlite_aclk.c +++ b/src/database/sqlite/sqlite_aclk.c @@ -199,6 +199,34 @@ fail: buffer_free(sql); } +#define SQL_INVALIDATE_HOST_LAST_CONNECTED "UPDATE host SET last_connected = 1 WHERE host_id = @host_id" + +static void invalidate_host_last_connected(nd_uuid_t *host_uuid) +{ + sqlite3_stmt *res = NULL; + if (!host_uuid) + return; + + if (!PREPARE_STATEMENT(db_meta, SQL_INVALIDATE_HOST_LAST_CONNECTED, &res)) + return; + + int param = 0; + SQLITE_BIND_FAIL(bind_fail, sqlite3_bind_blob(res, ++param, host_uuid, sizeof(*host_uuid), SQLITE_STATIC)); + + param = 0; + int rc = sqlite3_step_monitored(res); + if (unlikely(rc != SQLITE_DONE)) { + char wstr[UUID_STR_LEN]; + uuid_unparse_lower(*host_uuid, wstr); + error_report("Failed invalidate last_connected time for host with GUID %s, rc = %d", wstr, rc); + } + +bind_fail: + REPORT_BIND_FAIL(res, param); + SQLITE_FINALIZE(res); +} + + // OPCODE: ACLK_DATABASE_NODE_UNREGISTER static void sql_unregister_node(char *machine_guid) { @@ -226,6 +254,7 @@ static void sql_unregister_node(char *machine_guid) error_report("Failed to execute command to remove host node id"); } else { // node: machine guid will be freed after processing + invalidate_host_last_connected(&host_uuid); metadata_delete_host_chart_labels(machine_guid); machine_guid = NULL; } @@ -329,7 +358,6 @@ static void aclk_synchronization(void *arg) break; case ACLK_DATABASE_NODE_UNREGISTER: sql_unregister_node(cmd.param[0]); - break; // ALERTS case ACLK_DATABASE_PUSH_ALERT_CONFIG: diff --git a/src/database/sqlite/sqlite_aclk_alert.c b/src/database/sqlite/sqlite_aclk_alert.c index 3e7076169..dbe5a5045 100644 --- a/src/database/sqlite/sqlite_aclk_alert.c +++ b/src/database/sqlite/sqlite_aclk_alert.c @@ -488,10 +488,9 @@ done: freez(claim_id); } -#define SQL_DELETE_PROCESSED_ROWS \ - "DELETE FROM alert_queue WHERE host_id = @host_id AND rowid between @row1 AND @row2" +#define SQL_DELETE_PROCESSED_ROWS "DELETE FROM alert_queue WHERE host_id = @host_id AND rowid = @row" -static void delete_alert_from_pending_queue(RRDHOST *host, int64_t row1, int64_t row2) +static void delete_alert_from_pending_queue(RRDHOST *host, int64_t row) { static __thread sqlite3_stmt *res = NULL; @@ -500,8 +499,7 @@ static void delete_alert_from_pending_queue(RRDHOST *host, int64_t row1, int64_t int param = 0; SQLITE_BIND_FAIL(done, sqlite3_bind_blob(res, ++param, &host->host_uuid, sizeof(host->host_uuid), SQLITE_STATIC)); - SQLITE_BIND_FAIL(done, sqlite3_bind_int64(res, ++param, row1)); - SQLITE_BIND_FAIL(done, sqlite3_bind_int64(res, ++param, row2)); + SQLITE_BIND_FAIL(done, sqlite3_bind_int64(res, ++param, row)); param = 0; int rc = sqlite3_step_monitored(res); @@ -571,8 +569,6 @@ bool process_alert_pending_queue(RRDHOST *host) SQLITE_BIND_FAIL(done, sqlite3_bind_blob(res, ++param, &host->host_uuid, sizeof(host->host_uuid), SQLITE_STATIC)); param = 0; - int64_t start_row = 0; - int64_t end_row = 0; while (sqlite3_step_monitored(res) == SQLITE_ROW) { int64_t health_log_id = sqlite3_column_int64(res, 0); @@ -586,16 +582,11 @@ bool process_alert_pending_queue(RRDHOST *host) added++; } - if (!start_row) - start_row = row; - end_row = row; + delete_alert_from_pending_queue(host, row); count++; } - if (start_row) - delete_alert_from_pending_queue(host, start_row, end_row); - if(count) nd_log(NDLS_ACCESS, NDLP_NOTICE, "ACLK STA [%s (N/A)]: Processed %d entries, queued %d", rrdhost_hostname(host), count, added); done: diff --git a/src/database/sqlite/sqlite_health.c b/src/database/sqlite/sqlite_health.c index a632fd494..9304c8c73 100644 --- a/src/database/sqlite/sqlite_health.c +++ b/src/database/sqlite/sqlite_health.c @@ -437,12 +437,10 @@ static void sql_inject_removed_status( int64_t health_log_id = sqlite3_column_int64(res, 0); RRDCALC_STATUS old_status = (RRDCALC_STATUS)sqlite3_column_double(res, 1); insert_alert_queue( - host, health_log_id, (int64_t)unique_id, (int64_t)alarm_id, old_status, RRDCALC_STATUS_REMOVED); + host, health_log_id, (int64_t)max_unique_id, (int64_t)alarm_id, old_status, RRDCALC_STATUS_REMOVED); } #endif } - //else - // error_report("HEALTH [N/A]: Failed to execute SQL_INJECT_REMOVED, rc = %d", rc); done: REPORT_BIND_FAIL(res, param); |