vitessio/vitess · error

no primary tablet found for materialization workflow %s and

Error message

no primary tablet found for materialization workflow %s and its stream from the binary log source %s/%s

What it means

While stopping source streams, intra-keyspace materialization workflows (source keyspace == the keyspace being resharded) must catch up to the primary position of the shard their stream reads from. The code looks up tablets in the binlog-source shard and needs its PRIMARY; this error is thrown when no PRIMARY tablet can be found for that source shard. The nil check catches the case where sourceTablet was never initialized or the shard's tablet map contained no primary.

Source

Thrown at go/vt/vtctl/workflow/stream_migrator.go:723

				return fmt.Errorf("no binlog source is defined for workflow %s", vrs.Workflow)
			}
			if vrs.WorkflowType == binlogdatapb.VReplicationWorkflowType_Materialize && vrs.BinlogSource.Keyspace == sm.ts.TargetKeyspaceName() {
				eg.Go(func() error {
					sourceTablet := source.primary.CloneVT()
					if sourceTablet.Shard != vrs.BinlogSource.Shard {
						si, err := sm.ts.TopoServer().GetTabletMapForShard(egCtx, vrs.BinlogSource.GetKeyspace(), vrs.BinlogSource.GetShard())
						if err != nil {
							return err
						}
						for _, tablet := range si {
							if tablet.GetType() == topodatapb.TabletType_PRIMARY {
								sourceTablet = tablet.CloneVT()
								break
							}
						}
					}
					if sourceTablet == nil {
						return fmt.Errorf("no primary tablet found for materialization workflow %s and its stream from the binary log source %s/%s",
							vrs.Workflow, vrs.BinlogSource.GetKeyspace(), vrs.BinlogSource.GetShard())
					}
					pos, err := sm.ts.TabletManagerClient().PrimaryPosition(egCtx, sourceTablet)
					if err != nil {
						return err
					}
					sm.ts.Logger().Infof("Waiting for intra-keyspace materialization workflow %s on %v/%v to reach position %v for stream source from %s/%s, starting from position %s on tablet %s",
						vrs.Workflow, source.primary.Keyspace, source.primary.Shard, pos, vrs.BinlogSource.Keyspace, vrs.BinlogSource.Shard, vrs.Position, topoproto.TabletAliasString(source.primary.Alias))
					if err := sm.ts.TabletManagerClient().VReplicationWaitForPos(egCtx, source.primary.Tablet, vrs.ID, pos); err != nil {
						return err
					}
					return nil
				})
			}
		}
		if err := eg.Wait(); err != nil {
			var xtra string
			if errors.Is(err, context.DeadlineExceeded) {

View on GitHub (pinned to 01a25a7d17)

Solutions

  1. Check the topo for the source shard (`vtctldclient GetTablets --keyspace ks --shard <shard>`) and confirm a PRIMARY exists and is healthy.
  2. If the primary is missing, run Reparenting/Elect or re-init the shard's primary (PlannedReparentShard) before retrying the migration stop.
  3. Verify the materialization workflow's binlog source keyspace/shard are correct; cancel and recreate the materialize workflow if it points at a wrong or removed shard.
  4. Remove stale shard topo entries if the shard no longer exists.

Example fix

// before: shard '40-' in topo has only REPLICA tablets (no PRIMARY)
// after: re-establish a primary then retry
vtctldclient PlannedReparentShard --keyspace ks --shard 40- <alias-of-new-primary>
Defensive patterns

Strategy: validation

Validate before calling

// Before cutover, verify each shard involved has a serving primary
// vtctldclient GetTablets --keyspace ks  -> every shard must list exactly one PRIMARY in SERVING state

Prevention

When it happens

Trigger: StopStreams on a reshard whose target keyspace hosts a Materialize workflow reading from that same keyspace, and GetTabletMapForShard for vrs.BinlogSource keyspace/shard returns tablets with no PRIMARY (or the shard map lookup yields nothing), leaving sourceTablet nil.

Common situations: The binlog-source shard has no serving primary (mid-failover, primary tablet removed from topo, or orphaned shard); stale topo cache after a shard was deleted; typo'd keyspace/shard in the materialization workflow config; sourceTablet nil because source.primary was nil and no replacement was found.

Related errors


AI-assisted analysis of vitessio/vitess@01a25a7d17 (2026-09-01). Data as JSON: /api/errors/12dca5e8f1bd426c. Report an issue: GitHub.