@cryptotaxi247 / netdata-1 / commits / 3f6a59da3

Add defines for cleanup statements (#20570)

* Add defines for cleanup statements * Fix compile * Initialize started_ut variable at declaration in sqlite_metadata.c * Mark 'args' parameter as unused in cmd_update_node_info function

Stelios Fragkakis committed Jun 26, 2025 at 21:47 UTC 3f6a59da33e7b0d963e011b4757e0b0a47fe44ba
2 files changed +16 -11
src/daemon/commands.c
+1 -1
@@ -458,7 +458,7 @@ done:
458 return CMD_STATUS_SUCCESS;
459 }
460
461 -static cmd_status_t cmd_update_node_info(char *args, char **message)
461 +static cmd_status_t cmd_update_node_info(char *args __maybe_unused, char **message)
462 {
463 if (aclk_online()) {
464 schedule_node_state_update(localhost, 1000);
src/database/sqlite/sqlite_metadata.c
+15 -10
@@ -131,6 +131,16 @@ sqlite3 *db_meta = NULL;
131
132 // SQL statements
133
134 +#define SQL_CLEANUP_AGENT_EVENT_LOG "DELETE FROM agent_event_log WHERE date_created < UNIXEPOCH() - 30 * 86400"
135 +
136 +#define SQL_DELETE_ORPHAN_HEALTH_LOG "DELETE FROM health_log WHERE host_id NOT IN (SELECT host_id FROM host)"
137 +
138 +#define SQL_DELETE_ORPHAN_HEALTH_LOG_DETAIL \
139 + "DELETE FROM health_log_detail WHERE health_log_id NOT IN (SELECT health_log_id FROM health_log)"
140 +
141 +#define SQL_DELETE_ORPHAN_ALERT_VERSION \
142 + "DELETE FROM alert_version WHERE health_log_id NOT IN (SELECT health_log_id FROM health_log)"
143 +
144 #define SQL_STORE_CLAIM_ID \
145 "INSERT INTO node_instance " \
146 "(host_id, claim_id, date_created) VALUES (@host_id, @claim_id, UNIXEPOCH()) " \
@@ -1499,13 +1509,9 @@ static void cleanup_health_log(struct meta_config_s *config)
1509 return;
1510 }
1511
1502 - (void)db_execute(db_meta, "DELETE FROM health_log WHERE host_id NOT IN (SELECT host_id FROM host)", NULL);
1503 - (void)db_execute(
1504 - db_meta,
1505 - "DELETE FROM health_log_detail WHERE health_log_id NOT IN (SELECT health_log_id FROM health_log)",
1506 - NULL);
1507 - (void)db_execute(
1508 - db_meta, "DELETE FROM alert_version WHERE health_log_id NOT IN (SELECT health_log_id FROM health_log)", NULL);
1512 + (void) db_execute(db_meta, SQL_DELETE_ORPHAN_HEALTH_LOG, NULL);
1513 + (void) db_execute(db_meta, SQL_DELETE_ORPHAN_HEALTH_LOG_DETAIL, NULL);
1514 + (void) db_execute(db_meta, SQL_DELETE_ORPHAN_ALERT_VERSION, NULL);
1515 worker_is_idle();
1516 }
1517
@@ -2360,9 +2366,8 @@ static void store_hosts_metadata(BUFFER *work_buffer, bool is_worker)
2366 {
2367 RRDHOST *host;
2368 size_t host_count = 0;
2363 - usec_t started_ut;
2369 + usec_t started_ut = now_monotonic_usec();
2370 if (!is_worker) {
2365 - started_ut = now_monotonic_usec();
2371 dfe_start_reentrant(rrdhost_root_index, host) {
2372 host_count++;
2373 }
@@ -2875,7 +2880,7 @@ done:
2880
2881 void cleanup_agent_event_log(void)
2882 {
2878 - (void)db_execute(db_meta, "DELETE FROM agent_event_log WHERE date_created < UNIXEPOCH() - 30 * 86400", NULL);
2883 + (void) db_execute(db_meta, SQL_CLEANUP_AGENT_EVENT_LOG, NULL);
2884 }
2885
2886 #define SQL_GET_AGENT_EVENT_TYPE_MEDIAN \