{"record":{"id":"0a844f11a003669c","repo":"vitessio/vitess","slug":"no-primary-in-shard-v-v-0a844f","errorCode":null,"errorMessage":"no primary in shard %v/%v","messagePattern":"no primary in shard (.+?)/(.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/wrangler/schema.go","lineNumber":66,"sourceCode":"\tif err != nil {\n\t\ter.RecordError(fmt.Errorf(\"GetSchema(%v, nil, %v, %v) failed: %v\", alias, excludeTables, includeViews, err))\n\t\treturn\n\t}\n\n\tlog.Info(fmt.Sprintf(\"Diffing schema for %v\", topoproto.TabletAliasString(alias)))\n\ttmutils.DiffSchema(topoproto.TabletAliasString(primaryTabletAlias), primarySchema, topoproto.TabletAliasString(alias), replicaSchema, er)\n}\n\n// ValidateSchemaShard will diff the schema from all the tablets in the shard.\nfunc (wr *Wrangler) ValidateSchemaShard(ctx context.Context, keyspace, shard string, excludeTables []string, includeViews bool, includeVSchema bool) error {\n\tsi, err := wr.ts.GetShard(ctx, keyspace, shard)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"GetShard(%v, %v) failed: %v\", keyspace, shard, err)\n\t}\n\n\t// get schema from the primary, or error\n\tif !si.HasPrimary() {\n\t\treturn fmt.Errorf(\"no primary in shard %v/%v\", keyspace, shard)\n\t}\n\tlog.Info(fmt.Sprintf(\"Gathering schema for primary %v\", topoproto.TabletAliasString(si.PrimaryAlias)))\n\treq := &tabletmanagerdatapb.GetSchemaRequest{ExcludeTables: excludeTables, IncludeViews: includeViews}\n\tprimarySchema, err := schematools.GetSchema(ctx, wr.ts, wr.tmc, si.PrimaryAlias, req)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"GetSchema(%v, nil, %v, %v) failed: %v\", si.PrimaryAlias, excludeTables, includeViews, err)\n\t}\n\n\tif includeVSchema {\n\t\terr := wr.ValidateVSchema(ctx, keyspace, []string{shard}, excludeTables, includeViews)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\n\t// read all the aliases in the shard, that is all tablets that are\n\t// replicating from the primary\n\taliases, err := wr.ts.FindAllTabletAliasesInShard(ctx, keyspace, shard)","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/wrangler/schema.go#L48-L84","documentation":"ValidateSchemaShard requires a primary tablet in the shard to serve as the schema baseline; this error is returned when the shard record shows no primary (si.HasPrimary() is false). Schema validation cannot proceed without a source of truth for the schema.","triggerScenarios":"Running ValidateSchemaShard on a shard whose Shard record has no PrimaryAlias — e.g. during reparenting, after a failed InitShardPrimary, or in an empty/decommissioned shard.","commonSituations":"Primary tablet was down so an emergency reparent left the shard record without a primary; shard was created but tablets never initialized; scripted decommission removed the primary; aborted planned reparenting.","solutions":["Run vtctldclient PlannedReparentShard (or EmergencyReparentShard) to elect a primary and populate PrimaryAlias","If no valid primary candidate exists, add a tablet and use InitShardPrimary --force","Verify shard state with vtctldclient GetShard <keyspace/shard> before validating","Ensure tablet health checks are passing so reparenting can succeed"],"exampleFix":"// before: shard has no primary\n// after: elect a primary\nvtctldclient PlannedReparentShard commerce/0 commerce-0000000100","handlingStrategy":"validation","validationCode":"si, err := ts.GetShard(ctx, keyspace, shard)\nif err != nil { return err }\nif !si.HasPrimary() {\n    return fmt.Errorf(\"shard %s/%s has no primary; reparent first\", keyspace, shard)\n}","typeGuard":"func shardHasPrimary(ctx context.Context, ts topoclient.Server, keyspace, shard string) bool {\n    si, err := ts.GetShard(ctx, keyspace, shard)\n    return err == nil && si.HasPrimary()\n}","tryCatchPattern":"if err := wr.ValidateSchemaShard(ctx, ks, shard, nil, true, false); err != nil {\n    if strings.Contains(err.Error(), \"no primary in shard\") {\n        // trigger PlannedReparentShard before retrying\n    }\n}","preventionTips":["Run validation only when each shard has a healthy primary","Alert on shards with empty PrimaryAlias in the topo","Complete reparenting operations before schema validation"],"tags":["vitess","topology","schema-validation","no-primary"],"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"}