{"record":{"id":"12dca5e8f1bd426c","repo":"vitessio/vitess","slug":"no-primary-tablet-found-for-materialization-workfl","errorCode":null,"errorMessage":"no primary tablet found for materialization workflow %s and its stream from the binary log source %s/%s","messagePattern":"no primary tablet found for materialization workflow (.+?) and its stream from the binary log source (.+?)/(.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/vtctl/workflow/stream_migrator.go","lineNumber":723,"sourceCode":"\t\t\t\treturn fmt.Errorf(\"no binlog source is defined for workflow %s\", vrs.Workflow)\n\t\t\t}\n\t\t\tif vrs.WorkflowType == binlogdatapb.VReplicationWorkflowType_Materialize && vrs.BinlogSource.Keyspace == sm.ts.TargetKeyspaceName() {\n\t\t\t\teg.Go(func() error {\n\t\t\t\t\tsourceTablet := source.primary.CloneVT()\n\t\t\t\t\tif sourceTablet.Shard != vrs.BinlogSource.Shard {\n\t\t\t\t\t\tsi, err := sm.ts.TopoServer().GetTabletMapForShard(egCtx, vrs.BinlogSource.GetKeyspace(), vrs.BinlogSource.GetShard())\n\t\t\t\t\t\tif err != nil {\n\t\t\t\t\t\t\treturn err\n\t\t\t\t\t\t}\n\t\t\t\t\t\tfor _, tablet := range si {\n\t\t\t\t\t\t\tif tablet.GetType() == topodatapb.TabletType_PRIMARY {\n\t\t\t\t\t\t\t\tsourceTablet = tablet.CloneVT()\n\t\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif sourceTablet == nil {\n\t\t\t\t\t\treturn fmt.Errorf(\"no primary tablet found for materialization workflow %s and its stream from the binary log source %s/%s\",\n\t\t\t\t\t\t\tvrs.Workflow, vrs.BinlogSource.GetKeyspace(), vrs.BinlogSource.GetShard())\n\t\t\t\t\t}\n\t\t\t\t\tpos, err := sm.ts.TabletManagerClient().PrimaryPosition(egCtx, sourceTablet)\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\treturn err\n\t\t\t\t\t}\n\t\t\t\t\tsm.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\",\n\t\t\t\t\t\tvrs.Workflow, source.primary.Keyspace, source.primary.Shard, pos, vrs.BinlogSource.Keyspace, vrs.BinlogSource.Shard, vrs.Position, topoproto.TabletAliasString(source.primary.Alias))\n\t\t\t\t\tif err := sm.ts.TabletManagerClient().VReplicationWaitForPos(egCtx, source.primary.Tablet, vrs.ID, pos); err != nil {\n\t\t\t\t\t\treturn err\n\t\t\t\t\t}\n\t\t\t\t\treturn nil\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\t\tif err := eg.Wait(); err != nil {\n\t\t\tvar xtra string\n\t\t\tif errors.Is(err, context.DeadlineExceeded) {","sourceCodeStart":705,"sourceCodeEnd":741,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/vtctl/workflow/stream_migrator.go#L705-L741","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Check the topo for the source shard (`vtctldclient GetTablets --keyspace ks --shard <shard>`) and confirm a PRIMARY exists and is healthy.","If the primary is missing, run Reparenting/Elect or re-init the shard's primary (PlannedReparentShard) before retrying the migration stop.","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.","Remove stale shard topo entries if the shard no longer exists."],"exampleFix":"// before: shard '40-' in topo has only REPLICA tablets (no PRIMARY)\n// after: re-establish a primary then retry\nvtctldclient PlannedReparentShard --keyspace ks --shard 40- <alias-of-new-primary>","handlingStrategy":"validation","validationCode":"// Before cutover, verify each shard involved has a serving primary\n// vtctldclient GetTablets --keyspace ks  -> every shard must list exactly one PRIMARY in SERVING state","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Confirm shard primaries exist and are serving before any reshard/cutover operation.","Fix materialization workflows' source shard configuration and remove workflows pointing at deleted shards.","Watch topo health (vtctldclient GetTablets) after any reparent or shard removal."],"tags":["vitess","vreplication","materialize","topology","missing-primary"],"backgroundTag":"missing-primary-tablet","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}