@cryptotaxi247 / netdata-1 / commits / 7f70ffbee

Improve processing of pending alerts (#18470)

Delete only processed alerts

Stelios Fragkakis committed Sep 4, 2024 at 07:34 UTC 7f70ffbee2b5c196170f67537081c9b1267603cc
1 file changed +4 -13
src/database/sqlite/sqlite_aclk_alert.c
+4 -13
@@ -483,10 +483,9 @@ done:
483 SQLITE_FINALIZE(res);
484 }
485
486 -#define SQL_DELETE_PROCESSED_ROWS \
487 - "DELETE FROM alert_queue WHERE host_id = @host_id AND rowid between @row1 AND @row2"
486 +#define SQL_DELETE_PROCESSED_ROWS "DELETE FROM alert_queue WHERE host_id = @host_id AND rowid = @row"
487
489 -static void delete_alert_from_pending_queue(RRDHOST *host, int64_t row1, int64_t row2)
488 +static void delete_alert_from_pending_queue(RRDHOST *host, int64_t row)
489 {
490 static __thread sqlite3_stmt *res = NULL;
491
@@ -495,8 +494,7 @@ static void delete_alert_from_pending_queue(RRDHOST *host, int64_t row1, int64_t
494
495 int param = 0;
496 SQLITE_BIND_FAIL(done, sqlite3_bind_blob(res, ++param, &host->host_id.uuid, sizeof(host->host_id.uuid), SQLITE_STATIC));
498 - SQLITE_BIND_FAIL(done, sqlite3_bind_int64(res, ++param, row1));
499 - SQLITE_BIND_FAIL(done, sqlite3_bind_int64(res, ++param, row2));
497 + SQLITE_BIND_FAIL(done, sqlite3_bind_int64(res, ++param, row));
498
499 param = 0;
500 int rc = sqlite3_step_monitored(res);
@@ -566,8 +564,6 @@ bool process_alert_pending_queue(RRDHOST *host)
564 SQLITE_BIND_FAIL(done, sqlite3_bind_blob(res, ++param, &host->host_id.uuid, sizeof(host->host_id.uuid), SQLITE_STATIC));
565
566 param = 0;
569 - int64_t start_row = 0;
570 - int64_t end_row = 0;
567 while (sqlite3_step_monitored(res) == SQLITE_ROW) {
568
569 int64_t health_log_id = sqlite3_column_int64(res, 0);
@@ -581,16 +577,11 @@ bool process_alert_pending_queue(RRDHOST *host)
577 added++;
578 }
579
584 - if (!start_row)
585 - start_row = row;
586 - end_row = row;
580 + delete_alert_from_pending_queue(host, row);
581
582 count++;
583 }
584
591 - if (start_row)
592 - delete_alert_from_pending_queue(host, start_row, end_row);
593 -
585 if(count)
586 nd_log(NDLS_ACCESS, NDLP_NOTICE, "ACLK STA [%s (N/A)]: Processed %d entries, queued %d", rrdhost_hostname(host), count, added);
587 done: