vitessio/vitess · error

no primary tablet in shard %s/%s

Error message

no primary tablet in shard %s/%s

What it means

Returned when the first shard of the source keyspace (used as the reference for permission copying) has no primary tablet — its shard record lacks a PrimaryAlias. The permission-copy flow needs a reference primary to read permissions from.

Source

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

		// Validate all of the shards.
		shards, err = s.ts.GetShardNames(ctx, req.Keyspace)
		if err != nil {
			return nil, err
		}
	}

	if len(shards) == 0 {
		return nil, fmt.Errorf("no shards found in keyspace %s", req.Keyspace)
	}
	sort.Strings(shards)

	// Find the reference permissions using the first shard's primary.
	si, err := s.ts.GetShard(ctx, req.Keyspace, shards[0])
	if err != nil {
		return nil, err
	}
	if !si.HasPrimary() {
		return nil, fmt.Errorf("no primary tablet in shard %s/%s", req.Keyspace, shards[0])
	}
	referenceAlias := si.PrimaryAlias
	log.Info("Gathering permissions for reference primary " + topoproto.TabletAliasString(referenceAlias))
	pres, err := s.GetPermissions(ctx, &vtctldatapb.GetPermissionsRequest{
		TabletAlias: si.PrimaryAlias,
	})
	if err != nil {
		return nil, err
	}
	referencePermissions := pres.Permissions

	// Then diff the first/reference tablet with all the others.
	eg, egctx := errgroup.WithContext(ctx)
	for _, shard := range shards {
		eg.Go(func() error {
			aliases, err := s.ts.FindAllTabletAliasesInShard(egctx, req.Keyspace, shard)
			if err != nil {
				return err

View on GitHub (pinned to 01a25a7d17)

Solutions

  1. Restore a primary with `vtctldclient PlannedReparentShard <keyspace/shard>`
  2. Verify with `vtctldclient GetShard <keyspace/shard>` that primary_alias is set
  3. Re-run the permissions copy after the shard has a healthy primary
  4. Pick a shard known to have a primary instead of relying on shards[0]

Example fix

// before
if !si.HasPrimary() {
    return nil, fmt.Errorf("no primary tablet in shard %s/%s", req.Keyspace, shards[0])
}
// after
if !si.HasPrimary() {
    return nil, vterrors.Errorf(vtrpcpb.Code_FAILED_PRECONDITION, "no primary tablet in shard %s/%s; run PlannedReparentShard first", req.Keyspace, shards[0])
}
Defensive patterns

Strategy: validation

Validate before calling

shard, _ := topoServer.GetShard(ctx, keyspace, shardName)
if shard.PrimaryAlias == nil { /* no primary; run reparent first */ }

Try / catch

try {
  await client.copyPermissions(sourceKeyspace, shard)
} catch (e) {
  if (String(e).includes('no primary tablet in shard')) {
    await client.plannedReparentShard(sourceKeyspace, shard)
    await retryCopy()
  } else { throw e }
}

Prevention

When it happens

Trigger: Copy-permissions style RPC where shards[0].HasPrimary() is false — the shard has no elected/recorded primary, typically after a failed reparent or before initial tablet promotion.

Common situations: Shard initialized but never promoted to primary; reparent failed leaving PrimaryAlias empty; running the copy during a topology repair window.

Related errors


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