{"record":{"id":"189011ba319631c9","repo":"tursodatabase/turso","slug":"database-page-is-missing-from-replace-base-snap","errorCode":null,"errorMessage":"database page {} is missing from replace-base snapshot","messagePattern":"database page (.+?) is missing from replace-base snapshot","errorType":"http","errorClass":null,"httpStatus":500,"severity":"critical","filePath":"cli/sync_server.rs","lineNumber":978,"sourceCode":"    #[allow(clippy::type_complexity)]\n    fn read_replace_base_pages(&self, db: &DbHandle) -> Result<(u64, Vec<(u64, Vec<u8>)>)> {\n        let conn = db.conn.lock().unwrap();\n        let wal_state = conn.wal_state()?;\n        let frame_watermark = Some(wal_state.max_frame);\n        let db_size = current_snapshot_db_size_pages(&conn, wal_state.max_frame)?;\n        let pages_capacity = usize::try_from(db_size)\n            .map_err(|_| anyhow!(\"database page count does not fit usize: {db_size}\"))?;\n        let mut pages = Vec::with_capacity(pages_capacity);\n\n        for page_no in 1..=db_size {\n            let page_no_u32 = u32::try_from(page_no)\n                .map_err(|_| anyhow!(\"database page number does not fit u32: {page_no}\"))?;\n            let mut page = vec![0; PAGE_SIZE];\n            let found =\n                conn.try_wal_watermark_read_page(page_no_u32, &mut page, frame_watermark)?;\n            if !found {\n                return Err(anyhow!(\n                    \"database page {} is missing from replace-base snapshot\",\n                    page_no\n                ));\n            }\n            pages.push((page_no - 1, page));\n        }\n\n        Ok((db_size, pages))\n    }\n}\n\nstruct HttpResponse {\n    status: u16,\n    content_type: String,\n    body: Vec<u8>,\n}\n\nstruct MvccLogSnapshot {\n    end_offset: u64,","sourceCodeStart":960,"sourceCodeEnd":996,"githubUrl":"https://github.com/tursodatabase/turso/blob/492c4a71cd7c2649e7df83da1471b74f4b1c7aa9/cli/sync_server.rs#L960-L996","documentation":"While reading a replace-base snapshot, the server loops over pages 1..=db_size but try_wal_watermark_read_page reported a page as not found in the database file or the WAL up to the frame watermark. The snapshot's declared size and the actually readable pages disagree, meaning the db+WAL file set is incomplete, truncated, or corrupt.","triggerScenarios":"Serving a replace-base bootstrap when the db file is truncated relative to its claimed size; db and WAL files copied from different points in time; a concurrent checkpoint/truncation removing pages mid-read; hand-edited files.","commonSituations":"Copying a database without its WAL sidecar; crash mid-checkpoint; disk-full during earlier writes; test fixtures pairing a db with a stale WAL; copying files while the server is running.","solutions":["Restore the database and WAL as a consistent pair from a known-good backup","Recreate the sync server database from the authoritative source of truth","Stop the server before copying or mutating db/WAL files","Run integrity verification (dbhash / integrity check) before serving sync traffic"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"// pre-flight: claimed page count must be coverable by db+WAL bytes\nlet min_bytes = db_size_pages as u64 * PAGE_SIZE as u64;\nlet available = db_file_len + wal_file_len;\nassert!(available >= min_bytes, \"snapshot claims {db_size_pages} pages but files are too small\");","typeGuard":null,"tryCatchPattern":"match read_replace_base_pages().await {\n    Ok(pages) => pages,\n    Err(e) if e.to_string().contains(\"missing from replace-base snapshot\") => {\n        quarantine_current_db().await?;      // stop serving inconsistent state\n        rebuild_db_from_source().await?;     // recreate from authoritative copy\n        read_replace_base_pages().await?\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Always copy the db and its WAL together, with the server stopped","Never hand-edit or truncate db/WAL files","Verify consistency (dbhash / integrity check) before putting a file set into service","Monitor disk space so writes do not fail mid-page"],"tags":["sync-server","snapshot","wal","corruption","missing-page"],"backgroundTag":"database-corruption-detected","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"}