{"record":{"id":"52abd5152fee67da","repo":"vitessio/vitess","slug":"no-primary-in-shard-v-v","errorCode":null,"errorMessage":"no primary in shard %v/%v","messagePattern":"no primary in shard (.+?)/(.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/vtctl/grpcvtctldserver/server.go","lineNumber":5413,"sourceCode":"\treturn resp, err\n}\n\n// ValidateVersionShard validates all versions are the same in all\n// tablets in a shard\nfunc (s *VtctldServer) ValidateVersionShard(ctx context.Context, req *vtctldatapb.ValidateVersionShardRequest) (resp *vtctldatapb.ValidateVersionShardResponse, err error) {\n\tspan, ctx := trace.NewSpan(ctx, \"VtctldServer.ValidateVersionShard\")\n\tdefer span.Finish()\n\n\tdefer panicHandler(&err)\n\n\tshard, err := s.ts.GetShard(ctx, req.Keyspace, req.Shard)\n\tif err != nil {\n\t\terr = fmt.Errorf(\"GetShard(%s) failed: %v\", req.Shard, err)\n\t\treturn nil, err\n\t}\n\n\tif !shard.HasPrimary() {\n\t\terr = fmt.Errorf(\"no primary in shard %v/%v\", req.Keyspace, req.Shard)\n\t\treturn nil, err\n\t}\n\n\tlog.Info(fmt.Sprintf(\"Gathering version for primary %v\", topoproto.TabletAliasString(shard.PrimaryAlias)))\n\tprimaryVersion, err := s.GetVersion(ctx, &vtctldatapb.GetVersionRequest{\n\t\tTabletAlias: shard.PrimaryAlias,\n\t})\n\tif err != nil {\n\t\terr = fmt.Errorf(\"GetVersion(%s) failed: %v\", topoproto.TabletAliasString(shard.PrimaryAlias), err)\n\t\treturn nil, err\n\t}\n\n\taliases, err := s.ts.FindAllTabletAliasesInShard(ctx, req.Keyspace, req.Shard)\n\tif err != nil {\n\t\terr = fmt.Errorf(\"FindAllTabletAliasesInShard(%s, %s) failed: %v\", req.Keyspace, req.Shard, err)\n\t\treturn nil, err\n\t}\n","sourceCodeStart":5395,"sourceCodeEnd":5431,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/vtctl/grpcvtctldserver/server.go#L5395-L5431","documentation":"After loading the shard record, ValidateShard requires the shard to have a serving primary tablet. If shard.HasPrimary() is false, it fails with \"no primary in shard %v/%v\" because the primary's version/schema cannot be used as the reference.","triggerScenarios":"Calling ValidateShard (or GetVersion flow) on a shard whose Shard record has no PrimaryAlias set — typically during a primary failover, after ERS/PRS was interrupted, or before InitShardPrimary.","commonSituations":"Shard freshly created but primary not initialized; failover in progress; primary tablet was deleted without electing a new one.","solutions":["Initialize the primary: vtctldclient InitShardPrimary <keyspace>/<shard> <tablet-alias>.","Complete or re-run PlannedReparentShard / EmergencyReparentShard if a failover was interrupted.","Confirm with vtctldclient GetShard <keyspace>/<shard> that a primary alias is present before validating."],"exampleFix":"// before\nvtctldclient ValidateShard commerce 0   // fails: no primary\n// after\nvtctldclient InitShardPrimary commerce/0 zone1-0000000100\nvtctldclient ValidateShard commerce 0","handlingStrategy":"validation","validationCode":"shardInfo, err := ts.GetShard(ctx, ks, shard); if err == nil && !shardInfo.HasPrimary() { return fmt.Errorf(\"shard %s/%s has no primary; run InitShardPrimary first\", ks, shard) }","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"no primary in shard\") { /* initiate reparent or InitShardPrimary before retrying */ }","preventionTips":["Always InitShardPrimary on newly created shards","Confirm primary exists after any reparent before validation","Monitor shard records for missing PrimaryAlias with a periodic check"],"tags":["shard","primary","replication","vtctld"],"backgroundTag":"no-primary-in-shard","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}