{"record":{"id":"b320c43b44eb2595","repo":"apache/cassandra","slug":"encountered-bad-header-at-position-d-of-commit-lo","errorCode":null,"errorMessage":"Encountered bad header at position %d of commit log %s, with invalid CRC. The end of segment marker should be zero.","messagePattern":"Encountered bad header at position (.+?) of commit log (.+?), with invalid CRC\\. The end of segment marker should be zero\\.","errorType":"exception","errorClass":"SegmentReadException","httpStatus":null,"severity":"warning","filePath":"src/java/org/apache/cassandra/db/commitlog/CommitLogSegmentReader.java","lineNumber":203,"sourceCode":"            // The next marker position and CRC value are not written atomically, so it is possible for the latter to \n            // still be zero after the former has been finalized, even though the mutations that follow it are valid.\n            // When there is no compression or encryption enabled, we can ignore a sync marker CRC mismatch and defer \n            // to the per-mutation CRCs, which may be preferable to preventing startup altogether.\n            if (allowSkipSyncMarkerCrc\n                && descriptor.compression == null && !descriptor.getEncryptionContext().isEnabled()\n                && filecrc == 0 && end != 0)\n            {\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);","sourceCodeStart":185,"sourceCodeEnd":221,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/commitlog/CommitLogSegmentReader.java#L185-L221","documentation":"During commit log replay, CommitLogSegmentReader.readSyncMarker validates each sync marker. When the marker CRC matches but the recorded 'end' is the segment end marker (0) while trailing bytes/CRC are nonzero, the header is deemed invalid and SegmentReadException(tolerable=true) is thrown: 'The end of segment marker should be zero.' It indicates a truncated or corrupted segment tail.","triggerScenarios":"Replaying a commit log whose final sync marker region contains a nonzero end marker or nonzero CRC where zeros are required — typically due to a crash mid-write, torn page, or manual file truncation at a non-marker boundary.","commonSituations":"Node crash without clean shutdown; disk full during segment close; file copied/synced mid-write (e.g. backup of live segment); corrupted storage.","solutions":["Let Cassandra skip the corrupt tail: replay handles SegmentReadException with tolerable=true by stopping at the last valid marker.","Remove the affected segment from commitlog/ if replay is blocked and data loss is acceptable (it will be restored from SSTables).","Restore from backup/SSTables and run a repair (nodetool repair) to re-sync replicas.","Check disk health (dmesg, SMART) if corruption recurs."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    end = CommitLogSegmentReader.readSyncMarker(reader, offset);\n} catch (SegmentReadException e) {\n    if (e.tolerable)\n        logger.warn(\"Corrupt segment tail, stopping replay at last valid marker: {}\", e.getMessage());\n    else\n        throw e;\n}","preventionTips":["Stop Cassandra cleanly; avoid copying live commit log segments for backups","Monitor disk health and free space to prevent torn writes","Keep the commitlog directory on reliable storage"],"tags":["commitlog","replay","corruption","crc"],"backgroundTag":"checksum-mismatch","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"}