Table of Contents

Class ServerBandwidthReportService

Namespace
FishMMO.Database.Npgsql.Services
Assembly
FishMMO-DB.dll

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

dbContextFactory INpgsqlDbContextFactory

Fields

HourPruneBatchRows

Expired hour rows deleted per retention batch.

public const int HourPruneBatchRows = 5000

Field Value

int

RollupLockKey

The advisory lock every rollup and retention transaction takes first ("FMMOBWRU").

public const long RollupLockKey = 5065790158672450133

Field Value

long

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

range ServerBandwidthRange

The charted range.

scopeKind int

Chart one tier (ServerBandwidthKind), or 0 for all.

scopeName string

Chart one server of scopeKind, or null.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<DatabaseResult<ServerBandwidthReport>>

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

maxMinuteHours int

The most whole hours of minutes to prune this pass.

maxHourBatches int

The most delete batches of expired hour rows this pass.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<DatabaseResult<ServerBandwidthPruneResult>>

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

catchUp bool

Roll every hour that has minute rows, not just the recent window.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<DatabaseResult<ServerBandwidthRollupResult>>