{"record":{"id":"c1773bc5122c932f","repo":"tursodatabase/turso","slug":"mvcc-logical-log-header-checksum-mismatch","errorCode":null,"errorMessage":"MVCC logical log header checksum mismatch","messagePattern":"MVCC logical log header checksum mismatch","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"cli/sync_server.rs","lineNumber":1128,"sourceCode":"        return Err(anyhow!(\n            \"invalid MVCC logical log header length: {header_len}\"\n        ));\n    }\n    if log[MVCC_LOG_HEADER_RESERVED_START..MVCC_LOG_HEADER_CRC_START]\n        .iter()\n        .any(|byte| *byte != 0)\n    {\n        return Err(anyhow!(\n            \"MVCC logical log header reserved bytes must be zero\"\n        ));\n    }\n    let stored_crc = read_u32_le(log, MVCC_LOG_HEADER_CRC_START)?;\n    let mut crc_buf = [0u8; MVCC_LOG_HEADER_SIZE];\n    crc_buf.copy_from_slice(&log[..MVCC_LOG_HEADER_SIZE]);\n    crc_buf[MVCC_LOG_HEADER_CRC_START..MVCC_LOG_HEADER_SIZE].fill(0);\n    let expected_crc = crc32c::crc32c(&crc_buf);\n    if stored_crc != expected_crc {\n        return Err(anyhow!(\"MVCC logical log header checksum mismatch\"));\n    }\n    Ok(())\n}\n\nfn initial_mvcc_log_crc(log: &[u8]) -> Result<u32> {\n    let salt = u64::from_le_bytes(\n        log[MVCC_LOG_HEADER_SALT_START..MVCC_LOG_HEADER_SALT_END]\n            .try_into()\n            .expect(\"fixed-size salt slice\"),\n    );\n    Ok(crc32c::crc32c(&salt.to_le_bytes()))\n}\n\nfn read_mvcc_frame_boundary(\n    log: &[u8],\n    offset: usize,\n    running_crc: u32,\n) -> Result<Option<(usize, u32)>> {","sourceCodeStart":1110,"sourceCodeEnd":1146,"githubUrl":"https://github.com/tursodatabase/turso/blob/492c4a71cd7c2649e7df83da1471b74f4b1c7aa9/cli/sync_server.rs#L1110-L1146","documentation":"The last 4 bytes of the 56-byte MVCC logical log header store a CRC32C computed over the whole header with the CRC field itself zeroed. validate_mvcc_log_header recomputes it and throws on mismatch, so this error means at least one header byte changed after the log was written.","triggerScenarios":"read_u32_le(log, MVCC_LOG_HEADER_CRC_START) returns a value different from crc32c::crc32c over the zeroed-CRC copy of log[..56] during scan_mvcc_log on a /pull-updates pull.","commonSituations":"Torn header write when the process crashed while creating the log; bit rot on disk; the salt or version bytes edited manually; the file truncated and re-grown by another process.","solutions":["Restore the log from backup; a header CRC mismatch means the header itself is untrustworthy","Regenerate the log and let clients resync from the replace-base fallback","Check disk/filesystem health (dmesg, smartctl) if header corruption recurs"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"fn mvcc_header_crc_ok(log: &[u8]) -> bool {\n    if log.len() < MVCC_LOG_HEADER_SIZE {\n        return false;\n    }\n    let stored = u32::from_le_bytes(\n        log[MVCC_LOG_HEADER_CRC_START..MVCC_LOG_HEADER_CRC_START + 4]\n            .try_into()\n            .unwrap(),\n    );\n    let mut buf = [0u8; MVCC_LOG_HEADER_SIZE];\n    buf.copy_from_slice(&log[..MVCC_LOG_HEADER_SIZE]);\n    buf[MVCC_LOG_HEADER_CRC_START..MVCC_LOG_HEADER_SIZE].fill(0);\n    stored == crc32c::crc32c(&buf)\n}","typeGuard":null,"tryCatchPattern":"match scan_mvcc_log(&log) {\n    Ok(snapshot) => serve(snapshot),\n    Err(err) if err.to_string().starts_with(\"MVCC logical log header checksum mismatch\") => {\n        warn!(\"MVCC log header corrupt: {err}\");\n        restore_from_backup_or_regenerate()?;\n    }\n    Err(err) => return Err(err),\n}","preventionTips":["Create the log atomically: write header to a temp file, fsync, rename","Keep periodic backups of the logical log","Run on storage with checksumming (ZFS/Btrfs) or schedule fsck if corruption recurs"],"tags":["mvcc","sync-server","crc32c","checksum","corruption"],"backgroundTag":"checksum-mismatch","analyzedSha":"492c4a71cd7c2649e7df83da1471b74f4b1c7aa9","analyzedAt":"2026-08-20T07:02:18.389Z","contentChangedAt":"2026-08-20T07:02:18.389Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}