{"record":{"id":"5d9baf1d31357cc1","repo":"apache/cassandra","slug":"mismatched-last-line-in-file-not-the-same","errorCode":null,"errorMessage":"Mismatched last line in file {}: '{}' not the same as '{}'","messagePattern":"Mismatched last line in file (.+?): '(.+?)' not the same as '(.+?)'","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/java/org/apache/cassandra/db/lifecycle/LogReplicaSet.java","lineNumber":159,"sourceCode":"                    firstLine = currentLine;\n                    continue;\n                }\n\n                if (!isPrefixMatch(firstLine, currentLine))\n                { // not a prefix match\n                    logger.error(\"Mismatched line in file {}: got '{}' expected '{}', giving up\",\n                                 entry.getKey().getFileName(),\n                                 currentLine,\n                                 firstLine);\n                    entry.getKey().setError(currentLine, String.format(\"Does not match <%s> in first replica file\", firstLine));\n                    return false;\n                }\n\n                if (!firstLine.equals(currentLine))\n                {\n                    if (i == currentLines.size() - 1)\n                    { // last record, just set record as invalid and move on\n                        logger.warn(\"Mismatched last line in file {}: '{}' not the same as '{}'\",\n                                    entry.getKey().getFileName(),\n                                    currentLine,\n                                    firstLine);\n\n                        if (currentLine.length() > firstLine.length())\n                            firstLine = currentLine;\n\n                        partial = true;\n                    }\n                    else\n                    {   // mismatched entry file has more lines, giving up\n                        logger.error(\"Mismatched line in file {}: got '{}' expected '{}', giving up\",\n                                     entry.getKey().getFileName(),\n                                     currentLine,\n                                     firstLine);\n                        entry.getKey().setError(currentLine, String.format(\"Does not match <%s> in first replica file\", firstLine));\n                        return false;\n                    }","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/lifecycle/LogReplicaSet.java#L141-L177","documentation":"When reading a truncation/replica log file, LogReplicaSet.readRecords compares the first and last lines: the last line of a replica file must repeat the first line as a checksum/sentinel of a complete record. A mismatch means the file's last line is incomplete or corrupted, typically due to a crash mid-write; the reader logs a warning and adopts the longer line as the record.","triggerScenarios":"Reading commit-log/sstable truncation replica files where the final line differs from the first line, e.g. partial writes from an unclean shutdown, disk-full truncation, or manual editing of the log file.","commonSituations":"Node crashed or lost power mid-commitlog write; filesystem truncated the log; operator inspected/modified files in the commitlog directory while Cassandra was stopped.","solutions":["Verify disk integrity and space; ensure the node shut down cleanly","If only these log files are affected, Cassandra continues with the last valid record; run nodetool verify / scrub on affected sstables if data concerns remain","Do not hand-edit files under commitlog/; let Cassandra manage them","Restore from backup or remove the corrupted replica file only with full understanding that truncation replay information may be lost"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// sanity-check a replica file before relying on replay\nList<String> lines = Files.readAllLines(replicaFile);\nif (!lines.get(0).equals(lines.get(lines.size()-1)))\n    logger.warn(\"Replica file {} incomplete/corrupted\", replicaFile);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never hand-edit files under commitlog/","Ensure clean shutdowns; investigate crashes that stop mid-write","Monitor disk space to avoid truncated writes","Verify filesystem integrity after power loss"],"tags":["commitlog","file-corruption","crash-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"}