{"record":{"id":"36f1e713dc457ef7","repo":"vitessio/vitess","slug":"region-bytes-must-be-1-or-2-v","errorCode":null,"errorMessage":"region_bytes must be 1 or 2: %v","messagePattern":"region_bytes must be 1 or 2: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/vtgate/vindexes/region_json.go","lineNumber":89,"sourceCode":"\trmPath := m[regionJSONParamRegionMap]\n\trmap := make(map[string]uint64)\n\tdata, err := os.ReadFile(rmPath)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tlog.Info(\"Loaded Region map from: \" + rmPath)\n\terr = json.Unmarshal(data, &rmap)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\trb, err := strconv.Atoi(m[regionJSONParamRegionBytes])\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tswitch rb {\n\tcase 1, 2:\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"region_bytes must be 1 or 2: %v\", rb)\n\t}\n\n\treturn &RegionJSON{\n\t\tname:          name,\n\t\tregionMap:     rmap,\n\t\tregionBytes:   rb,\n\t\tunknownParams: FindUnknownParams(m, regionJSONParams),\n\t}, nil\n}\n\n// String returns the name of the vindex.\nfunc (rv *RegionJSON) String() string {\n\treturn rv.name\n}\n\n// Cost returns the cost of this index as 1.\nfunc (rv *RegionJSON) Cost() int {\n\treturn 1","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/vtgate/vindexes/region_json.go#L71-L107","documentation":"RegionJSON is configured via a vschema 'region_bytes' parameter that must be exactly 1 or 2, since the region is encoded in 1 or 2 bytes of the keyspace id. Any other value (0, 3, negative, wrong type) makes vindex creation fail with this error.","triggerScenarios":"Creating/loading a region_json vindex whose JSON parameters include region_bytes set to a value other than 1 or 2 (e.g. omitted-and-typed incorrectly, 0, or 8).","commonSituations":"Copy-pasted vschema config with region_bytes: 4; misunderstanding that region_bytes means total keyspace length instead of the region prefix width; typo feeding a string into the integer field.","solutions":["Set region_bytes to 1 or 2 in the vindex's JSON configuration.","Validate the vschema JSON before applying it (vtctldclient ApplyVSchema validates this).","Re-apply the corrected vschema."],"exampleFix":"// before\n{\"type\": \"region_json\", \"params\": {\"region_bytes\": \"4\"}}\n// after\n{\"type\": \"region_json\", \"params\": {\"region_bytes\": \"1\"}}","handlingStrategy":"validation","validationCode":"if rb != 1 && rb != 2 {\n    return fmt.Errorf(\"region_bytes must be 1 or 2, got %v\", rb)\n}","typeGuard":"func validRegionBytes(v any) bool {\n    rb, ok := v.(int)\n    return ok && (rb == 1 || rb == 2)\n}","tryCatchPattern":null,"preventionTips":["Validate vschema JSON before applying it.","Keep vindex parameter defaults documented for your team.","Add a config lint that checks region_bytes ∈ {1,2} for region_json vindexes."],"tags":["vindex","region-json","configuration","vschema"],"backgroundTag":"invalid-vindex-config","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}