{"record":{"id":"bbd3244f3923b2d3","repo":"apache/cassandra","slug":"corruptsstableexception","errorCode":null,"errorMessage":"CorruptSSTableException","messagePattern":"CorruptSSTableException","errorType":"exception","errorClass":"CorruptSSTableException","httpStatus":null,"severity":"critical","filePath":"src/java/org/apache/cassandra/io/compress/CompressedSequentialWriter.java","lineNumber":354,"sourceCode":"            }\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        {\n            throw new CorruptSSTableException(new CorruptBlockException(getPath(), chunkOffset, chunkSize), getPath());\n        }\n        catch (IOException e)\n        {\n            throw new FSReadError(e, getPath());\n        }\n\n        // Mark as dirty so we can guarantee the newly buffered bytes won't be lost on a rebuffer\n        buffer.position(realMark.validBufferBytes);\n\n        bufferOffset = truncateTarget - buffer.position();\n        chunkCount = realMark.nextChunkIndex - 1;\n\n        // truncate data and index file\n        truncate(chunkOffset, bufferOffset);","sourceCodeStart":336,"sourceCodeEnd":372,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/io/compress/CompressedSequentialWriter.java#L336-L372","documentation":"resetAndTruncate() catches CorruptBlockException (including an EOFException while reading the chunk, wrapped as a CorruptBlockException) and rethrows it as CorruptSSTableException for the file. This signals that the compressed SSTable being truncated/rewound is unreadable at the requested offset and the write session cannot safely continue.","triggerScenarios":"Truncation point falls in a chunk that is incomplete (EOF while reading chunk or CRC bytes) or fails validation, e.g. a crash mid-flush left a partial last chunk and the writer later attempts to reset and truncate through it.","commonSituations":"Recovery after unclean shutdown (power loss, OOM kill) leaving truncated compressed SSTables; compaction retries over partially written files; disks returning short reads.","solutions":["Let the standard failure handling move the broken SSTable aside; then run nodetool scrub to repair or discard it","Restore the file from a snapshot/backup or repair the range from replicas (nodetool repair)","Investigate the cause of the partial write (crash logs, dmesg for I/O errors) and ensure fsync/power-loss protections (UPS, write barriers)","After recovery, confirm table integrity with nodetool verify"],"exampleFix":"// before\n// unclean shutdown -> EOF reading chunk on truncate -> CorruptSSTableException\n// after\nnodetool scrub ks tbl\nnodetool verify ks tbl\nnodetool repair ks tbl","handlingStrategy":"fallback","validationCode":"nodetool verify ks tbl\n# confirm SSTables are complete and readable after any unclean shutdown","typeGuard":null,"tryCatchPattern":"try {\n    writer.resetAndTruncate(pos);\n} catch (CorruptSSTableException e) {\n    // fallback: abandon in-flight write; remove/rename the partial file and rebuild from replicas\n    recovery.discardAndRebuild(e.getPath());\n}","preventionTips":["Ensure clean shutdowns (nodetool drain before maintenance) to avoid partial last chunks","Keep RF >= 3 and run repairs so recovery from any single corrupt file is routine","Configure automated scrub/verify after crash recovery","Use ECC memory and stable storage to reduce mid-write corruption"],"tags":["corruption","sstable","compressed-writer","recovery"],"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"}