{"record":{"id":"2c612bd659de9eb8","repo":"vitessio/vitess","slug":"primary-elect-tablet-v-is-not-the-only-primary-in","errorCode":null,"errorMessage":"primary-elect tablet %v is not the only primary in the shard, use -force to proceed anyway","messagePattern":"primary-elect tablet (.+?) is not the only 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":2896,"sourceCode":"\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\n\t// an unstable database process in the mix, with a database daemon\n\t// at a wrong replication spot.\n\n\t// Create a context for the following RPCs that respects waitReplicasTimeout\n\tresetCtx, resetCancel := context.WithTimeout(ctx, waitReplicasTimeout)\n\tdefer resetCancel()\n\n\tevent.DispatchUpdate(ev, \"resetting replication on all tablets\")\n\twg := sync.WaitGroup{}\n\trec := concurrency.AllErrorRecorder{}\n\tfor alias, tabletInfo := range tabletMap {\n\t\twg.Add(1)","sourceCodeStart":2878,"sourceCodeEnd":2914,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/vtctl/grpcvtctldserver/server.go#L2878-L2914","documentation":"Before promoting, PlannedReparentShard ensures the primary-elect would be the only PRIMARY-type tablet in the shard. If another tablet is still marked PRIMARY in the topo (split-brain risk), the RPC aborts unless --force is used, because demoting that other primary is not part of a clean planned reparent.","triggerScenarios":"Calling PlannedReparentShard with --primary-elect-alias X while the tablet map contains a different PRIMARY-type tablet (and X itself may also be primary), with req.Force unset. Happens after interrupted or manual reparents.","commonSituations":"Recovering from a network partition that left two tablets typed as primary, or a previous failed PRS that did not reset the old primary's type.","solutions":["Inspect the shard (`vtctldclient GetShard`, `GetTablets`) to find the extra primary tablet.","Repair the shard state first — e.g. run EmergencyReparentShard or manually fix the stale primary's type — then retry PRS.","Use --force only if you accept the risk of demoting/proceeding with multiple primaries and understand the replication state."],"exampleFix":"// before\nvtctldclient PlannedReparentShard commerce/0 --primary-elect-alias zone1-0000000102\n// after (after confirming safe)\nvtctldclient PlannedReparentShard commerce/0 --primary-elect-alias zone1-0000000102 --force","handlingStrategy":"validation","validationCode":"_, primaryMap := topotools.SortedTabletMap(tabletMap)\nalias := topoproto.TabletAliasString(req.PrimaryElectTabletAlias)\nfor a := range primaryMap {\n    if a != alias {\n        return fmt.Errorf(\"extra primary %s present; repair shard first\", a)\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Detect and repair multiple-primary states with EmergencyReparentShard before planned reparents","After any interrupted failover, verify only one PRIMARY-type tablet remains","Treat --force here as a last resort with full understanding of replication state"],"tags":["vitess","reparent","failover","split-brain"],"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"}