Skip to main content

ic_backup/ops/persistence/effect_graph/
mod.rs

1//! Immutable bounded graph publication and exact original local graph admission.
2
3use 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
10/// Durably create `effect-graph.json` under layout exclusion without replacing evidence.
11///
12/// # Errors
13/// Rejects excessive canonical bytes, existing/unsafe entries, replaced roots and IO/locks.
14pub 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
21/// Admit retained bounded graph under its original exact expected digest, using local IO only.
22///
23/// Lost creation replies reconcile by reading the exact graph. This neither checks
24/// remote completion nor grants effects, fresh authority or plan acceptance.
25///
26/// # Errors
27/// Rejects unsafe/missing/oversized/invalid graphs, digest mismatch, replaced roots and locks.
28pub 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/// Typed declared graph identity or immutable local persistence rejection.
42#[derive(Debug, Error)]
43pub enum EffectGraphPersistenceError {
44    /// Retained graph differs from the original exact declared digest.
45    #[error("effect graph digest mismatch")]
46    DigestMismatch,
47    /// Cooperating layout/journal ownership failed.
48    #[error(transparent)]
49    Lock(#[from] JournalLockError),
50    /// Bounded JSON, graph admission or durable filesystem access failed.
51    #[error(transparent)]
52    Persistence(#[from] PersistenceError),
53}
54
55#[cfg(all(test, unix))]
56mod tests;