Skip to content

Commit 5394c0d

Browse files
committed
Pauses ingestion during retention cleanup
Ensures data ingestion is paused during retention cleanup to prevent conflicts and data corruption. Sets a flag to prevent more data ingestion while partitions are being dropped to avoid race conditions.
1 parent 4f62e3e commit 5394c0d

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

src/ServiceControl.Audit.Persistence.Sql.Core/Infrastructure/RetentionCleaner.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ public abstract class RetentionCleaner(
1515
AuditSqlPersisterSettings settings,
1616
IBodyStoragePersistence bodyPersistence,
1717
IPartitionManager partitionManager,
18-
RetentionMetrics metrics) : BackgroundService
18+
RetentionMetrics metrics,
19+
MinimumRequiredStorageState storageState) : BackgroundService
1920
{
2021
const int HoursAhead = 6;
2122

@@ -80,6 +81,7 @@ async Task Clean(CancellationToken stoppingToken)
8081
// Find and drop expired partitions
8182
var expiredPartitions = await partitionManager.GetExpiredPartitions(dbContext, cutoff, stoppingToken);
8283

84+
storageState.CanIngestMore = false;
8385
foreach (var hour in expiredPartitions)
8486
{
8587
// Delete body storage for this hour first
@@ -101,6 +103,7 @@ async Task Clean(CancellationToken stoppingToken)
101103
finally
102104
{
103105
await ReleaseLock(lockConnection, stoppingToken);
106+
storageState.CanIngestMore = true;
104107
}
105108
}
106109

0 commit comments

Comments
 (0)