{"record":{"id":"d5e140c0e3f81f04","repo":"vitessio/vitess","slug":"target-shard-v-has-no-primary-tablet","errorCode":null,"errorMessage":"target shard %v has no primary tablet","messagePattern":"target shard (.+?) has no primary tablet","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/vtctl/workflow/resharder.go","lineNumber":112,"sourceCode":"\t\t\treturn nil, vterrors.Wrapf(err, \"GetShard(%s) failed\", shard)\n\t\t}\n\t\tif !si.IsPrimaryServing {\n\t\t\treturn nil, fmt.Errorf(\"source shard %v is not in serving state\", shard)\n\t\t}\n\t\trs.sourceShards = append(rs.sourceShards, si)\n\t\tprimary, err := s.ts.GetTablet(ctx, si.PrimaryAlias)\n\t\tif err != nil {\n\t\t\treturn nil, vterrors.Wrapf(err, \"GetTablet(%s) failed\", si.PrimaryAlias)\n\t\t}\n\t\trs.sourcePrimaries[si.ShardName()] = primary\n\t}\n\tfor _, shard := range targets {\n\t\tsi, err := s.ts.GetShard(ctx, keyspace, shard)\n\t\tif err != nil {\n\t\t\treturn nil, vterrors.Wrapf(err, \"GetShard(%s) failed\", shard)\n\t\t}\n\t\tif si.PrimaryAlias == nil {\n\t\t\treturn nil, fmt.Errorf(\"target shard %v has no primary tablet\", shard)\n\t\t}\n\t\tif si.IsPrimaryServing {\n\t\t\treturn nil, fmt.Errorf(\"target shard %v is in serving state\", shard)\n\t\t}\n\t\trs.targetShards = append(rs.targetShards, si)\n\t\tprimary, err := s.ts.GetTablet(ctx, si.PrimaryAlias)\n\t\tif err != nil {\n\t\t\treturn nil, vterrors.Wrapf(err, \"GetTablet(%s) failed\", si.PrimaryAlias)\n\t\t}\n\t\trs.targetPrimaries[si.ShardName()] = primary\n\t}\n\tif err := topotools.ValidateForReshard(rs.sourceShards, rs.targetShards); err != nil {\n\t\treturn nil, vterrors.Wrap(err, \"ValidateForReshard\")\n\t}\n\tif err := rs.validateTargets(ctx); err != nil {\n\t\treturn nil, vterrors.Wrap(err, \"validateTargets\")\n\t}\n","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/vtctl/workflow/resharder.go#L94-L130","documentation":"buildResharder requires every target shard to have a primary tablet (PrimaryAlias set) so the vreplication streams have somewhere to replicate into. If a target shard has no elected primary, this error names the shard and aborts ReshardCreate.","triggerScenarios":"ReshardCreate targets new shards whose primaries were not initialized — e.g. target tablets registered but InitShardPrimary never run on one of the new shards.","commonSituations":"New shards created for the split but one target tablet failed to start before Reshard; forgotten InitShardPrimary on a fresh shard; target tablet in a bad state so no primary was elected.","solutions":["Initialize the shard's primary: `vtctl InitShardPrimary <keyspace>/<shard> <tablet-alias>` (or force flag as appropriate)","Verify with `vtctl GetShard <keyspace>/<shard>` that PrimaryAlias is now set before re-running Reshard","Bring up/repair the missing target tablet so it can be promoted"],"exampleFix":"// before (shard 40- has no primary)\nReshard --source-shards=0- --target-shards=0-40,40-\n// after\nvtctl InitShardPrimary ks/40- zone1-0000000100\nReshard --source-shards=0- --target-shards=0-40,40-","handlingStrategy":"validation","validationCode":"for _, shard := range targetShards {\n    si, err := ts.GetShard(ctx, ks, shard)\n    if err != nil { return err }\n    if si.PrimaryAlias == nil {\n        return fmt.Errorf(\"pre-check: target shard %s has no primary; run InitShardPrimary\", shard)\n    }\n}","typeGuard":null,"tryCatchPattern":"if _, err := reshardCreate(ctx, req); err != nil {\n    if strings.Contains(err.Error(), \"has no primary tablet\") {\n        // init the shard primary, then retry ReshardCreate\n    }\n    return err\n}","preventionTips":["Always run InitShardPrimary on every new target shard before Reshard","Verify PrimaryAlias via GetShard in the reshard pre-flight","Bring up all target tablets and confirm election before starting the workflow"],"tags":["vitess","resharding","vreplication","primary-tablet","topology"],"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"}