{"record":{"id":"022587e2ae680db5","repo":"vitessio/vitess","slug":"invalid-keyspace-id-v","errorCode":null,"errorMessage":"invalid keyspace id: %v","messagePattern":"invalid keyspace id: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/vtgate/vindexes/reverse_bits.go","lineNumber":137,"sourceCode":"\tif err != nil {\n\t\treturn nil, err\n\t}\n\treturn reverse(num), nil\n}\n\nfunc init() {\n\tRegister(\"reverse_bits\", newReverseBits)\n}\n\nfunc reverse(shardKey uint64) []byte {\n\treversed := make([]byte, 8)\n\tbinary.BigEndian.PutUint64(reversed, bits.Reverse64(shardKey))\n\treturn reversed\n}\n\nfunc unreverse(k []byte) (uint64, error) {\n\tif len(k) != 8 {\n\t\treturn 0, fmt.Errorf(\"invalid keyspace id: %v\", hex.EncodeToString(k))\n\t}\n\treturn bits.Reverse64(binary.BigEndian.Uint64(k)), nil\n}\n","sourceCodeStart":119,"sourceCodeEnd":141,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/vtgate/vindexes/reverse_bits.go#L119-L141","documentation":"ReverseBits.unreverse expects keyspace ids of exactly 8 bytes (bit-reversed uint64). A different length cannot be a valid ReverseBits keyspace id, so reversal fails with this hex-encoded diagnostic. It guards ReverseMap against ids produced by other vindexes or corrupt data.","triggerScenarios":"ReverseMap on a reverse_bits vindex receives a keyspace id whose length != 8 — e.g. ids from a binary_md5 (16-byte) vindex or truncated keys in a lookup table.","commonSituations":"Wrong vindex type in vschema after a migration; lookup tables populated by a different vindex; manual test fixtures with short/long ids.","solutions":["Ensure the vindex used for reversal is the same one that generated the keyspace ids (reverse_bits produces 8-byte ids).","Fix vschema if the table actually uses binary/unicode vindexes.","Rebuild lookup data containing truncated or foreign keyspace ids."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if len(ksid) != 8 {\n    return fmt.Errorf(\"expected 8-byte reverse_bits keyspace id, got %d bytes\", len(ksid))\n}","typeGuard":"func isReverseBitsKeyspaceID(k []byte) bool { return len(k) == 8 }","tryCatchPattern":null,"preventionTips":["Confirm the generating vindex before calling ReverseMap.","Do not truncate keyspace ids when storing them in lookup tables.","Keep vschema vindex types aligned with data written historically."],"tags":["vindex","reverse-bits","keyspace-id","reverse-map"],"backgroundTag":"invalid-keyspace-id","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}