Delay context cleanup checks after startup (#19403)
Delay ctx cleanup checks after startup
Stelios Fragkakis committed
Jan 15, 2025 at 13:18 UTC
9f2e8fc65d8a49086a7d59f26c7cbf56edf22e97
1 file changed
+10
-1
src/database/sqlite/sqlite_metadata.c
+10
-1
@@ -170,6 +170,7 @@ sqlite3 *db_meta = NULL;
170
171
#define METADATA_MAINTENANCE_FIRST_CHECK (1800) // Maintenance first run after agent startup in seconds
172
#define METADATA_MAINTENANCE_REPEAT (60) // Repeat if last run for dimensions, charts, labels needs more work
173
+#define METADATA_MAINTENANCE_CTX_CLEAN_REPEAT (300) // Repeat if last run for dimensions, charts, labels needs more work
174
#define METADATA_HEALTH_LOG_INTERVAL (3600) // Repeat maintenance for health
175
#define METADATA_DIM_CHECK_INTERVAL (3600) // Repeat maintenance for dimensions
176
#define METADATA_CHART_CHECK_INTERVAL (3600) // Repeat maintenance for charts
@@ -1696,10 +1697,17 @@ done:
1697
1698
void run_metadata_cleanup(struct metadata_wc *wc)
1699
{
1700
+ static time_t next_context_list_cleanup = 0;
1701
+
1702
+ time_t now = now_realtime_sec();
1703
+
1704
+ if (!next_context_list_cleanup)
1705
+ next_context_list_cleanup = now + METADATA_MAINTENANCE_FIRST_CHECK;
1706
+
1707
if (unlikely(metadata_flag_check(wc, METADATA_FLAG_SHUTDOWN)))
1708
return;
1709
1702
- if (sql_metadata_wal_size_acceptable()) {
1710
+ if (next_context_list_cleanup < now && sql_metadata_wal_size_acceptable()) {
1711
RRDHOST *host;
1712
dfe_start_reentrant(rrdhost_root_index, host) {
1713
ctx_get_context_list_to_cleanup(&host->host_id.uuid, cleanup_host_context_metadata, host);
@@ -1707,6 +1715,7 @@ void run_metadata_cleanup(struct metadata_wc *wc)
1715
break;
1716
}
1717
dfe_done(host);
1718
+ next_context_list_cleanup = now_realtime_sec() + METADATA_MAINTENANCE_CTX_CLEAN_REPEAT;
1719
}
1720
1721
if (unlikely(metadata_flag_check(wc, METADATA_FLAG_SHUTDOWN)))