vitessio/vitess · error

no shards found in keyspace %s

Error message

no shards found in keyspace %s

What it means

Returned by CopyShardPermissions/CopySchemaShard-style flows when the source keyspace contains no shards. The operation needs at least one shard from which to pick a reference primary tablet, so it fails early.

Source

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

	defer panicHandler(&err)

	span.Annotate("keyspace", req.Keyspace)
	span.Annotate("shards", req.Shards)

	var shards []string
	if len(req.Shards) != 0 {
		// If the user has specified a list of specific shards, we'll use that.
		shards = req.Shards
	} else {
		// 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

View on GitHub (pinned to 01a25a7d17)

Solutions

  1. Verify the keyspace name is spelled correctly
  2. Ensure the source keyspace has shards/tablets (`vtctldclient GetSrvKeyspace` or `GetKeyspace`)
  3. Initialize the keyspace with tablets before copying permissions/schema
  4. Re-run the copy after resharding cleanup has restored shards, or copy from the original keyspace

Example fix

// before
if len(shards) == 0 {
    return nil, fmt.Errorf("no shards found in keyspace %s", req.Keyspace)
}
// after
if len(shards) == 0 {
    return nil, vterrors.Errorf(vtrpcpb.Code_FAILED_PRECONDITION, "no shards found in keyspace %s; ensure the keyspace has tablets before copying", req.Keyspace)
}
Defensive patterns

Strategy: validation

Validate before calling

srvKeyspace, err := topoServer.GetSrvKeyspace(ctx, cell, keyspace)
if err != nil || len(srvKeyspace.Partitions) == 0 { /* keyspace empty; abort */ }

Try / catch

try {
  await client.copySchemaShard(sourceKeyspace, shard)
} catch (e) {
  if (String(e).includes('no shards found in keyspace')) {
    // check spelling / initialize tablets in source keyspace
  } else { throw e }
}

Prevention

When it happens

Trigger: Calling the copy-permissions/copy-schema-shard vtctld RPC against a keyspace whose shard list is empty — e.g. a freshly created keyspace with no tablets yet, or a typo'd keyspace name.

Common situations: Typo in the keyspace name resolving to an empty/fresh keyspace; running the copy before the source keyspace has been initialized with tablets; source shards were all removed after resharding completed.

Related errors


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