Interface IServerBandwidthService
- Namespace
- FishMMO.Database.Npgsql.Services.Interfaces
- Assembly
- FishMMO-DB.dll
What a server process writes about its own bandwidth: server_bandwidth_minute rows.
public interface IServerBandwidthService
Remarks
Separate from IServerBandwidthReportService for the reason IServerBoardService is separate from the per-tier services: a game server talks about itself here and has no business reading every other server's traffic.
The key is decided by the caller, before the write, from the database clock. The
process reads FetchDatabaseUtcNowAsync(CancellationToken), truncates it to the minute, and
passes finished rows to RecordAsync(int, string, Guid, IReadOnlyList<ServerBandwidthSample>, CancellationToken). The upsert never reads a clock itself:
ExecuteWriteAsync retries a lost connection, and a retry that re-read
now() could land a second after the minute turned and write the same traffic
under the next minute's key, where the SET-upsert no longer protects it.
Methods
FetchDatabaseUtcNowAsync(CancellationToken)
The database's UTC wall time, for keying the next minute row.
Task<DatabaseResult<DateTime>> FetchDatabaseUtcNowAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenCancellation token.
Returns
RecordAsync(int, string, Guid, IReadOnlyList<ServerBandwidthSample>, CancellationToken)
Writes a process's minute rows: INSERT … ON CONFLICT DO UPDATE SET col = EXCLUDED.col.
Task<DatabaseResult<int>> RecordAsync(int serverKind, string serverName, Guid instanceId, IReadOnlyList<ServerBandwidthSample> samples, CancellationToken cancellationToken = default)
Parameters
serverKindintThe tier (ServerBandwidthKind).
serverNamestringThe server's configured name.
instanceIdGuidThe process's instance id, taken once at start.
samplesIReadOnlyList<ServerBandwidthSample>The rows, at most one per minute.
cancellationTokenCancellationTokenCancellation token.
Returns
- Task<DatabaseResult<int>>
The number of rows inserted or replaced.
Remarks
Idempotent: writing the same rows twice leaves the table as writing them once, so the caller may re-send rows whose previous write failed or whose reply was lost. A row for a minute already stored REPLACES it (the row carries the minute's running total), unless its interval is shorter than the stored one — the running total of one minute only grows, so a shorter one is an older write arriving late and is ignored.
Failure cases: VALIDATION_ERROR for a bad kind, name, empty instance id, a duplicate minute in the batch, or a row whose Invalid() says why; otherwise the database's own error.