Skip to main content

ic_backup/ops/persistence/
mod.rs

1//! Durable publication, journal/layout exclusion and retained local dependencies.
2
3mod artifact_commit;
4mod attempt_journal;
5mod command_lifetime_lock;
6mod consistency;
7mod download_journal;
8mod effect_graph;
9mod execution_progress;
10mod execution_settlement;
11mod execution_workflow;
12mod fence_obligation;
13mod file_lock;
14mod inventory;
15mod journal_lock;
16mod json;
17mod layout_lifetime;
18mod operation_plan;
19mod restore_safety;
20
21pub use artifact_commit::{ArtifactCommitOutcome, commit_artifact_directory};
22pub use attempt_journal::{AttemptJournalError, AttemptJournalGuard};
23pub use command_lifetime_lock::{
24    COMMAND_CUSTODY_DESCRIPTOR_ENV, CommandLifetimeLock, CommandLifetimeLockError,
25    CommandQuiescenceGuard,
26};
27pub use consistency::{
28    ConsistencyPersistenceError, create_consistency_requirement, read_consistency_requirement,
29};
30pub use download_journal::{
31    DownloadIntegrityError, DownloadJournalError, DownloadJournalGuard, DownloadManifestError,
32    LocalRestoreArtifactError, LocalRestoreArtifactPublicationError, LocalRestoreArtifactView,
33    LocalRestoreSourceError, read_download_manifest,
34};
35#[cfg(unix)]
36pub use download_journal::{
37    IcSnapshotArtifactError, IcSnapshotArtifactWriter, IcSnapshotLocalMetrics,
38    IcSnapshotUploadArtifactError, MeasurementHistogram, MeasurementSummary,
39};
40pub use effect_graph::{EffectGraphPersistenceError, create_effect_graph, read_effect_graph};
41pub use execution_progress::{ExecutionProgressPersistenceError, read_execution_progress};
42pub use execution_settlement::{
43    ExecutionSettlementPersistenceError, create_execution_settlement, read_execution_settlement,
44};
45pub use execution_workflow::{
46    ExecutionStageGuard, ExecutionWorkflowPersistenceError, create_execution_workflow,
47    read_execution_workflow,
48};
49pub use fence_obligation::{
50    FenceObligationPersistenceError, FenceObligationRequirement, create_fence_obligation,
51    read_fence_obligation,
52};
53pub use inventory::{InventoryError, create_inventory, read_inventory};
54pub use journal_lock::{JournalLock, JournalLockError};
55pub use json::{create_json_durable, read_json, write_json_durable};
56pub use layout_lifetime::{BackupLayoutGuard, MAX_RESTORE_REFERENCE_BYTES};
57pub use operation_plan::{
58    OperationPlanPersistenceError, create_operation_plan, read_operation_plan,
59};
60pub use restore_safety::{
61    RestoreSafetyPersistenceError, create_restore_safety_requirement,
62    read_restore_safety_requirement,
63};
64
65use crate::{model::artifacts::ChecksumError, ops::artifacts::ArtifactError};
66use std::io;
67use thiserror::Error;
68
69/// Typed local persistence failure.
70#[derive(Debug, Error)]
71pub enum PersistenceError {
72    /// An existing layout path no longer denotes the held directory.
73    #[error("backup layout changed while held: {path:?}")]
74    LayoutChanged {
75        /// Resolved layout location.
76        path: std::path::PathBuf,
77    },
78    /// A retained dependency document or journal location has an unsafe entry type.
79    #[error("unsafe restore reference entry: {path:?}")]
80    InvalidRestoreReferences {
81        /// Rejected local path.
82        path: std::path::PathBuf,
83    },
84    /// Restore dependency validation or an immutable retention transition failed.
85    #[error(transparent)]
86    RestoreReference(#[from] crate::model::restore_references::RestoreReferenceError),
87    /// Parent preparation, record reads or other local filesystem IO failed.
88    /// Shared JSON publication failures retain their separate structured boundary.
89    #[error(transparent)]
90    Io(#[from] io::Error),
91    /// Shared file publication failed, retaining producer/cleanup causes and visibility.
92    /// An after-publication failure leaves output visible and requires reconciliation.
93    #[error(transparent)]
94    Publication(#[from] ic_host_fs::durable::NamedWriteError<io::Error>),
95    /// JSON encoding or decoding failed.
96    #[error(transparent)]
97    Json(#[from] serde_json::Error),
98    /// A machine record exceeds its caller-selected byte bound.
99    #[error("record exceeds byte limit {limit}")]
100    RecordTooLarge {
101        /// Maximum accepted bytes.
102        limit: u64,
103    },
104    /// Artifact traversal or streaming failed.
105    #[error(transparent)]
106    Artifact(#[from] ArtifactError),
107    /// Verified bytes do not match the expected checksum.
108    #[error(transparent)]
109    Checksum(#[from] ChecksumError),
110    /// Publication requires distinct siblings in one directory.
111    #[error("artifact commit paths must be distinct siblings: {temporary}, {canonical}")]
112    ArtifactCommitPathMismatch {
113        /// Retained staging path.
114        temporary: String,
115        /// Canonical destination.
116        canonical: String,
117    },
118    /// Both staging and canonical trees exist; neither is overwritten.
119    #[error("artifact commit has conflicting paths: {temporary}, {canonical}")]
120    ArtifactCommitPathConflict {
121        /// Retained staging path.
122        temporary: String,
123        /// Existing canonical destination.
124        canonical: String,
125    },
126    /// Neither expected tree exists.
127    #[error("artifact commit is missing both paths: {temporary}, {canonical}")]
128    ArtifactCommitPathMissing {
129        /// Missing staging path.
130        temporary: String,
131        /// Missing canonical destination.
132        canonical: String,
133    },
134    /// Atomic no-replace directory publication is unsupported.
135    #[error("durable artifact publication is unsupported on {platform}")]
136    ArtifactCommitUnsupportedPlatform {
137        /// Host platform name.
138        platform: &'static str,
139    },
140    /// Publication found an unsafe tree entry.
141    #[error("unsupported artifact entry at {path}: {kind}")]
142    UnsupportedArtifactEntry {
143        /// Entry path.
144        path: String,
145        /// Observed entry kind.
146        kind: String,
147    },
148}