{"record":{"id":"c3b8359b355400ef","repo":"apache/cassandra","slug":"error-seeking-to-index-offset-for-ordinal-d-with","errorCode":null,"errorMessage":"Error seeking to index offset for ordinal %d with ordToRowOffset %d","messagePattern":"Error seeking to index offset for ordinal (.+?) with ordToRowOffset (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"critical","filePath":"src/java/org/apache/cassandra/index/sai/disk/v1/vector/OnDiskOrdinalsMap.java","lineNumber":94,"sourceCode":"        return BitsUtil.bitsIgnoringDeleted(acceptBits, deletedOrdinals);\n    }\n\n    public class RowIdsView implements AutoCloseable\n    {\n        final RandomAccessReader reader = fh.createReader();\n\n        public int[] getSegmentRowIdsMatching(int vectorOrdinal) throws IOException\n        {\n            Preconditions.checkArgument(vectorOrdinal < size, \"vectorOrdinal %s is out of bounds %s\", vectorOrdinal, size);\n\n            // read index entry\n            try\n            {\n                reader.seek(ordToRowOffset + 4L + vectorOrdinal * 8L);\n            }\n            catch (Exception e)\n            {\n                throw new RuntimeException(String.format(\"Error seeking to index offset for ordinal %d with ordToRowOffset %d\",\n                                                         vectorOrdinal, ordToRowOffset), e);\n            }\n            long offset = reader.readLong();\n            // seek to and read rowIds\n            try\n            {\n                reader.seek(offset);\n            }\n            catch (Exception e)\n            {\n                throw new RuntimeException(String.format(\"Error seeking to rowIds offset for ordinal %d with ordToRowOffset %d\",\n                                                         vectorOrdinal, ordToRowOffset), e);\n            }\n            int postingsSize = reader.readInt();\n            int[] rowIds = new int[postingsSize];\n            for (int i = 0; i < rowIds.length; i++)\n            {\n                rowIds[i] = reader.readInt();","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/index/sai/disk/v1/vector/OnDiskOrdinalsMap.java#L76-L112","documentation":"RuntimeException thrown when FileHandle/DataInput seek fails while positioning the reader at the index offset for a vector ordinal during getSegmentRowIdsMatching. The computed offset is ordToRowOffset + 4 + vectorOrdinal*8; a seek failure there indicates the ordinal map data is shorter or corrupt relative to the metadata offsets.","triggerScenarios":"Querying a vector segment where ordToRowOffset or the ordinal points beyond the mapped region, the file is truncated, or the map was initialized against mismatched segment bounds.","commonSituations":"Truncated/corrupt vector index files, version mismatch between writer and reader layouts, ordinals requested that exceed the segment's vector count, or mismatched component files after manual file moves.","solutions":["REBUILD the vector index to regenerate a consistent ordinal map file","Validate that the queried ordinal is within the segment's vector count before lookup","Ensure component files come from the same segment generation; restore a matching set from backup","Check the chained cause to distinguish mmap/IO failures from offset computation bugs"],"exampleFix":"// guard before lookup\nif (vectorOrdinal < 0 || vectorOrdinal >= vectorCount)\n    throw new IllegalArgumentException(\"ordinal out of range: \" + vectorOrdinal);\nrowIds = ordinalsMap.getSegmentRowIdsMatching(vectorOrdinal);","handlingStrategy":"try-catch","validationCode":"if (vectorOrdinal < 0 || vectorOrdinal >= vectorCount)\n    throw new IllegalArgumentException(\"ordinal out of range for segment: \" + vectorOrdinal);","typeGuard":"boolean ordinalInSegment(int ordinal, int vectorCount) {\n    return ordinal >= 0 && ordinal < vectorCount;\n}","tryCatchPattern":"try {\n    rowIds = ordinalsMap.getSegmentRowIdsMatching(ordinal);\n} catch (RuntimeException e) {\n    logger.error(\"Ordinal lookup failed: {}\", e.getMessage(), e);\n    return emptyRowIds(); // or mark segment unhealthy\n}","preventionTips":["Clamp/check ordinals against the segment's vector count before lookup","Rebuild indexes when files may be truncated","Keep reader and writer SAI format versions in sync"],"tags":["cassandra","sai","vector-index","io"],"backgroundTag":"file-read-failed","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}