{"record":{"id":"9d2bdf7a7f3df02a","repo":"apache/cassandra","slug":"corrupted-file-integrity-check-digest-failed-fo","errorCode":null,"errorMessage":"Corrupted file: integrity check (digest) failed for %s: %d != %d","messagePattern":"Corrupted file: integrity check \\(digest\\) failed for (.+?): (.+?) != (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/io/util/DataIntegrityMetadata.java","lineNumber":115,"sourceCode":"        {\n            this.dataFile = dataFile;\n            this.digestFile = digestFile;\n            this.checksum = ChecksumType.CRC32.newInstance();\n        }\n\n        // Validate the entire file\n        public void validate() throws IOException\n        {\n            try (RandomAccessReader digestReader = RandomAccessReader.open(digestFile);\n                 RandomAccessReader dataReader = RandomAccessReader.open(dataFile);\n                 CheckedInputStream checkedInputStream = new CheckedInputStream(dataReader, checksum);)\n            {\n                long storedDigestValue = Long.parseLong(digestReader.readLine());\n                byte[] chunk = new byte[64 * 1024];\n                while (checkedInputStream.read(chunk) > 0) ;\n                long calculatedDigestValue = checkedInputStream.getChecksum().getValue();\n                if (storedDigestValue != calculatedDigestValue)\n                    throw new IOException(String.format(\"Corrupted file: integrity check (digest) failed for %s: %d != %d\", dataFile, storedDigestValue, calculatedDigestValue));\n            }\n        }\n    }\n}\n","sourceCodeStart":97,"sourceCodeEnd":120,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/io/util/DataIntegrityMetadata.java#L97-L120","documentation":"FileDigestValidator validates a whole file's rolling CRC digest (from a -Digest sidecar) by streaming the file through a CheckedInputStream and comparing the final value with the stored digest line. Mismatch throws this IOException, meaning the file changed or was corrupted since its digest was written.","triggerScenarios":"Calling validate() after fully reading a data file whose computed digest differs from the stored Long parsed from the digest file — full-file corruption, modifications after digest creation, or a digest file from a different generation of the file.","commonSituations":"Verifying SSTable manifests/components after restore; detecting tampering or bit rot in descriptor files; snapshot restore where the digest sidecar didn't accompany the data file correctly.","solutions":["Regenerate the file (or restore from backup/replica) so its digest matches; the existing file cannot be trusted.","Re-create the digest sidecar alongside the file if the file is legitimately new/modified (via FileDigestValidator creation path).","Verify both data file and digest file came from the same snapshot/generation.","Investigate storage integrity (fsck, SMART) if corruption is unexpected."],"exampleFix":"// before\ntry (FileDigestValidator v = DataIntegrityMetadata.fileDigestValidator(dataFile)) { v.validate(); }\n// after\ntry (FileDigestValidator v = DataIntegrityMetadata.fileDigestValidator(dataFile)) {\n    v.validate();\n} catch (IOException e) {\n    logger.error(\"Digest mismatch for {}\", dataFile, e);\n    Files.delete(digestFile); // force regeneration\n    throw e;\n}\n","handlingStrategy":"try-catch","validationCode":"// confirm digest sidecar exists and parse it before full validation\nif (!digestFileExists(dataFile)) throw new IOException(\"Missing digest sidecar for \" + dataFile);","typeGuard":null,"tryCatchPattern":"try (FileDigestValidator v = DataIntegrityMetadata.fileDigestValidator(dataFile)) { v.validate(); }\ncatch (IOException e) { regenerateOrRestore(dataFile); }","preventionTips":["Regenerate digests whenever a file is legitimately rewritten","Keep digest files with their data files in snapshots/backups","Treat digest mismatch as corruption, not a retryable error","Schedule periodic integrity verification"],"tags":["io","digest","corruption","integrity"],"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"}