{"record":{"id":"ecf016efede5b3c2","repo":"apache/cassandra","slug":"encountered-bad-header-at-position-d-of-commit-lo-ecf016","errorCode":null,"errorMessage":"Encountered bad header at position %d of commit log %s, with bad position but valid CRC","messagePattern":"Encountered bad header at position (.+?) of commit log (.+?), with bad position but valid CRC","errorType":"exception","errorClass":"SegmentReadException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/db/commitlog/CommitLogSegmentReader.java","lineNumber":210,"sourceCode":"            {\n                logger.warn(\"Skipping sync marker CRC check at position {} (end={}, calculated crc={}) of commit log {}.\" +\n                            \"Using per-mutation CRC checks to ensure correctness...\",\n                            offset, end, crc.getValue(), reader.getPath());\n                return end;\n            }\n\n            if (end != 0 || filecrc != 0)\n            {\n                String msg = String.format(\"Encountered bad header at position %d of commit log %s, with invalid CRC. \" +\n                             \"The end of segment marker should be zero.\", offset, reader.getPath());\n                throw new SegmentReadException(msg, true);\n            }\n            return -1;\n        }\n        else if (end < offset || end > reader.length())\n        {\n            String msg = String.format(\"Encountered bad header at position %d of commit log %s, with bad position but valid CRC\", offset, reader.getPath());\n            throw new SegmentReadException(msg, false);\n        }\n        return end;\n    }\n\n    public static class SegmentReadException extends IOException\n    {\n        public final boolean invalidCrc;\n\n        public SegmentReadException(String msg, boolean invalidCrc)\n        {\n            super(msg);\n            this.invalidCrc = invalidCrc;\n        }\n    }\n\n    public static class SyncSegment\n    {\n        /** the 'buffer' to replay commit log data from */","sourceCodeStart":192,"sourceCodeEnd":228,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/commitlog/CommitLogSegmentReader.java#L192-L228","documentation":"readSyncMarker also validates the marker's next-segment offset: end must lie within [offset, reader.length()]. When CRC is valid but the target position is out of range, SegmentReadException(tolerable=false) is thrown ('bad position but valid CRC'). A valid checksum pointing outside the file means the segment is truncated or from a different configuration — replay cannot continue safely.","triggerScenarios":"Replaying a commit log shorter than the recorded marker end (truncation, incomplete copy, restored partial file), or a segment written with a different segment size than the current configuration.","commonSituations":"Restoring only part of the commitlog directory from backup; rsync/scp interrupted mid-copy; mismatched cassandra.yaml commitlog_segment_size_in_mb between writer and replayer; deliberately trimmed files.","solutions":["Restore the complete, untruncated commit log files from backup.","Match commitlog_segment_size_in_mb to the value used when the logs were written.","Accept partial replay: remove/discard the truncated segment; run nodetool repair so replicas restore lost data.","If only this node is affected, wipe commitlog/ and bootstrap/repair from peers."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if (markerEnd > reader.length() || markerEnd < offset)\n    throw new IOException(\"Segment truncated: marker end \" + markerEnd + \" outside file length \" + reader.length());","typeGuard":null,"tryCatchPattern":"try {\n    replaySegment(file);\n} catch (SegmentReadException e) {\n    if (!e.tolerable) {\n        logger.error(\"Truncated commit log {}: restore full file or accept loss and repair\", file);\n        // decide: abort vs. discard segment + nodetool repair\n    }\n}","preventionTips":["Back up the entire commitlog directory atomically (verify file sizes after restore)","Keep commitlog_segment_size_in_mb unchanged across restore/replay","Run nodetool repair after discarding any damaged segment"],"tags":["commitlog","replay","truncation","corruption"],"backgroundTag":"file-read-failed","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}