vitessio/vitess · error

unable to get shards for keyspace: %s, error: %v

Error message

unable to get shards for keyspace: %s, error: %v

What it means

TabletExecutor.Open discovers all shards in the target keyspace via the topo server (FindAllShardsInKeyspace) to locate primaries. If the topology lookup fails, this error wraps the underlying topo error, naming the keyspace. The executor cannot proceed without the shard map.

Source

Thrown at go/vt/schemamanager/tablet_executor.go:118

	}
	exec.uuids = uuids
	return nil
}

// hasProvidedUUIDs returns true when UUIDs were provided
func (exec *TabletExecutor) hasProvidedUUIDs() bool {
	return len(exec.uuids) != 0
}

// Open opens a connection to the primary for every shard.
func (exec *TabletExecutor) Open(ctx context.Context, keyspace string) error {
	if !exec.isClosed {
		return nil
	}
	exec.keyspace = keyspace
	shards, err := exec.ts.FindAllShardsInKeyspace(ctx, keyspace, nil)
	if err != nil {
		return fmt.Errorf("unable to get shards for keyspace: %s, error: %v", keyspace, err)
	}
	exec.tablets = make([]*topodatapb.Tablet, 0, len(shards))
	for shardName, shardInfo := range shards {
		if !shardInfo.HasPrimary() {
			return fmt.Errorf("shard: %s does not have a primary", shardName)
		}
		tabletInfo, err := exec.ts.GetTablet(ctx, shardInfo.PrimaryAlias)
		if err != nil {
			return fmt.Errorf("unable to get primary tablet info, keyspace: %s, shard: %s, error: %v", keyspace, shardName, err)
		}
		exec.tablets = append(exec.tablets, tabletInfo.Tablet)
	}

	if len(exec.tablets) == 0 {
		return fmt.Errorf("keyspace: %s does not contain any primary tablets", keyspace)
	}
	exec.isClosed = false
	return nil

View on GitHub (pinned to 01a25a7d17)

Solutions

  1. Check the wrapped error for the topo root cause (not-found vs connection error)
  2. Verify the keyspace exists (vtctldclient GetKeyspaces) and is spelled correctly
  3. Confirm topo server connectivity/flags (etcd/zk endpoints) and retry once the topo is healthy

Example fix

// before: keyspace typo
exec.Open(ctx, "commerc")
// after
exec.Open(ctx, "commerce")
Defensive patterns

Strategy: try-catch

Validate before calling

_, err := ts.FindAllShardsInKeyspace(ctx, keyspace, nil)
if err != nil { return fmt.Errorf("keyspace %q not ready: %w", keyspace, err) }

Try / catch

err := exec.Open(ctx, keyspace)
if err != nil {
  if strings.Contains(err.Error(), "unable to get shards for keyspace") {
    // check topo health / keyspace existence, then retry with backoff
  }
}

Prevention

When it happens

Trigger: Calling Open when FindAllShardsInKeyspace fails: topo server unreachable, keyspace does not exist, or permission/timeout errors from the topo store.

Common situations: Typo in keyspace name; vtctld/vttablet environment with wrong topo flags; etcd/zk outage or network partition; keyspace deleted while a schema change was queued.

Related errors


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