vitessio/vitess · error

primary-elect tablet %v is not the only primary in the shard

Error message

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

What it means

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.

Source

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

		}

		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 {
			return fmt.Errorf("primary-elect tablet %v is not the only primary in the shard, use -force to proceed anyway", topoproto.TabletAliasString(req.PrimaryElectTabletAlias))
		}
		logger.Warningf("primary-elect tablet %v is not the only primary in the shard, proceeding anyway as -force was used", topoproto.TabletAliasString(req.PrimaryElectTabletAlias))
	}

	// First phase: reset replication on all tablets. If anyone fails,
	// we stop. It is probably because it is unreachable, and may leave
	// an unstable database process in the mix, with a database daemon
	// at a wrong replication spot.

	// Create a context for the following RPCs that respects waitReplicasTimeout
	resetCtx, resetCancel := context.WithTimeout(ctx, waitReplicasTimeout)
	defer resetCancel()

	event.DispatchUpdate(ev, "resetting replication on all tablets")
	wg := sync.WaitGroup{}
	rec := concurrency.AllErrorRecorder{}
	for alias, tabletInfo := range tabletMap {
		wg.Add(1)

View on GitHub (pinned to 01a25a7d17)

Solutions

  1. Inspect the shard (`vtctldclient GetShard`, `GetTablets`) to find the extra primary tablet.
  2. Repair the shard state first — e.g. run EmergencyReparentShard or manually fix the stale primary's type — then retry PRS.
  3. Use --force only if you accept the risk of demoting/proceeding with multiple primaries and understand the replication state.

Example fix

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

Strategy: validation

Validate before calling

_, primaryMap := topotools.SortedTabletMap(tabletMap)
alias := topoproto.TabletAliasString(req.PrimaryElectTabletAlias)
for a := range primaryMap {
    if a != alias {
        return fmt.Errorf("extra primary %s present; repair shard first", a)
    }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


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