{"record":{"id":"ddee0c25eaac92ca","repo":"apache/cassandra","slug":"corrupted-index-file-s-read-d-but-expected-d-c","errorCode":null,"errorMessage":"Corrupted Index File %s: read %d but expected %d chunks.","messagePattern":"Corrupted Index File (.+?): read (.+?) but expected (.+?) chunks\\.","errorType":"exception","errorClass":"CorruptSSTableException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/io/compress/CompressionMetadata.java","lineNumber":317,"sourceCode":"        {\n\n            for (i = 0; i < chunkCount; i++)\n            {\n                offsets.setLong(i * 8L, input.readLong());\n            }\n\n            return offsets;\n        }\n        catch (IOException e)\n        {\n            if (offsets != null)\n                offsets.close();\n\n            if (e instanceof EOFException)\n            {\n                String msg = String.format(\"Corrupted Index File %s: read %d but expected %d chunks.\",\n                                           input.file.path(), i, chunkCount);\n                throw new CorruptSSTableException(new IOException(msg, e), input.file);\n            }\n            throw new FSReadError(e, input.file);\n        }\n    }\n\n    /**\n     * Get a chunk of compressed data (offset, length) corresponding to given position\n     *\n     * @param position Position in the file.\n     * @return pair of chunk offset and length.\n     */\n    public Chunk chunkFor(long position)\n    {\n        // position of the chunk\n        long idx = 8 * (position / parameters.chunkLength());\n\n        if (idx >= chunkOffsetsSize)\n            throw new CorruptSSTableException(new EOFException(), chunksIndexFile);","sourceCodeStart":299,"sourceCodeEnd":335,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/io/compress/CompressionMetadata.java#L299-L335","documentation":"readChunkOffsets() reads the chunk offset array from the compression index file. If it hits EOF before reading all expected chunkCount offsets, the index file is inconsistent with its own header, so it throws CorruptSSTableException reporting how many chunks were read vs expected. Non-EOF I/O errors become FSReadError.","triggerScenarios":"Opening a compressed SSTable whose -CompressionInfo.db is shorter than expected: partial write during flush, truncated copy, or corruption. open() → readChunkOffsets hits EOFException mid-array.","commonSituations":"Crash while the compression metadata was being written; rsync/scp of an active SSTable without freezing; disk corruption; manually deleting/truncating metadata files.","solutions":["Run nodetool scrub (with --skip-corrupted if needed) to repair or quarantine the SSTable","Restore the CompressionInfo.db from backup or re-stream the SSTable via nodetool repair","Regenerate compression metadata by rewriting the SSTable (upgrade-sstables/alter compression and full rewrite)","Investigate the copy/backup procedure — copy SSTables only after flush/snapshot (nodetool snapshot)"],"exampleFix":"// before\ncp /var/lib/cassandra/data/ks/t-*/xx-CompressionInfo.db /backup/  // while writers active\n// after\nnodetool snapshot ks -t pre_backup\ncp /var/lib/cassandra/data/ks/t-*/snapshots/pre_backup/* /backup/","handlingStrategy":"try-catch","validationCode":"// Confirm index file size matches expected chunk count before open\nlong expected = 8L * chunkCount;\nif (indexFile.length() - HEADER_SIZE < expected)\n    throw new IllegalStateException(\"Index too small: \" + indexFile);","typeGuard":null,"tryCatchPattern":"try { CompressionMetadata.open(file, len); }\ncatch (CorruptSSTableException e) { logger.error(\"Corrupt index {}\", file, e); scrubOrRestore(file); }","preventionTips":["Always copy SSTables via nodetool snapshot","Run scrub after crashes or unclean shutdowns","Enable checksums/backups for metadata files","Never manually truncate metadata files"],"tags":["sstable","corruption","compression-index","eof"],"backgroundTag":"checksum-mismatch","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"}