switchReads method

DVSchemaPhaseResult switchReads({
  1. required String release,
  2. required DVBackfillProgress? progress,
})

Moves reads to the new shape in release, once verified. Both shapes are still written, so the old one stays current for any release that reads it. progress is checked again: a chunk that has since stopped matching refuses the switch.

Implementation

DVSchemaPhaseResult switchReads({
  required String release,
  required DVBackfillProgress? progress,
}) {
  if (_phase != DVSchemaPhase.verify || readsSwitched) {
    return _refused(
      reasons: <String>[
        readsSwitched
            ? 'Reads of $id already moved in $_readSwitchRelease.'
            : '$id is in its ${_phase.name} phase; reads switch in the '
                  'verify phase.',
      ],
    );
  }
  final String? reused = _reusedBy(release);
  if (reused != null) return _refused(reasons: <String>[reused]);
  final List<String> reasons = <String>[];
  final List<DVSchemaFinding> findings = <DVSchemaFinding>[];
  if (!verified) {
    reasons.add(
      '$id is not verified: every chunk has to agree on both shapes, with no '
      'dual-write discrepancy, for the whole verification window.',
    );
  }
  _chunks(progress, reasons, findings);
  if (reasons.isNotEmpty || findings.isNotEmpty) {
    return _refused(reasons: reasons, findings: findings);
  }
  _readSwitchRelease = release;
  return DVSchemaPhaseResult(allowed: true, phase: _phase);
}