use super::format::{KV_CKPT_FORMAT_VERSION, KvCheckpointManifest};
use super::paths::KV_CKPT_MANIFEST;
use crate::data::executor::checkpoint_decode_error::CheckpointDecodeError;
use crate::data::executor::core_loop::CoreLoop;
impl CoreLoop {
pub(super) fn read_kv_manifest(
&self,
ckpt_dir: &std::path::Path,
) -> Result<Option<KvCheckpointManifest>, CheckpointDecodeError> {
let path = ckpt_dir.join(KV_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::<KvCheckpointManifest>(&bytes).map_err(|source| {
CheckpointDecodeError::MsgpackDecode {
path: path.clone(),
source,
}
})?;
if manifest.format_version != KV_CKPT_FORMAT_VERSION {
return Err(CheckpointDecodeError::FormatVersion {
path: path.clone(),
found: manifest.format_version,
expected: KV_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: "kv".to_string(),
detail: format!(
"KV checkpoint: failed to {action} at {}: {e}",
path.display()
),
}
}