|
26 | 26 | // Maximum recordings to delete per stream per run |
27 | 27 | #define MAX_RECORDINGS_PER_STREAM 100 |
28 | 28 |
|
| 29 | +// Default retention period (in days) when no global or stream-specific value is configured |
| 30 | +#define DEFAULT_RETENTION_DAYS 30 |
| 31 | +// Multiplier for detection retention default (detection = N * regular retention) |
| 32 | +#define DETECTION_RETENTION_MULTIPLIER 3 |
| 33 | +// Orphan safety parameters |
| 34 | +#define ORPHAN_SAFETY_THRESHOLD 0.5 |
| 35 | +#define MIN_RECORDINGS_FOR_THRESHOLD 10 |
| 36 | + |
29 | 37 | // Forward declarations |
30 | 38 | static int apply_legacy_retention_policy(void); |
31 | | -int get_all_stream_names(char stream_names[][64], int max_streams); |
| 39 | +static int get_all_stream_names(char stream_names[][64], int max_streams); |
32 | 40 |
|
33 | 41 | // Storage manager state |
34 | 42 | static struct { |
@@ -274,8 +282,8 @@ int apply_retention_policy(void) { |
274 | 282 | // Get stream-specific retention config |
275 | 283 | if (get_stream_retention_config(stream_name, &config) != 0) { |
276 | 284 | log_warn("Failed to get retention config for stream %s, using defaults", stream_name); |
277 | | - config.retention_days = storage_manager.retention_days > 0 ? storage_manager.retention_days : 30; |
278 | | - config.detection_retention_days = config.retention_days * 3; // Default: 3x regular retention |
| 285 | + config.retention_days = storage_manager.retention_days > 0 ? storage_manager.retention_days : DEFAULT_RETENTION_DAYS; |
| 286 | + config.detection_retention_days = config.retention_days * DETECTION_RETENTION_MULTIPLIER; // Default: 3x regular retention |
279 | 287 | config.max_storage_mb = 0; // No quota |
280 | 288 | } |
281 | 289 |
|
@@ -401,7 +409,8 @@ int apply_retention_policy(void) { |
401 | 409 | // Safety threshold: if more than 50% of checked recordings appear orphaned, |
402 | 410 | // this is almost certainly a storage availability problem, not genuine orphans. |
403 | 411 | double orphan_ratio = (double)orphan_count / (double)total_checked; |
404 | | - if (orphan_ratio > 0.5 && total_checked >= 10) { |
| 412 | + if (orphan_ratio > ORPHAN_SAFETY_THRESHOLD && |
| 413 | + total_checked >= MIN_RECORDINGS_FOR_THRESHOLD) { |
405 | 414 | log_error("Orphan safety threshold exceeded: %d of %d checked recordings (%.0f%%) " |
406 | 415 | "appear orphaned - this likely indicates a storage availability issue, " |
407 | 416 | "skipping orphan cleanup to protect database integrity", |
@@ -587,9 +596,6 @@ int create_stream_directory(const char *stream_name) { |
587 | 596 | // Maximum recordings to process per emergency cleanup |
588 | 597 | #define MAX_EMERGENCY_RECORDINGS 200 |
589 | 598 |
|
590 | | -// Forward declaration for the cache refresh function |
591 | | -extern int force_refresh_cache(void); |
592 | | - |
593 | 599 | // Unified storage controller thread state |
594 | 600 | static struct { |
595 | 601 | pthread_t thread; |
|
0 commit comments