ic_backup/ops/persistence/effect_graph/
mod.rs1use super::{BackupLayoutGuard, JournalLockError, PersistenceError, immutable_record};
4use crate::model::{
5 artifacts::ArtifactChecksumRecord,
6 effect_graph::{EffectGraphRecord, MAX_EFFECT_GRAPH_BYTES},
7};
8use thiserror::Error;
9
10pub fn create_effect_graph(
15 layout: &BackupLayoutGuard,
16 record: &EffectGraphRecord,
17) -> Result<(), EffectGraphPersistenceError> {
18 immutable_record::create(layout, "effect-graph.json", MAX_EFFECT_GRAPH_BYTES, record)
19}
20
21pub fn read_effect_graph(
29 layout: &BackupLayoutGuard,
30 expected: &ArtifactChecksumRecord,
31) -> Result<EffectGraphRecord, EffectGraphPersistenceError> {
32 immutable_record::read(
33 layout,
34 "effect-graph.json",
35 MAX_EFFECT_GRAPH_BYTES,
36 |record: &EffectGraphRecord| &record.digest() == expected,
37 || EffectGraphPersistenceError::DigestMismatch,
38 )
39}
40
41#[derive(Debug, Error)]
43pub enum EffectGraphPersistenceError {
44 #[error("effect graph digest mismatch")]
46 DigestMismatch,
47 #[error(transparent)]
49 Lock(#[from] JournalLockError),
50 #[error(transparent)]
52 Persistence(#[from] PersistenceError),
53}
54
55#[cfg(all(test, unix))]
56mod tests;