{"record":{"id":"89e307cee8036acf","repo":"tursodatabase/turso","slug":"truncated-mvcc-logical-log-header-len-header-s","errorCode":null,"errorMessage":"truncated MVCC logical log header: len={} header_size={}","messagePattern":"truncated MVCC logical log header: len=(.+?) header_size=(.+?)","errorType":"http","errorClass":null,"httpStatus":500,"severity":"critical","filePath":"cli/sync_server.rs","lineNumber":1067,"sourceCode":"            .parse::<u64>()\n            .map_err(|err| anyhow!(\"invalid MVCC pull revision offset: {revision}: {err}\"));\n    }\n    // Older page bootstrap responses from this test server used WAL frame\n    // numbers. Treat them as \"the page snapshot already includes the current\n    // logical log\" so the required follow-up logical pull becomes a no-op.\n    Ok(legacy_default)\n}\n\nfn scan_mvcc_log(log: &[u8]) -> Result<MvccLogSnapshot> {\n    if log.is_empty() {\n        return Ok(MvccLogSnapshot {\n            end_offset: 0,\n            crc_by_offset: vec![(0, 0)],\n        });\n    }\n    if log.len() < MVCC_LOG_HEADER_SIZE {\n        return Err(anyhow!(\n            \"truncated MVCC logical log header: len={} header_size={}\",\n            log.len(),\n            MVCC_LOG_HEADER_SIZE\n        ));\n    }\n    validate_mvcc_log_header(log)?;\n    let mut running_crc = initial_mvcc_log_crc(log)?;\n    let mut offset = MVCC_LOG_HEADER_SIZE;\n    let mut crc_by_offset = vec![(MVCC_LOG_HEADER_SIZE as u64, running_crc)];\n\n    while offset < log.len() {\n        let Some((frame_end, frame_crc)) = read_mvcc_frame_boundary(log, offset, running_crc)?\n        else {\n            break;\n        };\n        running_crc = frame_crc;\n        offset = frame_end;\n        crc_by_offset.push((offset as u64, running_crc));\n    }","sourceCodeStart":1049,"sourceCodeEnd":1085,"githubUrl":"https://github.com/tursodatabase/turso/blob/492c4a71cd7c2649e7df83da1471b74f4b1c7aa9/cli/sync_server.rs#L1049-L1085","documentation":"scan_mvcc_log found the .db-log file non-empty but shorter than the fixed MVCC log header size, so it cannot even read magic/version/flags. This indicates a truncated or corrupted logical log: a partial write, a crash during log creation, or a foreign/wrong file sitting at the .db-log path.","triggerScenarios":"Server hard-killed while the logical log was being created or extended; disk-full truncation; a truncated file copied in as <db>.db-log; then any MVCC logical pull triggers the scan and fails.","commonSituations":"Power loss or kill -9 during heavy write load; copying files mid-write; filesystem faults; test fixtures with sliced log files.","solutions":["Restore the database and .db-log together from a consistent backup","If the database itself is intact and disposable, delete the invalid .db-log and let clients re-bootstrap (server rebuilds the log)","Check disk space and filesystem health to stop recurrence"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"// pre-flight before serving logical pulls\nlet meta = std::fs::metadata(&log_path)?;\nif 0 < meta.len() && (meta.len() as usize) < MVCC_LOG_HEADER_SIZE {\n    return Err(anyhow!(\"logical log file is truncated; restore or delete it and re-bootstrap\"));\n}","typeGuard":null,"tryCatchPattern":"match scan_mvcc_log(&log_bytes) {\n    Ok(snapshot) => snapshot,\n    Err(e) if e.to_string().contains(\"truncated MVCC logical log header\") => {\n        // log is unusable: rebuild from the authoritative database and force client re-bootstrap\n        regenerate_logical_log()?;\n        scan_mvcc_log(&std::fs::read(&log_path)?)?\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Shut the server down cleanly so the log is never left mid-write","Restore db and .db-log only as a consistent pair from backups","Monitor disk space; truncation often follows ENOSPC"],"tags":["mvcc","logical-log","truncated","corruption","sync-server"],"backgroundTag":"corrupted-log-file","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"}