{"record":{"id":"3e6f18e262cab642","repo":"apache/cassandra","slug":"corruptblockexception","errorCode":null,"errorMessage":"CorruptBlockException","messagePattern":"CorruptBlockException","errorType":"exception","errorClass":"CorruptBlockException","httpStatus":null,"severity":"critical","filePath":"src/java/org/apache/cassandra/io/compress/CompressedSequentialWriter.java","lineNumber":339,"sourceCode":"        {\n            compressed.clear();\n            compressed.limit(chunkSize);\n            fchannel.position(chunkOffset);\n            fchannel.read(compressed);\n\n            try\n            {\n                // Repopulate buffer from compressed data\n                buffer.clear();\n                compressed.flip();\n                if (chunkSize < maxCompressedLength)\n                    compressor.uncompress(compressed, buffer);\n                else\n                    buffer.put(compressed);\n            }\n            catch (IOException e)\n            {\n                throw new CorruptBlockException(getPath(), chunkOffset, chunkSize, e);\n            }\n\n            CRC32 checksum = new CRC32();\n            compressed.rewind();\n            checksum.update(compressed);\n\n            crcCheckBuffer.clear();\n            fchannel.read(crcCheckBuffer);\n            crcCheckBuffer.flip();\n            if (crcCheckBuffer.getInt() != (int) checksum.getValue())\n                throw new CorruptBlockException(getPath(), chunkOffset, chunkSize);\n        }\n        catch (CorruptBlockException e)\n        {\n            throw new CorruptSSTableException(e, getPath());\n        }\n        catch (EOFException e)\n        {","sourceCodeStart":321,"sourceCodeEnd":357,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/io/compress/CompressedSequentialWriter.java#L321-L357","documentation":"During resetAndTruncate(), CompressedSequentialWriter re-reads and validates already-written chunks from disk before rewinding the file. If decompressing a chunk (compressor.uncompress) fails with an IOException, the writer throws CorruptBlockException identifying the file, chunk offset and size, indicating the on-disk data for that chunk cannot be decompressed.","triggerScenarios":"Truncating/rewinding a compressed SSTable writer (e.g. on a failed flush retry or sstable rewrite) when the chunk at the target offset is corrupt: partial write from a crash, bit rot, or a chunk written by a mismatched compressor class/params.","commonSituations":"Power loss or OS crash leaving partially written chunks; storage-level corruption; compression parameter changes on a table between write and truncate/replay.","solutions":["Identify the file from the exception; the chunk offset/size pinpoint the corrupt region","Run nodetool scrub (or sstablescrub) on the table to isolate/discard the corrupt chunk and rebuild readable data","Restore the affected SSTable from a backup or repair from replicas (nodetool repair)","Check disk health (smartctl/dmesg) to rule out ongoing hardware corruption"],"exampleFix":"// before\n// truncate after failed flush -> uncompress of on-disk chunk fails -> CorruptBlockException\n// after\nnodetool scrub ks tbl\nnodetool repair ks tbl","handlingStrategy":"try-catch","validationCode":"// Validate SSTable integrity proactively\nnodetool verify ks tbl\n# or: sstableverify ks tbl","typeGuard":null,"tryCatchPattern":"try {\n    writer.resetAndTruncate(truncateLength);\n} catch (CorruptSSTableException e) {\n    // discard the corrupt file; recover data via scrub/repair from replicas\n    filesRecovery.handleCorrupt(e.getPath());\n}","preventionTips":["Use UPS-backed power and journaling filesystems to avoid torn writes","Run regular nodetool verify/scrub to catch corruption early","Keep replication factor >= 3 so corrupt data can be repaired from replicas","Do not change table compression parameters without rewriting existing SSTables"],"tags":["corruption","compressed-writer","truncate","sstable"],"backgroundTag":"corrupt-block-detected","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"}