{"record":{"id":"a5f5d50976747f0a","repo":"vitessio/vitess","slug":"primary-elect-tablet-v-is-not-a-primary-in-the-sh","errorCode":null,"errorMessage":"primary-elect tablet %v is not a primary in the shard, use -force to proceed anyway","messagePattern":"primary-elect tablet (.+?) is not a primary in the shard, use -force to proceed anyway","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/vtctl/grpcvtctldserver/server.go","lineNumber":2884,"sourceCode":"\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}\n\thaveOtherPrimary := false\n\tfor alias := range primaryTabletMap {\n\t\tif primaryElectTabletAliasStr != alias {\n\t\t\thaveOtherPrimary = true\n\t\t}\n\t}\n\tif haveOtherPrimary {\n\t\tif !req.Force {\n\t\t\treturn fmt.Errorf(\"primary-elect tablet %v is not the only 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 the only primary in the shard, proceeding anyway as -force was used\", topoproto.TabletAliasString(req.PrimaryElectTabletAlias))\n\t}\n\n\t// First phase: reset replication on all tablets. If anyone fails,\n\t// we stop. It is probably because it is unreachable, and may leave","sourceCodeStart":2866,"sourceCodeEnd":2902,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/vtctl/grpcvtctldserver/server.go#L2866-L2902","documentation":"PlannedReparentShard also checks the tablet map: the primary-elect tablet must currently be running as a PRIMARY type tablet in the shard. If it is a replica/rdonly tablet, the RPC refuses to proceed unless --force is given.","triggerScenarios":"Calling PlannedReparentShard with --primary-elect-alias naming a tablet whose topo record is not of type PRIMARY (e.g. a REPLICA) and req.Force unset. Typically after a partial prior failover left the shard's type assignments inconsistent.","commonSituations":"Resuming after a failed reparent where the intended tablet is a replica; stale topo types after an emergency reparent; operator confusion between current and desired primary.","solutions":["Verify the tablet's type with `vtctldclient GetTablet <alias>`; if it is actually the primary in practice, fix the topo type (e.g. via EmergencyReparentShard or TabletExternallyReparented).","Use --force to proceed with promotion despite the topo type mismatch.","Re-run PlannedReparentShard without an alias to let Vitess pick the current primary."],"exampleFix":"// before\nvtctldclient PlannedReparentShard commerce/0 --primary-elect-alias zone1-0000000102\n// after\nvtctldclient PlannedReparentShard commerce/0 --primary-elect-alias zone1-0000000102 --force","handlingStrategy":"validation","validationCode":"info, ok := tabletMap[topoproto.TabletAliasString(req.PrimaryElectTabletAlias)]\nif !ok || info.Tablet.Type != topodatapb.TabletType_PRIMARY {\n    if !req.Force { return errors.New(\"primary-elect is not a PRIMARY tablet\") }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run GetTablet on the alias to confirm its type is PRIMARY before PRS","Repair inconsistent tablet types after failed reparents before retrying","Understand that topo type must match reality; fix with ERS if not"],"tags":["vitess","reparent","failover","tablet-type"],"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"}