{"record":{"id":"a8b837bc8d352f01","repo":"apache/cassandra","slug":"corrupt-clustering-value-length-d-encountered-as","errorCode":null,"errorMessage":"Corrupt clustering value length %d encountered, as it exceeds the maximum of %d, which is set via max_value_size in cassandra.yaml","messagePattern":"Corrupt clustering value length (.+?) encountered, as it exceeds the maximum of (.+?), which is set via max_value_size in cassandra\\.yaml","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/io/sstable/SSTableCursorReader.java","lineNumber":1107,"sourceCode":"        clustering.loadPart(dataReader, varLength);\n        return 0;\n    }\n\n    /**\n     * Rejects a clustering value length the wire cannot have produced honestly. Both checks mirror\n     * AbstractType.read, the reference for this format. readUnsignedVInt32 can return a negative\n     * int, which is why the first check exists: an unchecked negative length reaches\n     * {@link java.io.DataInput#skipBytes} as a silent no-op, and a buffer sizer as a defect.\n     *\n     * <p>Every caller of this walk wraps it and reports a {@code CorruptSSTableException}.\n     */\n    @VisibleForTesting\n    static void validateClusteringValueLength(int length) throws IOException\n    {\n        if (length < 0)\n            throw new IOException(\"Corrupt (negative) clustering value length encountered: \" + length);\n        if (length > DatabaseDescriptor.getMaxValueSize())\n            throw new IOException(String.format(\"Corrupt clustering value length %d encountered, as it exceeds the maximum of %d, \" +\n                                                \"which is set via max_value_size in cassandra.yaml\",\n                                                length, DatabaseDescriptor.getMaxValueSize()));\n    }\n\n    private static void skipClustering(RandomAccessReader dataReader, AbstractType<?>[] types, int clusteringColumnsBound) throws IOException\n    {\n        long clusteringBlockHeader = 0;\n        for (int clusteringIndex = 0; clusteringIndex < clusteringColumnsBound; clusteringIndex++)\n        {\n            // struct clustering_block {\n            //    varint clustering_block_header;\n            //    simple_cell[] clustering_cells;\n            // };\n            if (clusteringIndex % 32 == 0)\n            {\n                clusteringBlockHeader = dataReader.readUnsignedVInt();\n            }\n            // skip value if present","sourceCodeStart":1089,"sourceCodeEnd":1125,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/io/sstable/SSTableCursorReader.java#L1089-L1125","documentation":"validateClusteringValueLength rejects clustering value lengths exceeding DatabaseDescriptor.getMaxValueSize() (max_value_size in cassandra.yaml). A larger length cannot be legitimate, so the data is treated as corrupt and an IOException with the configured maximum in the message is thrown.","triggerScenarios":"Deserializing a clustering value whose on-disk length prefix exceeds max_value_size — corrupt bytes, or a value written under a larger max_value_size now read under a smaller one.","commonSituations":"Corrupted sstable files; nodes with inconsistent max_value_size settings; bit corruption flipping length bytes; config changed after data was written.","solutions":["Check for corruption first: nodetool verify / sstableverify, then scrub if confirmed.","Align max_value_size across all nodes' cassandra.yaml and rewrite affected sstables (scrub/compact).","Restore the sstable from backup and run nodetool repair if corruption is confirmed.","Temporarily raise max_value_size if legitimate large values were written under a larger limit."],"exampleFix":"// before\nint len = in.readInt();\nreadClusteringValue(in, buf, type, len);\n// after\nint len = in.readInt();\nvalidateClusteringValueLength(len); // enforces max_value_size before use\nreadClusteringValue(in, buf, type, len);","handlingStrategy":"validation","validationCode":"int max = DatabaseDescriptor.getMaxValueSize();\nif (length < 0 || length > max)\n    throw new IOException(\"invalid clustering length \" + length + \" (max \" + max + \")\");","typeGuard":null,"tryCatchPattern":"try {\n    validateClusteringValueLength(len);\n} catch (IOException e) {\n    throw new CorruptSSTableException(e, filename); // or align max_value_size if config-related\n}","preventionTips":["Keep max_value_size identical on all nodes in cassandra.yaml.","Document config changes that affect previously written data.","Verify sstables when this error appears after config changes.","Scrub rather than retrying reads on the same corrupt bytes."],"tags":["sstable","corruption","config","deserialization"],"backgroundTag":"file-size-limit-exceeded","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"}