{"record":{"id":"c69f90fd0b48d3aa","repo":"clockworklabs/SpacetimeDB","slug":"repo-error-getting-file-metadata-for-segment","errorCode":null,"errorMessage":"repo {}: error getting file metadata for segment {}: {}","messagePattern":"repo (.+?): error getting file metadata for segment (.+?): (.+?)","errorType":"exception","errorClass":"std::io::Error","httpStatus":null,"severity":"error","filePath":"crates/commitlog/src/repo/fs.rs","lineNumber":307,"sourceCode":"                    warn!(\"repo {}: failed to remove {}: {}\", self, lock_path.display(), e);\n                }\n            },\n        );\n\n        // Check whether the segment already exists.\n        // Overwrite it if its length is zero.\n        match fs::metadata(&path) {\n            Ok(stat) => {\n                if stat.len() > 0 {\n                    return Err(io::Error::new(\n                        io::ErrorKind::AlreadyExists,\n                        format!(\"repo {}: segment {} already exists and is non-empty\", self, offset),\n                    ));\n                }\n            }\n            Err(e) => {\n                if e.kind() != io::ErrorKind::NotFound {\n                    return Err(io::Error::new(\n                        e.kind(),\n                        format!(\n                            \"repo {}: error getting file metadata for segment {}: {}\",\n                            self, offset, e\n                        ),\n                    ));\n                }\n            }\n        }\n\n        // The segment file either does not exist, or is of length zero.\n        // Write the header to a temporary file and atomically move it into place.\n        let mut tmp = tempfile::Builder::new().make_in(&self.root.0, |tmp_path| {\n            File::options().read(true).write(true).create_new(true).open(tmp_path)\n        })?;\n        header.write(&mut tmp)?;\n        let segment = self.persist_durably(tmp, &path)?;\n","sourceCodeStart":289,"sourceCodeEnd":325,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/3653d2ed498fddbd83b7062aa6bf8970e18635ec/crates/commitlog/src/repo/fs.rs#L289-L325","documentation":"While checking whether a segment file may be (re)created, filesystem create_segment stats the path with fs::metadata. NotFound is the expected, healthy answer (segment does not exist); any other stat failure - PermissionDenied on a directory in the path, IO errors from failing storage, path loops - is re-wrapped with this message including repo path, segment offset and the underlying error.","triggerScenarios":"fs::metadata on the segment path failing with a kind other than NotFound: permission problems on the data directory or a parent, a read-only remount after filesystem errors, or a failing disk.","commonSituations":"Permission mismatches in containerized/mounted data directories; storage devices going bad; data directory moved or restructured while a node holds offsets from the old layout.","solutions":["Inspect the full segment path: every parent directory must be traversable and writable by the node user.","Check storage health and mount options (filesystems often remount read-only after errors).","If the directory layout changed, point the log at the correct location or restore the expected layout."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Startup probe: verify the data directory is traversable and writable\nlet probe = data_dir.join(\"segment-probe\");\nstd::fs::write(&probe, b\"\")?;\nstd::fs::remove_file(&probe)?;","typeGuard":null,"tryCatchPattern":"match repo.create_segment(offset, header) {\n    Ok(seg) => seg,\n    Err(e) => {\n        // stat failed with a kind other than NotFound: report path/permissions/disk and stop\n        tracing::error!(\"cannot stat segment path: {e}\");\n        return Err(e.into());\n    }\n}","preventionTips":["Validate the data directory once at node startup: create, write and remove a probe file.","Pin ownership of the data directory to the node's service account.","Do not move, rename or remount a live node's data directory."],"tags":["rust","commitlog","filesystem","metadata","io"],"backgroundTag":"file-metadata-error","analyzedSha":"3653d2ed498fddbd83b7062aa6bf8970e18635ec","analyzedAt":"2026-08-20T06:08:37.179Z","contentChangedAt":"2026-08-20T06:08:37.179Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}