Skip to content

Implement manual retention sweep - #5845

Open
rbev wants to merge 10 commits into
masterfrom
allow-manual-retention-sweep
Open

Implement manual retention sweep#5845
rbev wants to merge 10 commits into
masterfrom
allow-manual-retention-sweep

Conversation

@rbev

@rbev rbev commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

This pull request introduces a manual data retention sweep API for ServiceControl, enabling users to trigger and monitor retention sweeps via new endpoints. It includes new API contracts, permission management, and enhancements to the EFCore persistence layer to support manual and scheduled sweeps, including proper status reporting and concurrency control. Additionally, it ensures that unsupported operations on RavenDB are handled gracefully.

Manual Retention Sweep API and EFCore Support:

  • Introduced new API contracts: RetentionSweepRequest, RetentionSweepResponse, and RetentionSweepStatus to enable manual triggering and status polling for data retention sweeps (src/ServiceControl.Api/Contracts/RetentionSweepRequest.cs, RetentionSweepResponse.cs, RetentionSweepStatus.cs). [1] [2] [3]
  • Added the IRetentionApi interface defining methods for starting a sweep and retrieving sweep status, with support for indicating when the operation is not supported (e.g., on RavenDB) (src/ServiceControl.Api/IRetentionApi.cs).
  • Enhanced the EFCore RetentionSweeper to support manual sweeps with caller-supplied cutoffs, concurrency control to prevent overlapping sweeps, and detailed status reporting for the new API (src/ServiceControl.Persistence.EFCore/Infrastructure/RetentionSweeper.cs, BasePersistence.cs). [1] [2] [3] [4] [5] [6] [7]

API Permissions and Roles:

  • Added a new permission constant ErrorRetentionSweep and included it in the admin role permissions to control access to the manual retention sweep API (src/ServiceControl.Infrastructure/Auth/Permissions.cs, RolePermissions.cs). [1] [2]

Comment thread src/ServiceControl/Retention/Api/RetentionController.cs Outdated
@rbev
rbev requested review from abparticular, johnsimons and warwickschroeder and removed request for johnsimons September 2, 2026 07:25
Comment thread src/ServiceControl/Retention/Api/RetentionController.cs Outdated
@rbev
rbev marked this pull request as ready for review September 3, 2026 01:40
Comment thread src/ServiceControl/Infrastructure/Api/RetentionApi.cs Outdated
Comment thread src/ServiceControl.Api/IRetentionApi.cs Outdated
@rbev
rbev force-pushed the allow-manual-retention-sweep branch from 599d097 to 6f54751 Compare September 7, 2026 02:27
@rbev
rbev requested a review from johnsimons September 8, 2026 03:47
Comment thread src/ServiceControl/Infrastructure/Api/RetentionApi.cs Outdated
Comment thread src/ServiceControl/Infrastructure/Api/RetentionApi.cs Outdated
Comment thread src/ServiceControl.Persistence.EFCore/Infrastructure/RetentionSweeper.cs Outdated
Comment thread src/ServiceControl/Retention/Api/SystemMaintenanceController.cs
Comment thread src/ServiceControl/Infrastructure/Api/RetentionApi.cs Outdated
DateTime? lastFinishedAt;
DateTime? lastErrorCutoff;
DateTime? lastEventsCutoff;
string? lastError;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These seem to be shared between the manual purge and the hourly sweep. Is this going to cause a problem? Someone polling their manual, might get wrong values due to the hourly running? Or should the hourly be disabled while a manual is running, and vice versa?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are, but the two have slightly different paths -

  • auto sweep blocks if another (manual) one is running
  • manual run takes the lock and immediately and kicks off a background task to do the work

Both paths take the semaphore before mutating the variables and finish editing them before releasing it, however the manual run sets the start values before kicking off the background work.

Comment thread src/ServiceControl/Retention/Api/SystemMaintenanceController.cs Outdated
Comment thread src/ServiceControl/Infrastructure/Api/RetentionApi.cs Outdated
@rbev
rbev force-pushed the allow-manual-retention-sweep branch from 35151d8 to aa9f545 Compare September 8, 2026 09:17

@johnsimons johnsimons left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a couple of comments to consider

Comment thread src/ServiceControl.Persistence.EFCore/Infrastructure/RetentionSweeper.cs Outdated
@rbev
rbev force-pushed the allow-manual-retention-sweep branch from c578068 to 9c92da7 Compare September 9, 2026 02:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants