feat(historian): SQL Server retention purge (RetentionDays, Primary-gated, applock) (#667)

This commit is contained in:
Joseph Doherty
2026-10-11 08:21:30 -04:00
parent db6a53036b
commit 924eff8d3c
13 changed files with 602 additions and 2 deletions
@@ -0,0 +1,25 @@
namespace ZB.MOM.WW.OtOpcUa.Runtime.Historian;
/// <summary>Rows removed from one historian table by a single purge pass.</summary>
/// <param name="Table">Unqualified table name (the <c>table</c> tag on the retention counter).</param>
/// <param name="Rows">Rows deleted.</param>
public sealed record RetentionPurgeResult(string Table, long Rows);
/// <summary>
/// Backend-side retention purge: deletes history older than the backend's configured retention window.
/// Created by <see cref="IHistorianBackendProvider.CreateRetention"/> and driven on a timer by
/// <see cref="HistorianRetentionService"/>, which owns scheduling and the Primary gate.
/// </summary>
public interface IHistorianRetention
{
/// <summary>How often <see cref="HistorianRetentionService"/> should run a pass.</summary>
TimeSpan Interval { get; }
/// <summary>
/// Runs one purge pass. Returns an empty list when the pass was skipped (another process holds the
/// purge lock). Implementations honour cancellation between batches.
/// </summary>
/// <param name="ct">Cancellation.</param>
/// <returns>Per-table deleted-row counts.</returns>
Task<IReadOnlyList<RetentionPurgeResult>> PurgeAsync(CancellationToken ct);
}