apache/cassandra · warning

Mismatched last line in file

Error message

Mismatched last line in file {}: '{}' not the same as '{}'

What it means

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.

Solutions

  1. Verify disk integrity and space; ensure the node shut down cleanly
  2. 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
  3. Do not hand-edit files under commitlog/; let Cassandra manage them
  4. Restore from backup or remove the corrupted replica file only with full understanding that truncation replay information may be lost
Defensive patterns

Strategy: validation

Validate before calling

// sanity-check a replica file before relying on replay
List<String> lines = Files.readAllLines(replicaFile);
if (!lines.get(0).equals(lines.get(lines.size()-1)))
    logger.warn("Replica file {} incomplete/corrupted", replicaFile);

Prevention

When it happens

Trigger: 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.

Common situations: Node crashed or lost power mid-commitlog write; filesystem truncated the log; operator inspected/modified files in the commitlog directory while Cassandra was stopped.

Understand the failure class

Background: Checksum mismatch errors: "checksum verification failed", "digest mismatch", "expected vs actual checksum" — what they mean and how to fix them — this error's family across 41 libraries.

Related errors


AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10). Data as JSON: /api/errors/5d9baf1d31357cc1. Report an issue: GitHub.

Appendix: source

Thrown at src/java/org/apache/cassandra/db/lifecycle/LogReplicaSet.java:159

                    firstLine = currentLine;
                    continue;
                }

                if (!isPrefixMatch(firstLine, currentLine))
                { // not a prefix match
                    logger.error("Mismatched line in file {}: got '{}' expected '{}', giving up",
                                 entry.getKey().getFileName(),
                                 currentLine,
                                 firstLine);
                    entry.getKey().setError(currentLine, String.format("Does not match <%s> in first replica file", firstLine));
                    return false;
                }

                if (!firstLine.equals(currentLine))
                {
                    if (i == currentLines.size() - 1)
                    { // last record, just set record as invalid and move on
                        logger.warn("Mismatched last line in file {}: '{}' not the same as '{}'",
                                    entry.getKey().getFileName(),
                                    currentLine,
                                    firstLine);

                        if (currentLine.length() > firstLine.length())
                            firstLine = currentLine;

                        partial = true;
                    }
                    else
                    {   // mismatched entry file has more lines, giving up
                        logger.error("Mismatched line in file {}: got '{}' expected '{}', giving up",
                                     entry.getKey().getFileName(),
                                     currentLine,
                                     firstLine);
                        entry.getKey().setError(currentLine, String.format("Does not match <%s> in first replica file", firstLine));
                        return false;
                    }

View on GitHub (pinned to 88fd0f6a0e)