{"record":{"id":"3f2acc464efbf5bf","repo":"vitessio/vitess","slug":"source-shard-has-no-primary-v","errorCode":null,"errorMessage":"source shard has no primary: %v","messagePattern":"source shard has no primary: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/wrangler/materializer.go","lineNumber":656,"sourceCode":"\t\t\tcontinue\n\t\t}\n\t\tcolName := colVindex.Column\n\t\tif len(colVindex.Columns) != 0 {\n\t\t\tcolName = colVindex.Columns[0]\n\t\t}\n\t\tif colName == sourceVindexColumns[0] {\n\t\t\treturn nil, nil, nil, fmt.Errorf(\"ColumnVindex for table %v already exists: %v, please remove it and try again\", sourceTableName, colName)\n\t\t}\n\t}\n\n\t// Validate against source schema\n\tsourceShards, err := wr.ts.GetServingShards(ctx, keyspace)\n\tif err != nil {\n\t\treturn nil, nil, nil, err\n\t}\n\tonesource := sourceShards[0]\n\tif onesource.PrimaryAlias == nil {\n\t\treturn nil, nil, nil, fmt.Errorf(\"source shard has no primary: %v\", onesource.ShardName())\n\t}\n\treq := &tabletmanagerdatapb.GetSchemaRequest{Tables: []string{sourceTableName}}\n\ttableSchema, err := schematools.GetSchema(ctx, wr.ts, wr.tmc, onesource.PrimaryAlias, req)\n\tif err != nil {\n\t\treturn nil, nil, nil, err\n\t}\n\tif len(tableSchema.TableDefinitions) != 1 {\n\t\treturn nil, nil, nil, fmt.Errorf(\"unexpected number of tables returned from schema: %v\", tableSchema.TableDefinitions)\n\t}\n\n\t// Generate \"create table\" statement\n\tlines := strings.Split(tableSchema.TableDefinitions[0].Schema, \"\\n\")\n\tif len(lines) < 3 {\n\t\t// Unreachable\n\t\treturn nil, nil, nil, fmt.Errorf(\"schema looks incorrect: %s, expecting at least four lines\", tableSchema.TableDefinitions[0].Schema)\n\t}\n\tvar modified []string\n\tmodified = append(modified, strings.Replace(lines[0], sourceTableName, targetTableName, 1))","sourceCodeStart":638,"sourceCodeEnd":674,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/wrangler/materializer.go#L638-L674","documentation":"CreateLookupVindex needs to fetch the source table's schema from a source shard's primary tablet. If the first serving shard's shard record has no PrimaryAlias, there is no primary tablet to query and preparation fails.","triggerScenarios":"The first serving shard of the source keyspace has no elected primary — e.g. during a reshard while the old shard's primary was removed, after ERS/PRS failure, or a shard record left with PrimaryAlias nil following manual topo edits.","commonSituations":"Running CreateLookupVindex mid-reshard when a source shard is orphaned; a primary tablet down and not yet promoted; corrupt/legacy topo data lacking primary info.","solutions":["Ensure every source shard has a healthy primary (`vtctldclient Placements`/`GetTablets`, run PRS if needed) and retry","Wait for any in-flight reshard to finish or use a fully-serving source keyspace","Inspect the shard record (`vtctldclient GetShard ks/shard`) and repair missing PrimaryAlias via PlannedReparentShard"],"exampleFix":"null","handlingStrategy":"validation","validationCode":"shards, err := ts.GetServingShards(ctx, keyspace)\nif err != nil { return err }\nfor _, sh := range shards {\n    if sh.PrimaryAlias == nil {\n        return fmt.Errorf(\"shard %s has no primary; fix replication first\", sh.ShardName())\n    }\n}","typeGuard":"func shardHasPrimary(sh *topodata.Shard) bool { return sh.PrimaryAlias != nil }","tryCatchPattern":"if err := createLookupVindex(...); err != nil {\n    if strings.Contains(err.Error(), \"has no primary\") {\n        return repairShardPrimary(shardName) // run PRS, then retry\n    }\n    return err\n}","preventionTips":["Run `vtctldclient GetTablets` pre-flight to confirm every shard has a serving primary","Avoid running vindex materialization during reshard or failover windows","Monitor replication status alerts before topology-changing operations"],"tags":["vitess","topology","replication","primary-missing"],"backgroundTag":"shard-has-no-primary","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}