#20975·vitess

VReplication: engine should reconcile controllers with _vt.vreplication rows after partial VReplicationExec failures

Author: mattlordCreated Sep 2, 2026Updated Sep 30, 2026
LabelsType: BugComponent: VReplication

Overview of the Issue

VReplicationExec's update path in go/vt/vttablet/tabletmanager/vreplication/engine.go is not atomic with respect to the controller map, and a failure partway through leaves the engine's in-memory controllers inconsistent with the durable _vt.vreplication rows, with no reconciliation until the engine is next closed and reopened (e.g. a tablet state transition) or another VReplicationExec touches the same id.

The update path does, in order:

  1. Stop the existing controller(s) for the matched ids (ct.Stop(false)) — before anything durable happens.
  2. Execute the update against _vt.vreplication.
  3. For each id: readRow and newController, replacing the map entry.

Failure windows:

  • Step 2 fails: the row is unchanged, but the old controller is already stopped. The map still holds a stopped controller for a row whose state may say Running — the stream is dead until something rebuilds controllers.
  • Step 3 fails (transient DB error in readRow, or newController error): the row is already updated (e.g. to Running), the old controller is stopped, and no new controller exists. The caller gets an error and typically assumes the exec was not applied.
  • Multi-id updates: a mid-loop failure leaves earlier ids with fresh controllers and later ids stranded.

Symptoms: a workflow that shows Running in _vt.vreplication but replicates nothing and advances no liveness timestamps. For Online DDL migrations the pre-existing staleness mechanism eventually fails the migration (bounded, but the migration is lost to a transient error); for user workflows the stream simply sits dead until an operator intervenes or the tablet transitions state.

This affects every VReplicationExec caller — vtctld workflow commands, resharding operations, tabletmanager RPCs, and Online DDL's automatic resume (whose review surfaced this: see the discussion on #20964). The behavior predates #20964.

Proposed fix

Engine-side reconciliation, rather than caller-side workarounds (callers cannot see or repair engine-internal controller state):

  • A reconcile pass that compares live controllers against _vt.vreplication rows and converges them — create controllers for controller-less rows in a runnable state, stop controllers whose rows say stopped — run periodically, or at minimum scheduled immediately after any exec error in the windows above. This also heals crash-between-steps cases that no transactional rewrite of the exec path can cover.
  • Alternatively (or additionally), make the exec path failure-tolerant: retry the post-update readRow/newController with backoff instead of returning after mutating durable state, and only stop the old controller once its replacement is ready for the step-2-failure window.

Reproduction Steps

Inject a transient error into readRow (or the dbClient) between the update and controller creation during any Workflow start-style VReplicationExec; observe the row marked Running with no controller in the engine map and no replication progress until the engine reopens.

Binary Version

main (observed at 5647b3d69b during review of #20964; behavior is long-standing).

Operating System and Environment details

n/a — engine logic, platform-independent.