clockworklabs/SpacetimeDB · error · std::io::Error

repo : error getting file metadata for segment

Error message

repo {}: error getting file metadata for segment {}: {}

What it means

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.

Solutions

  1. Inspect the full segment path: every parent directory must be traversable and writable by the node user.
  2. Check storage health and mount options (filesystems often remount read-only after errors).
  3. If the directory layout changed, point the log at the correct location or restore the expected layout.
Defensive patterns

Strategy: try-catch

Validate before calling

// Startup probe: verify the data directory is traversable and writable
let probe = data_dir.join("segment-probe");
std::fs::write(&probe, b"")?;
std::fs::remove_file(&probe)?;

Try / catch

match repo.create_segment(offset, header) {
    Ok(seg) => seg,
    Err(e) => {
        // stat failed with a kind other than NotFound: report path/permissions/disk and stop
        tracing::error!("cannot stat segment path: {e}");
        return Err(e.into());
    }
}

Prevention

When it happens

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

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

Related errors


AI-assisted analysis of clockworklabs/SpacetimeDB@3653d2ed49 (2026-08-20). Data as JSON: /api/errors/c69f90fd0b48d3aa. Report an issue: GitHub.

Appendix: source

Thrown at crates/commitlog/src/repo/fs.rs:307

                    warn!("repo {}: failed to remove {}: {}", self, lock_path.display(), e);
                }
            },
        );

        // Check whether the segment already exists.
        // Overwrite it if its length is zero.
        match fs::metadata(&path) {
            Ok(stat) => {
                if stat.len() > 0 {
                    return Err(io::Error::new(
                        io::ErrorKind::AlreadyExists,
                        format!("repo {}: segment {} already exists and is non-empty", self, offset),
                    ));
                }
            }
            Err(e) => {
                if e.kind() != io::ErrorKind::NotFound {
                    return Err(io::Error::new(
                        e.kind(),
                        format!(
                            "repo {}: error getting file metadata for segment {}: {}",
                            self, offset, e
                        ),
                    ));
                }
            }
        }

        // The segment file either does not exist, or is of length zero.
        // Write the header to a temporary file and atomically move it into place.
        let mut tmp = tempfile::Builder::new().make_in(&self.root.0, |tmp_path| {
            File::options().read(true).write(true).create_new(true).open(tmp_path)
        })?;
        header.write(&mut tmp)?;
        let segment = self.persist_durably(tmp, &path)?;

View on GitHub (pinned to 3653d2ed49)