Class ServerBandwidthReportService
The bandwidth page's read, and the rollup and retention of the bandwidth tables.
public sealed class ServerBandwidthReportService : BaseService<ServerBandwidthHourEntity>, IServerBandwidthReportService
- Inheritance
-
ServerBandwidthReportService
- Implements
- Inherited Members
Remarks
Raw SQL throughout: every window is measured against the database clock inside the statement, and the aggregates are too wide for EF to translate sensibly. Table names come from the model, schema-qualified, never from input.
Constructors
ServerBandwidthReportService(INpgsqlDbContextFactory)
public ServerBandwidthReportService(INpgsqlDbContextFactory dbContextFactory)
Parameters
dbContextFactoryINpgsqlDbContextFactory
Fields
HourPruneBatchRows
Expired hour rows deleted per retention batch.
public const int HourPruneBatchRows = 5000
Field Value
RollupLockKey
The advisory lock every rollup and retention transaction takes first ("FMMOBWRU").
public const long RollupLockKey = 5065790158672450133
Field Value
Remarks
One key for both jobs: a retention batch folds the hour it deletes, which is a rollup, so the two must not interleave either. Nothing else in the codebase takes an advisory lock, so the key has no neighbour to collide with.
Methods
FetchReportAsync(ServerBandwidthRange, int, string?, CancellationToken)
Everything the bandwidth page shows, read in one REPEATABLE READ snapshot against one database clock.
public Task<DatabaseResult<ServerBandwidthReport>> FetchReportAsync(ServerBandwidthRange range, int scopeKind, string? scopeName, CancellationToken cancellationToken = default)
Parameters
rangeServerBandwidthRangeThe charted range.
scopeKindintChart one tier (ServerBandwidthKind), or 0 for all.
scopeNamestringChart one server of
scopeKind, or null.cancellationTokenCancellationTokenCancellation token.
Returns
PruneAsync(int, int, CancellationToken)
Deletes minute rows older than MinuteRetentionDays and hour rows older than HourRetentionMonths, in bounded batches.
public Task<DatabaseResult<ServerBandwidthPruneResult>> PruneAsync(int maxMinuteHours, int maxHourBatches, CancellationToken cancellationToken = default)
Parameters
maxMinuteHoursintThe most whole hours of minutes to prune this pass.
maxHourBatchesintThe most delete batches of expired hour rows this pass.
cancellationTokenCancellationTokenCancellation token.
Returns
Remarks
Minutes go one whole hour per transaction, and that transaction first rolls the hour it is about to delete, so pruning can never lose traffic the rollup had not reached, and no hour is ever left with some of its minutes gone (which a later recompute would read as a smaller hour).
RollupAsync(bool, CancellationToken)
Recomputes hour rows from the minutes: the last
RollupWindowHours hours, or every hour that still has
minutes when catchUp is set (the first pass after a panel starts,
covering however long no panel was running).
public Task<DatabaseResult<ServerBandwidthRollupResult>> RollupAsync(bool catchUp, CancellationToken cancellationToken = default)
Parameters
catchUpboolRoll every hour that has minute rows, not just the recent window.
cancellationTokenCancellationTokenCancellation token.