more index cleanups to optimise space
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -315,6 +315,10 @@ func (c *CronTask) RunSnapshotCleanup(ctx context.Context, logger *slog.Logger)
|
||||
now := time.Now()
|
||||
hourlyMaxDays := intWithDefault(c.Settings.Values.Settings.HourlySnapshotMaxAgeDays, 60)
|
||||
dailyMaxMonths := intWithDefault(c.Settings.Values.Settings.DailySnapshotMaxAgeMonths, 12)
|
||||
hourlyIndexMaxAgeDays := 7
|
||||
if c.Settings != nil && c.Settings.Values != nil {
|
||||
hourlyIndexMaxAgeDays = intWithDefault(c.Settings.Values.Settings.HourlyIndexMaxAgeDays, 7)
|
||||
}
|
||||
|
||||
hourlyCutoff := now.AddDate(0, 0, -hourlyMaxDays)
|
||||
dailyCutoff := now.AddDate(0, -dailyMaxMonths, 0)
|
||||
@@ -324,6 +328,7 @@ func (c *CronTask) RunSnapshotCleanup(ctx context.Context, logger *slog.Logger)
|
||||
"daily_cutoff", truncateDate(dailyCutoff),
|
||||
"hourly_max_age_days", hourlyMaxDays,
|
||||
"daily_max_age_months", dailyMaxMonths,
|
||||
"hourly_index_max_age_days", hourlyIndexMaxAgeDays,
|
||||
)
|
||||
|
||||
dbConn := c.Database.DB()
|
||||
@@ -382,13 +387,31 @@ func (c *CronTask) RunSnapshotCleanup(ctx context.Context, logger *slog.Logger)
|
||||
}
|
||||
}
|
||||
|
||||
trimmedHourlyIndexes := 0
|
||||
if hourlyIndexMaxAgeDays >= 0 && db.TableExists(ctx, dbConn, "vm_hourly_stats") {
|
||||
indexCutoff := truncateDate(now.AddDate(0, 0, -hourlyIndexMaxAgeDays))
|
||||
trimmed, trimErr := db.CleanupHourlySnapshotIndexesOlderThan(ctx, dbConn, indexCutoff)
|
||||
if trimErr != nil {
|
||||
c.Logger.Warn("failed to cleanup old hourly snapshot indexes", "error", trimErr, "index_cutoff", indexCutoff)
|
||||
} else {
|
||||
trimmedHourlyIndexes = trimmed
|
||||
c.Logger.Info("Snapshot cleanup hourly index trim",
|
||||
"index_cutoff", indexCutoff,
|
||||
"trimmed_indexes", trimmedHourlyIndexes,
|
||||
"hourly_index_max_age_days", hourlyIndexMaxAgeDays,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
c.Logger.Info("Finished snapshot cleanup",
|
||||
"hourly_tables_scanned", scannedHourly,
|
||||
"daily_tables_scanned", scannedDaily,
|
||||
"removed_hourly_tables", removedHourly,
|
||||
"removed_daily_tables", removedDaily,
|
||||
"trimmed_hourly_indexes", trimmedHourlyIndexes,
|
||||
"hourly_max_age_days", hourlyMaxDays,
|
||||
"daily_max_age_months", dailyMaxMonths,
|
||||
"hourly_index_max_age_days", hourlyIndexMaxAgeDays,
|
||||
)
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user