use super::format::{SPARSE_VECTOR_CKPT_FORMAT_VERSION, SparseVectorCheckpointManifest};
use super::paths::SPARSE_VECTOR_CKPT_MANIFEST;
use crate::data::executor::checkpoint_decode_error::CheckpointDecodeError;
pub(crate) fn read_sparse_vector_manifest_at(
ckpt_dir: &std::path::Path,
_core_id: usize,
) -> Result<Option<SparseVectorCheckpointManifest>, CheckpointDecodeError> {
let path = ckpt_dir.join(SPARSE_VECTOR_CKPT_MANIFEST);
if !path.exists() {
return Ok(None);
}
let bytes = nodedb_wal::segment::read_checkpoint_framed(&path).map_err(|source| {
CheckpointDecodeError::ReadFile {
path: path.clone(),
source,
}
})?;
let manifest =
zerompk::from_msgpack::<SparseVectorCheckpointManifest>(&bytes).map_err(|source| {
CheckpointDecodeError::MsgpackDecode {
path: path.clone(),
source,
}
})?;
if manifest.format_version != SPARSE_VECTOR_CKPT_FORMAT_VERSION {
return Err(CheckpointDecodeError::FormatVersion {
path: path.clone(),
found: manifest.format_version,
expected: SPARSE_VECTOR_CKPT_FORMAT_VERSION,
});
}
Ok(Some(manifest))
}
pub(super) fn storage_err(
path: &std::path::Path,
action: &str,
e: &dyn std::fmt::Display,
) -> crate::Error {
crate::Error::Storage {
engine: "sparse_vector".to_string(),
detail: format!(
"sparse-vector checkpoint: failed to {action} at {}: {e}",
path.display()
),
}
}