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