vitessio/vitess · error

could not map %v to a keyspace id, got destination %v

Error message

could not map %v to a keyspace id, got destination %v

What it means

The vindex Map returned exactly one destination, but it is not a concrete DestinationKeyspaceID (or is an empty keyspace ID) — e.g. DestinationAllShards, DestinationNone, or a range — so a binary keyspace id cannot be derived.

Source

Thrown at go/vt/binlog/keyspace_id_resolver.go:114

	}, nil
}

// keyspaceIDResolverFactoryV3 uses the Vindex to compute the value.
type keyspaceIDResolverFactoryV3 struct {
	vindex vindexes.SingleColumn
}

func (r *keyspaceIDResolverFactoryV3) keyspaceID(v sqltypes.Value) ([]byte, error) {
	destinations, err := r.vindex.Map(context.TODO(), nil, []sqltypes.Value{v})
	if err != nil {
		return nil, err
	}
	if len(destinations) != 1 {
		return nil, fmt.Errorf("mapping row to keyspace id returned an invalid array of destinations: %v", key.DestinationsString(destinations))
	}
	ksid, ok := destinations[0].(key.DestinationKeyspaceID)
	if !ok || len(ksid) == 0 {
		return nil, fmt.Errorf("could not map %v to a keyspace id, got destination %v", v, destinations[0])
	}
	return ksid, nil
}

View on GitHub (pinned to 01a25a7d17)

Solutions

  1. Inspect the value %v printed in the error; fix the offending row's sharding key data.
  2. Repair/repopulate the lookup vindex table if entries are missing.
  3. Use a functional unique vindex (e.g. hash) that always yields a concrete keyspace id.

Example fix

// before: NULL sharding key in row
INSERT INTO t (uid, msg) VALUES (NULL, 'x');
// after
INSERT INTO t (uid, msg) VALUES (12345, 'x');
Defensive patterns

Strategy: type-guard

Validate before calling

dests, err := vindex.Map(ctx, env, []sqltypes.Value{val})
if err != nil { return err }
if _, ok := dests[0].(key.DestinationKeyspaceID); !ok || len(dests) != 1 {
	return fmt.Errorf("value %v does not resolve to a concrete keyspace id", val)
}

Type guard

func toKeyspaceID(d key.Destination) (key.DestinationKeyspaceID, bool) {
	ksid, ok := d.(key.DestinationKeyspaceID)
	if !ok || len(ksid) == 0 { return nil, false }
	return ksid, true
}

Try / catch

if err := streamKeyRange(ctx, kr); err != nil {
	if strings.Contains(err.Error(), "could not map") {
		// inspect the printed value; fix row data or lookup vindex
	}
	return err
}

Prevention

When it happens

Trigger: keyspaceID(v) sees destinations[0] not type-assertable to key.DestinationKeyspaceID, or len(ksid)==0 — typically DestinationNone/AllShards from the vindex for the given value.

Common situations: Sharding key value absent from a lookup vindex; NULL or malformed sharding key; vindex returning symbolic destinations for unknown values.

Related errors


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