Add health database check before processing alerts and saving logs (#21592)
Stelios Fragkakis committed
Jan 19, 2026 at 16:09 UTC
2736dde103040150c25070e3d1af5ceb2e75a07a
3 files changed
+13
src/database/sqlite/sqlite_aclk_alert.c
+3
@@ -625,6 +625,9 @@ done:
625
626
bool process_alert_pending_queue(RRDHOST *host)
627
{
628
+ if (!REQUIRE_HEALTH_DB_OPEN())
629
+ return false;
630
+
631
static __thread sqlite3_stmt *compiled_res = NULL;
632
sqlite3_stmt *res = NULL;
633
src/database/sqlite/sqlite_functions.h
+4
@@ -57,6 +57,10 @@ void analytics_set_data_str(char **name, const char *value);
57
(db) != NULL; \
58
})
59
60
+extern bool sqlite_databases_closed;
61
+#define REQUIRE_HEALTH_DB_OPEN() \
62
+ (!__atomic_load_n(&sqlite_databases_closed, __ATOMIC_ACQUIRE))
63
+
64
#define PREPARE_COMPILED_STATEMENT(db, sql, stmt_ptr) \
65
({ \
66
bool _ret = true; \
src/database/sqlite/sqlite_health.c
+6
@@ -337,6 +337,9 @@ done:
337
338
void sql_health_alarm_log_save(RRDHOST *host, ALARM_ENTRY *ae)
339
{
340
+ if (!REQUIRE_HEALTH_DB_OPEN())
341
+ return;
342
+
343
if (ae->flags & HEALTH_ENTRY_FLAG_SAVED)
344
sql_health_alarm_log_update(host, ae);
345
else
@@ -945,6 +948,9 @@ done:
948
949
int sql_health_get_last_executed_event(RRDHOST *host, ALARM_ENTRY *ae, RRDCALC_STATUS *last_executed_status)
950
{
951
+ if (!REQUIRE_HEALTH_DB_OPEN())
952
+ return -1;
953
+
954
int ret = -1;
955
static __thread sqlite3_stmt *compiled_res = NULL;
956
sqlite3_stmt *res = NULL;