{"record":{"id":"97dd21754b7c3c71","repo":"vitessio/vitess","slug":"primary-elect-tablet-v-is-not-in-the-shard","errorCode":null,"errorMessage":"primary-elect tablet %v is not in the shard","messagePattern":"primary-elect tablet (.+?) is not in the shard","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/vtctl/grpcvtctldserver/server.go","lineNumber":2869,"sourceCode":"\t\treturn err\n\t}\n\tlog.Info(fmt.Sprintf(\"Getting a new durability policy for %v\", durabilityName))\n\tdurability, err := policy.GetDurabilityPolicy(durabilityName)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tevent.DispatchUpdate(ev, \"reading tablet map\")\n\ttabletMap, err := s.ts.GetTabletMapForShard(ctx, req.Keyspace, req.Shard)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\t// Check the primary elect is in tabletMap.\n\tprimaryElectTabletAliasStr := topoproto.TabletAliasString(req.PrimaryElectTabletAlias)\n\tprimaryElectTabletInfo, ok := tabletMap[primaryElectTabletAliasStr]\n\tif !ok {\n\t\treturn fmt.Errorf(\"primary-elect tablet %v is not in the shard\", topoproto.TabletAliasString(req.PrimaryElectTabletAlias))\n\t}\n\tev.NewPrimary = primaryElectTabletInfo.CloneVT()\n\n\t// Check the primary is the only primary is the shard, or -force was used.\n\t_, primaryTabletMap := topotools.SortedTabletMap(tabletMap)\n\tif !topoproto.TabletAliasEqual(shardInfo.PrimaryAlias, req.PrimaryElectTabletAlias) {\n\t\tif !req.Force {\n\t\t\treturn fmt.Errorf(\"primary-elect tablet %v is not the shard primary, use -force to proceed anyway\", topoproto.TabletAliasString(req.PrimaryElectTabletAlias))\n\t\t}\n\n\t\tlogger.Warningf(\"primary-elect tablet %v is not the shard primary, proceeding anyway as -force was used\", topoproto.TabletAliasString(req.PrimaryElectTabletAlias))\n\t}\n\tif _, ok := primaryTabletMap[primaryElectTabletAliasStr]; !ok {\n\t\tif !req.Force {\n\t\t\treturn fmt.Errorf(\"primary-elect tablet %v is not a primary in the shard, use -force to proceed anyway\", topoproto.TabletAliasString(req.PrimaryElectTabletAlias))\n\t\t}\n\t\tlogger.Warningf(\"primary-elect tablet %v is not a primary in the shard, proceeding anyway as -force was used\", topoproto.TabletAliasString(req.PrimaryElectTabletAlias))\n\t}","sourceCodeStart":2851,"sourceCodeEnd":2887,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/vtctl/grpcvtctldserver/server.go#L2851-L2887","documentation":"PlannedReparentShard validates that the requested PrimaryElectTabletAlias exists in the shard's tablet map before reparenting. If the alias is not found among the shard's tablets, the reparent is aborted — the RPC failed validation and no topology change was made.","triggerScenarios":"Calling PlannedReparentShard with req.PrimaryElectTabletAlias set to an alias that is not a tablet of the target shard (wrong shard, removed tablet, or mistyped alias).","commonSituations":"Copy-pasting an alias from another shard, referencing a tablet after it was decommissioned, or passing an empty alias.","solutions":["List the shard's tablets (`vtctldclient GetTablets --keyspace ks --shard shard`) and use a valid alias.","Correct typos or wrong-cluster/shard references in the alias.","If the tablet was removed, first restore/replace the tablet then retry the PRS call."],"exampleFix":"// before\nvtctldclient PlannedReparentShard commerce/0 --primary-elect-alias zone1-0000009999\n// after\nvtctldclient PlannedReparentShard commerce/0 --primary-elect-alias zone1-0000000102","handlingStrategy":"validation","validationCode":"alias := topoproto.TabletAliasString(req.PrimaryElectTabletAlias)\nif _, ok := tabletMap[alias]; !ok {\n    return fmt.Errorf(\"tablet %s not in shard\", alias)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["List shard tablets before choosing a primary-elect alias","Never hardcode tablet aliases in scripts; fetch them from the topo","Confirm the alias belongs to the target keyspace/shard"],"tags":["vitess","reparent","failover","validation"],"backgroundTag":"primary-elect-validation-failed","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}