vitessio/vitess · error

primary-elect tablet %v is not the shard primary, use -force

Error message

primary-elect tablet %v is not the shard primary, use -force to proceed anyway

What it means

During PlannedReparentShard, if the primary-elect tablet is not the shard's current primary alias in the topo, Vitess refuses to proceed unless req.Force is set, because reparenting to a non-primary would promote a replica and drop the existing primary. The shard's topology is left unchanged on this error.

Source

Thrown at go/vt/vtctl/grpcvtctldserver/server.go:2877

	event.DispatchUpdate(ev, "reading tablet map")
	tabletMap, err := s.ts.GetTabletMapForShard(ctx, req.Keyspace, req.Shard)
	if err != nil {
		return err
	}

	// Check the primary elect is in tabletMap.
	primaryElectTabletAliasStr := topoproto.TabletAliasString(req.PrimaryElectTabletAlias)
	primaryElectTabletInfo, ok := tabletMap[primaryElectTabletAliasStr]
	if !ok {
		return fmt.Errorf("primary-elect tablet %v is not in the shard", topoproto.TabletAliasString(req.PrimaryElectTabletAlias))
	}
	ev.NewPrimary = primaryElectTabletInfo.CloneVT()

	// Check the primary is the only primary is the shard, or -force was used.
	_, primaryTabletMap := topotools.SortedTabletMap(tabletMap)
	if !topoproto.TabletAliasEqual(shardInfo.PrimaryAlias, req.PrimaryElectTabletAlias) {
		if !req.Force {
			return fmt.Errorf("primary-elect tablet %v is not the shard primary, use -force to proceed anyway", topoproto.TabletAliasString(req.PrimaryElectTabletAlias))
		}

		logger.Warningf("primary-elect tablet %v is not the shard primary, proceeding anyway as -force was used", topoproto.TabletAliasString(req.PrimaryElectTabletAlias))
	}
	if _, ok := primaryTabletMap[primaryElectTabletAliasStr]; !ok {
		if !req.Force {
			return fmt.Errorf("primary-elect tablet %v is not a primary in the shard, use -force to proceed anyway", topoproto.TabletAliasString(req.PrimaryElectTabletAlias))
		}
		logger.Warningf("primary-elect tablet %v is not a primary in the shard, proceeding anyway as -force was used", topoproto.TabletAliasString(req.PrimaryElectTabletAlias))
	}
	haveOtherPrimary := false
	for alias := range primaryTabletMap {
		if primaryElectTabletAliasStr != alias {
			haveOtherPrimary = true
		}
	}
	if haveOtherPrimary {
		if !req.Force {

View on GitHub (pinned to 01a25a7d17)

Solutions

  1. Use --force if you really want to promote this non-primary tablet anyway.
  2. Pass --primary-elect-alias equal to the current primary for a graceful reparent, or omit the alias to just demote/promote cleanly.
  3. Verify shard state with `vtctldclient GetShard` to see who the current primary is before retrying.

Example fix

// before
vtctldclient PlannedReparentShard commerce/0 --primary-elect-alias zone1-0000000102
// after (intentional override)
vtctldclient PlannedReparentShard commerce/0 --primary-elect-alias zone1-0000000102 --force
Defensive patterns

Strategy: validation

Validate before calling

shardInfo, _ := ts.GetShard(ctx, ks, shard)
if !topoproto.TabletAliasEqual(shardInfo.PrimaryAlias, req.PrimaryElectTabletAlias) && !force {
    return fmt.Errorf("alias %s is not current primary; add --force or omit alias",
        topoproto.TabletAliasString(req.PrimaryElectTabletAlias))
}

Prevention

When it happens

Trigger: Calling PlannedReparentShard with --primary-elect-alias pointing to a replica when the shard's current primary is a different tablet, without --force. (Promoting the current primary without an alias, i.e. empty alias, is the normal path.)

Common situations: Operators thinking PRS behaves like EmergencyReparentShard, forgetting that a non-empty primary-elect must name the current primary for a clean swap (or must be paired with --force to override).

Related errors


AI-assisted analysis of vitessio/vitess@01a25a7d17 (2026-09-01). Data as JSON: /api/errors/374d0e4a891040bb. Report an issue: GitHub.