Skip to main content

ic_backup/ops/persistence/execution_progress/
mod.rs

1//! Original retained plan/journal admission for local progress and guarded reservations.
2
3use super::{AttemptJournalError, BackupLayoutGuard, OperationPlanPersistenceError};
4use crate::{
5    model::{
6        artifacts::ArtifactChecksumRecord, attempt_journal::AttemptJournalRecord,
7        operation_plan::OperationPlanError,
8    },
9    policy::execution_progress::{
10        ExecutionProgressError, ExecutionProgressView, progress_with_journals,
11    },
12};
13use thiserror::Error;
14
15/// Read complete original retained execution evidence without remote effects or artifact reads.
16///
17/// Requires the exact persisted plan and every original attempt journal. Missing
18/// journals never supply zero consumption. Journal locks are taken sequentially;
19/// hold no attempt guards when calling this function. The layout retains cooperating
20/// exclusion, while noncooperating byte custody remains integration-owned.
21/// This grants no fresh permission, executable call, authenticated receipt or release.
22/// # Errors
23/// Rejects missing/unsafe/changed originals, contention and invalid retained causality.
24pub fn read_execution_progress(
25    layout: &BackupLayoutGuard,
26    expected_plan: &ArtifactChecksumRecord,
27) -> Result<ExecutionProgressView, ExecutionProgressPersistenceError> {
28    read_with_current(layout, expected_plan, None)
29}
30
31pub(super) fn read_with_current(
32    layout: &BackupLayoutGuard,
33    expected_plan: &ArtifactChecksumRecord,
34    current: Option<&AttemptJournalRecord>,
35) -> Result<ExecutionProgressView, ExecutionProgressPersistenceError> {
36    let (plan, journals) = super::attempt_journal::read_original_plan_journals::<
37        ExecutionProgressPersistenceError,
38    >(layout, expected_plan, current)?;
39    Ok(progress_with_journals(&plan, journals.iter())?.0)
40}
41
42/// Typed local evidence or reservation rejection; no failure resets original spending.
43#[derive(Debug, Error)]
44pub enum ExecutionProgressPersistenceError {
45    /// Exact original persisted plan cannot be admitted.
46    #[error(transparent)]
47    Plan(#[from] OperationPlanPersistenceError),
48    /// Original bulk authority derivation failed.
49    #[error(transparent)]
50    Authority(#[from] OperationPlanError),
51    /// Original journal admission or durable reservation failed.
52    #[error(transparent)]
53    Journal(#[from] AttemptJournalError),
54    /// Complete retained accounting/causality cannot be projected.
55    #[error(transparent)]
56    Policy(#[from] ExecutionProgressError),
57    /// The selected operation has a prerequisite without retained Applied evidence.
58    #[error("operation {0} has unapplied prerequisites")]
59    DependenciesUnapplied(u64),
60}
61
62#[cfg(all(test, unix))]
63mod tests;