tursodatabase/turso · error

MVCC logical log header checksum mismatch

Error message

MVCC logical log header checksum mismatch

What it means

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.

Solutions

  1. Restore the log from backup; a header CRC mismatch means the header itself is untrustworthy
  2. Regenerate the log and let clients resync from the replace-base fallback
  3. Check disk/filesystem health (dmesg, smartctl) if header corruption recurs
Defensive patterns

Strategy: try-catch

Validate before calling

fn mvcc_header_crc_ok(log: &[u8]) -> bool {
    if log.len() < MVCC_LOG_HEADER_SIZE {
        return false;
    }
    let stored = u32::from_le_bytes(
        log[MVCC_LOG_HEADER_CRC_START..MVCC_LOG_HEADER_CRC_START + 4]
            .try_into()
            .unwrap(),
    );
    let mut buf = [0u8; MVCC_LOG_HEADER_SIZE];
    buf.copy_from_slice(&log[..MVCC_LOG_HEADER_SIZE]);
    buf[MVCC_LOG_HEADER_CRC_START..MVCC_LOG_HEADER_SIZE].fill(0);
    stored == crc32c::crc32c(&buf)
}

Try / catch

match scan_mvcc_log(&log) {
    Ok(snapshot) => serve(snapshot),
    Err(err) if err.to_string().starts_with("MVCC logical log header checksum mismatch") => {
        warn!("MVCC log header corrupt: {err}");
        restore_from_backup_or_regenerate()?;
    }
    Err(err) => return Err(err),
}

Prevention

When it happens

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

Common situations: 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.

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 tursodatabase/turso@492c4a71cd (2026-08-20). Data as JSON: /api/errors/c1773bc5122c932f. Report an issue: GitHub.

Appendix: source

Thrown at cli/sync_server.rs:1128

        return Err(anyhow!(
            "invalid MVCC logical log header length: {header_len}"
        ));
    }
    if log[MVCC_LOG_HEADER_RESERVED_START..MVCC_LOG_HEADER_CRC_START]
        .iter()
        .any(|byte| *byte != 0)
    {
        return Err(anyhow!(
            "MVCC logical log header reserved bytes must be zero"
        ));
    }
    let stored_crc = read_u32_le(log, MVCC_LOG_HEADER_CRC_START)?;
    let mut crc_buf = [0u8; MVCC_LOG_HEADER_SIZE];
    crc_buf.copy_from_slice(&log[..MVCC_LOG_HEADER_SIZE]);
    crc_buf[MVCC_LOG_HEADER_CRC_START..MVCC_LOG_HEADER_SIZE].fill(0);
    let expected_crc = crc32c::crc32c(&crc_buf);
    if stored_crc != expected_crc {
        return Err(anyhow!("MVCC logical log header checksum mismatch"));
    }
    Ok(())
}

fn initial_mvcc_log_crc(log: &[u8]) -> Result<u32> {
    let salt = u64::from_le_bytes(
        log[MVCC_LOG_HEADER_SALT_START..MVCC_LOG_HEADER_SALT_END]
            .try_into()
            .expect("fixed-size salt slice"),
    );
    Ok(crc32c::crc32c(&salt.to_le_bytes()))
}

fn read_mvcc_frame_boundary(
    log: &[u8],
    offset: usize,
    running_crc: u32,
) -> Result<Option<(usize, u32)>> {

View on GitHub (pinned to 492c4a71cd)