observe method
Adjusts the rate for load; returns DV-SCHEMA-003 once, when the rate
has stayed below the floor for longer than the patience.
Implementation
DVSchemaFinding? observe(DVBackfillLoad load, DateTime now) {
final Duration? lag = load.replicaLag;
final double? latency = load.writeLatencyIncrease;
final bool over =
(lag != null && lag > settings.targetReplicaLag) ||
(latency != null && latency > settings.maxWriteLatencyIncrease);
_rate = over
? math.max(1, _rate / 2)
: _rate + settings.tier.startingRate / 10;
if (_rate >= settings.floor) {
_belowFloorSince = null;
_reported = false;
return null;
}
final DateTime since = _belowFloorSince ??= now;
if (_reported || now.difference(since) < settings.patience) return null;
_reported = true;
return DVSchemaFinding(
'DV-SCHEMA-003',
'The backfill has run below its floor of ${settings.floor} rows/s '
'since ${since.toIso8601String()}, longer than its patience of '
'${settings.patience}. The database cannot take it at this load.',
);
}