{"record":{"id":"46e4c6b1dcea5000","repo":"apache/cassandra","slug":"the-requested-position-exceeds-the-index-length","errorCode":null,"errorMessage":"The requested position exceeds the index length","messagePattern":"The requested position exceeds the index length","errorType":"validation","errorClass":"IndexOutOfBoundsException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/io/sstable/SSTableCursorKeyReader.java","lineNumber":138,"sourceCode":"        }\n        entry.load(indexFileReader);\n        return true;\n    }\n\n    public boolean isExhausted()\n    {\n        return indexFileReader.isEOF();\n    }\n\n    public long indexPosition()\n    {\n        return indexFileReader.getFilePointer();\n    }\n\n    public void seek(long position) throws IOException\n    {\n        if (position > indexLength())\n            throw new IndexOutOfBoundsException(\"The requested position exceeds the index length\");\n        indexFileReader.seek(position);\n    }\n\n    public long indexLength()\n    {\n        return indexFileReader.length();\n    }\n\n    public void reset() throws IOException\n    {\n        indexFileReader.seek(initialPosition);\n    }\n\n    @Override\n    public String toString()\n    {\n        return String.format(\"BigTable-SSTableCursorKeyReader(%s), indexPosition=%d\", indexFile.path(), indexFileReader.getFilePointer());\n    }","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/io/sstable/SSTableCursorKeyReader.java#L120-L156","documentation":"SSTableCursorKeyReader.seek() validates that the requested offset lies within the on-disk primary index. Seeking past indexLength() would read outside the index file, so an IndexOutOfBoundsException is thrown instead.","triggerScenarios":"Calling seek(position) where position > indexFileReader.length() — typically an offset computed from a corrupted index summary or stale key-cache entry exceeding the actual index file size.","commonSituations":"Corrupt or truncated -Index.db files; stale key cache entries after an sstable was replaced/truncated; interrupted writes leaving a short index file; buggy offset computation.","solutions":["Clear the key cache (nodetool invalidatekeycache or restart) to drop stale offsets.","Verify the sstable with sstableverify / nodetool verify; scrub or rebuild if the index is truncated.","Restore the -Index.db file from backup if truncated.","In custom code, clamp/validate the offset against indexLength() before calling seek."],"exampleFix":"// before\nreader.seek(position);\n// after\nif (position >= 0 && position <= reader.indexLength()) {\n    reader.seek(position);\n} else {\n    // recompute offset from index summary before retrying\n}","handlingStrategy":"validation","validationCode":"if (position < 0 || position > keyReader.indexLength())\n    throw new IllegalArgumentException(\"offset \" + position + \" outside index length \" + keyReader.indexLength());","typeGuard":null,"tryCatchPattern":"try {\n    keyReader.seek(position);\n} catch (IndexOutOfBoundsException e) {\n    // invalidate cached offset (key cache) and recompute from index summary\n}","preventionTips":["Invalidate key cache entries when sstables are replaced or truncated.","Verify -Index.db integrity with sstableverify.","Never persist raw file offsets across sstable rewrites.","Clamp computed offsets to indexLength() before seeking."],"tags":["io","sstable","index","bounds"],"backgroundTag":"index-out-of-bounds","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}