vitessio/vitess · error · ErrNoSrvVSchema

%w: keyspace %s

Error message

%w: keyspace %s

What it means

The GetSrvVSchema RPC succeeded, but the returned SrvVSchema contained no entry for the requested keyspace. VTAdmin records errors.ErrNoSrvVSchema wrapped with the keyspace name. This means the keyspace has no deployed (served) vschema in that cell, so vtexplain cannot compute routing for it.

Source

Thrown at go/vt/vtadmin/api.go:2765

		defer wg.Done()

		span, ctx := trace.NewSpan(ctx, "Cluster.GetSrvVSchema")
		defer span.Finish()

		span.Annotate("cell", tablet.Tablet.Alias.Cell)
		cluster.AnnotateSpan(c, span)

		res, err := c.Vtctld.GetSrvVSchema(ctx, &vtctldatapb.GetSrvVSchemaRequest{
			Cell: tablet.Tablet.Alias.Cell,
		})
		if err != nil {
			er.RecordError(fmt.Errorf("GetSrvVSchema(%s): %w", tablet.Tablet.Alias.Cell, err))
			return
		}

		ksvs, ok := res.SrvVSchema.Keyspaces[req.Keyspace]
		if !ok {
			er.RecordError(fmt.Errorf("%w: keyspace %s", errors.ErrNoSrvVSchema, req.Keyspace))
			return
		}

		ksvsb, err := json.Marshal(&ksvs)
		if err != nil {
			er.RecordError(err)
			return
		}

		srvVSchema = fmt.Sprintf(`{"%s": %s}`, req.Keyspace, string(ksvsb))
	}(c)

	// FindAllShardsInKeyspace
	go func(c *cluster.Cluster) {
		defer wg.Done()

		shards, err := c.FindAllShardsInKeyspace(ctx, req.Keyspace, cluster.FindAllShardsInKeyspaceOptions{})
		if err != nil {

View on GitHub (pinned to 01a25a7d17)

Solutions

  1. Verify the keyspace name is spelled correctly in the request.
  2. Run `vtctldclient RebuildKeyspaceGraph <keyspace>` (or rebuild the cell's srv vschema) so the keyspace appears in the SrvVSchema.
  3. Deploy a vschema for the keyspace (`vtctldclient ApplyVSchema`) if it's a VReplication/VTGate-managed keyspace.
  4. Check with `vtctldclient GetSrvVSchema --cell <cell>` whether the keyspace is present; if stale, rebuild the topo entry.
  5. Confirm the tablet's cell actually serves this keyspace (SrvKeyspace exists for that cell).

Example fix

// before: keyspace missing from srv vschema
// after:
vtctldclient ApplyVSchema --keyspace commerce --vschema '{"tables": {}}'
vtctldclient RebuildKeyspaceGraph --cells zone1 commerce
Defensive patterns

Strategy: validation

Validate before calling

res, err := vtctldClient.GetSrvVSchema(ctx, &vtctldatapb.GetSrvVSchemaRequest{Cell: cell})
if err != nil { return err }
if _, ok := res.SrvVSchema.Keyspaces[keyspace]; !ok {
    return fmt.Errorf("keyspace %s not in cell %s srv vschema; rebuild keyspace graph first", keyspace, cell)
}

Type guard

func keyspaceInSrvVSchema(svs *vtctldatapb.SrvVSchema, ks string) bool {
    if svs == nil { return false }
    _, ok := svs.Keyspaces[ks]
    return ok
}

Try / catch

if _, ok := res.SrvVSchema.Keyspaces[req.Keyspace]; !ok {
    return vterrors.Errorf(vtrpcpb.Code_FAILED_PRECONDITION, "keyspace %s has no srv vschema in cell %s; run RebuildKeyspaceGraph", req.Keyspace, cell)
}

Prevention

When it happens

Trigger: req.Keyspace is absent from res.SrvVSchema.Keyspaces for the tablet's cell — the keyspace was never built/rebuilt into the cell's srv vschema, or the request used a wrong keyspace name.

Common situations: Typo in keyspace name in the request; a brand-new keyspace where `RebuildKeyspaceGraph` hasn't run; unmanaged keyspace without a vschema; stale srv vschema after keyspace deletion.

Related errors


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