ic_backup/ops/persistence/effect_graph/
mod.rs1use super::{
4 BackupLayoutGuard, JournalLock, JournalLockError, PersistenceError, create_json_durable,
5 read_json,
6};
7use crate::model::{
8 artifacts::ArtifactChecksumRecord,
9 effect_graph::{EffectGraphRecord, MAX_EFFECT_GRAPH_BYTES},
10};
11use thiserror::Error;
12
13pub fn create_effect_graph(
18 layout: &BackupLayoutGuard,
19 record: &EffectGraphRecord,
20) -> Result<(), EffectGraphPersistenceError> {
21 layout.check_root()?;
22 let path = layout.root().join("effect-graph.json");
23 let _lock = JournalLock::acquire(&path)?;
24 check_size(record)?;
25 create_json_durable(&path, record)?;
26 Ok(())
27}
28
29pub fn read_effect_graph(
37 layout: &BackupLayoutGuard,
38 expected: &ArtifactChecksumRecord,
39) -> Result<EffectGraphRecord, EffectGraphPersistenceError> {
40 layout.check_root()?;
41 let path = layout.root().join("effect-graph.json");
42 let _lock = JournalLock::acquire(&path)?;
43 let record: EffectGraphRecord = read_json(&path, MAX_EFFECT_GRAPH_BYTES)?;
44 check_size(&record)?;
45 if &record.digest() != expected {
46 return Err(EffectGraphPersistenceError::DigestMismatch);
47 }
48 Ok(record)
49}
50fn check_size(record: &EffectGraphRecord) -> Result<(), PersistenceError> {
51 super::json::check_json_size(record, MAX_EFFECT_GRAPH_BYTES)
52}
53
54#[derive(Debug, Error)]
56pub enum EffectGraphPersistenceError {
57 #[error("effect graph digest mismatch")]
59 DigestMismatch,
60 #[error(transparent)]
62 Lock(#[from] JournalLockError),
63 #[error(transparent)]
65 Persistence(#[from] PersistenceError),
66}
67
68#[cfg(all(test, unix))]
69mod tests;