{"record":{"id":"1dad4ff4e6598da3","repo":"databendlabs/databend","slug":"invalid-cache-item-expects-bytes-got-path","errorCode":null,"errorMessage":"Invalid cache item, expects {} bytes, got {}, path {:?}","messagePattern":"Invalid cache item, expects (.+?) bytes, got (.+?), path (.+?)","errorType":"exception","errorClass":"UnexpectedEof","httpStatus":null,"severity":"error","filePath":"src/query/storages/common/cache/src/providers/disk_cache/disk_cache_lru.rs","lineNumber":265,"sourceCode":"\n        let mut vec = Vec::<u8>::with_capacity(size);\n        let vec_ptr = vec.as_mut_ptr();\n        let fd = file.as_raw_fd();\n        let mut total_read = 0;\n\n        while total_read < size {\n            let result = unsafe {\n                read_syscall.read(\n                    fd,\n                    vec_ptr.add(total_read) as *mut libc::c_void,\n                    (size - total_read) as libc::size_t,\n                )\n            };\n\n            match result {\n                n if n > 0 => total_read += n as usize,\n                0 => {\n                    return Err(std::io::Error::new(\n                        std::io::ErrorKind::UnexpectedEof,\n                        format!(\n                            \"Invalid cache item, expects {} bytes, got {}, path {:?}\",\n                            size, total_read, path\n                        ),\n                    ));\n                }\n                _ => {\n                    let err = std::io::Error::last_os_error();\n                    if err.raw_os_error() == Some(libc::EINTR) {\n                        continue;\n                    } else {\n                        return Err(err);\n                    }\n                }\n            }\n        }\n","sourceCodeStart":247,"sourceCodeEnd":283,"githubUrl":"https://github.com/databendlabs/databend/blob/288d84d76e20a2f8f7173bda9691eb6ece301aa9/src/query/storages/common/cache/src/providers/disk_cache/disk_cache_lru.rs#L247-L283","documentation":"read_cache_content_with_syscall reads a disk-cache entry and expects exactly `size` bytes; a read returning 0 (EOF before the expected length) means the cache file is truncated or corrupted, so it raises an UnexpectedEof io error describing expected vs got bytes and the cache path.","triggerScenarios":"Reading a block from the disk cache (LRU-indexed) where the underlying cache file is shorter than the recorded size — partial write, crash during write, manual deletion/truncation, or stale LRU index pointing at a rewritten file.","commonSituations":"Node crash/power loss during cache writes; disk full causing truncated writes; sharing a cache directory between versions; corrupted cache volume.","solutions":["Delete the affected cache file (path is in the error) or clear the whole disk cache directory and let it repopulate.","Check disk space and filesystem health (dmesg, fsck) for the cache volume.","Upgrade/restart the query node if a stale index maps to the truncated file; disable disk cache temporarily if corruption recurs."],"exampleFix":"// before (keep serving from corrupt cache)\n// after\n$ rm /var/lib/databend/cache/<path-from-error>\n# then restart the query node or let the cache re-download the block","handlingStrategy":"try-catch","validationCode":"let meta = std::fs::metadata(&path)?;\nif (meta.len() as u64) < expected_size { bail!(\"cache file truncated: {:?}\", path); }","typeGuard":"fn cache_file_intact(path: &Path, expected: u64) -> bool {\n    std::fs::metadata(path).map(|m| m.len() >= expected).unwrap_or(false)\n}","tryCatchPattern":"match read_result {\n    Err(e) if e.kind() == std::io::ErrorKind::UnexpectedEof => {\n        // evict the corrupt entry (path is embedded in the message) and retry the read\n        invalidate_cache_entry(&path).await?;\n        retry().await\n    }\n    other => other,\n}","preventionTips":["Monitor cache volume for disk-full conditions","Clean the cache directory after crashes or OS upgrades","Do not share one cache directory across Databend versions"],"tags":["cache","disk","io","eof"],"backgroundTag":"file-read-failed","analyzedSha":"288d84d76e20a2f8f7173bda9691eb6ece301aa9","analyzedAt":"2026-09-11T11:29:36.208Z","contentChangedAt":"2026-09-11T11:29:36.208Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}