{"record":{"id":"964fa056fc50cf8c","repo":"apache/cassandra","slug":"digest-mismatch-exception","errorCode":null,"errorMessage":"Digest mismatch exception","messagePattern":"Digest mismatch exception","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/hints/ChecksummedDataInput.java","lineNumber":166,"sourceCode":"    /**\n     * Returns the position in the source file, which is different for getPosition() for compressed/encrypted files\n     * and may be imprecise.\n     */\n    protected long getSourcePosition()\n    {\n        return bufferOffset;\n    }\n\n    public void resetLimit()\n    {\n        limit = Long.MAX_VALUE;\n        limitMark = -1;\n    }\n\n    public void checkLimit(int length) throws IOException\n    {\n        if (getPosition() + length > limit)\n            throw new IOException(\"Digest mismatch exception\");\n    }\n\n    public long bytesPastLimit()\n    {\n        assert limitMark != -1;\n        return getPosition() - limitMark;\n    }\n\n    public boolean checkCrc() throws IOException\n    {\n        try\n        {\n            updateCrc();\n\n            // we must disable crc updates in case we rebuffer\n            // when called source.readInt()\n            crcUpdateDisabled = true;\n            return ((int) crc.getValue()) == readInt();","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/hints/ChecksummedDataInput.java#L148-L184","documentation":"ChecksummedDataInput.checkLimit() throws IOException(\"Digest mismatch exception\") when a requested read of `length` bytes would move the input position past the limit recorded by the current framing (the CRC-protected block set by resetLimit/synchronized reading in hints). Callers such as readFully/read use it to enforce that deserialization stays inside the verified block; exceeding the limit means the encoded length was wrong or the data is corrupt.","triggerScenarios":"Reading a hints file where a stored hint size or field length exceeds the remaining CRC-checked block: corrupt/truncated file, torn write from hard reboot, or a descriptor/parameters mismatch causing misaligned reads. Raised from readFully/read when their length argument overruns `limit`.","commonSituations":"Hints files damaged by unclean shutdown (power loss without fsync); copying hints files between nodes or versions; disk corruption; manually editing or truncating hints directories; reading hints written with different compression/encryption parameters than configured.","solutions":["Delete or move the corrupt hints file(s) out of the hints directory and let the node continue; hints are best-effort deliveries.","Check disks/filesystem for corruption (fsck, SMART) if many hints files are affected.","Verify compression/encryption config for hints matches what was used when the files were written (hints_compression in cassandra.yaml).","Restore affected hints files from a clean backup or let peers' hinted handoff data be re-gedged via repair."],"exampleFix":"// before\ninput.readFully(buffer, size); // IOException: Digest mismatch exception\n// after\ntry\n{\n    input.readFully(buffer, size);\n}\ncatch (IOException e)\n{\n    logger.warn(\"Corrupt hint block, skipping file\", e);\n    // abandon current hints file / resync to next descriptor\n}","handlingStrategy":"try-catch","validationCode":"// before reading, sanity-check the hints file exists and is non-empty\nif (!Files.isRegularFile(hintsFile) || Files.size(hintsFile) == 0) skipFile(hintsFile);","typeGuard":null,"tryCatchPattern":"try { input.readFully(buf, len); } catch (IOException e) { if (e.getMessage().contains(\"Digest mismatch\")) { abandonCurrentFile(); } else throw e; }","preventionTips":["Shut nodes down cleanly (drain) rather than hard-killing to avoid torn hint writes.","Keep hints compression/encryption config stable; changing it strands unreadable files.","Monitor hints directory for corrupt files and alert on repeated IOExceptions.","Run regular repairs so dropped hints are covered by anti-entropy."],"tags":["java","io","corruption","hints"],"backgroundTag":"checksum-mismatch","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}