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