The only force recovery allowed here is retrying the exact view whose native switch completed before its separate Git projection failed.
(
&self,
mode: atomic_repository::WorkspaceTxnMode,
target: Option<&str>,
)
| 122 | /// The only force recovery allowed here is retrying the exact view whose |
| 123 | /// native switch completed before its separate Git projection failed. |
| 124 | pub(super) fn workspace_repository_for_switch( |
| 125 | &self, |
| 126 | mode: atomic_repository::WorkspaceTxnMode, |
| 127 | target: Option<&str>, |
| 128 | ) -> Result<(Repository, atomic_repository::WorkspaceTxn), Status> { |
| 129 | use atomic_repository::{ |
| 130 | RepositoryError, UnanchoredWorkspace, WorkspaceRemediation, WorkspaceTxnMode, |
| 131 | WorkspaceTxnStart, |
| 132 | }; |
| 133 | if mode == WorkspaceTxnMode::Force { |
| 134 | return Err(domain_status( |
| 135 | ErrorCode::InvalidArgument, |
| 136 | "service workspace entry cannot force reconciliation", |
| 137 | )); |
| 138 | } |
| 139 | let deadline = std::time::Instant::now() + database_open_wait(); |
| 140 | loop { |
| 141 | let remaining = deadline.saturating_duration_since(std::time::Instant::now()); |
| 142 | if mode == WorkspaceTxnMode::Reconcile { |
| 143 | if let Some(remediation) = Repository::preflight_workspace_boundary(&self.root) |
| 144 | .map_err(repository_error)? |
| 145 | { |
| 146 | let retry_completed_switch = matches!( |
| 147 | &remediation, |
| 148 | WorkspaceRemediation::Unanchored { |
| 149 | state: UnanchoredWorkspace::AtomicCheckpointDrift { desired_view, .. }, |
| 150 | .. |
| 151 | } if target == Some(desired_view.as_str()) |
| 152 | ); |
| 153 | if !retry_completed_switch { |
| 154 | return Err(domain_status( |
| 155 | ErrorCode::PreconditionFailed, |
| 156 | format!("workspace reconciliation required: {}\nInspect with 'atomic status --no-reconcile'; then run 'atomic git shim reconcile' before retrying.", remediation.describe()), |
| 157 | )); |
| 158 | } |
| 159 | } |
| 160 | } |
| 161 | let mut repo = match mode { |
| 162 | WorkspaceTxnMode::Observe => Repository::open_readonly_wait(&self.root, remaining), |
| 163 | WorkspaceTxnMode::Reconcile => { |
| 164 | Repository::open_for_workspace_transaction_wait(&self.root, remaining) |
| 165 | } |
| 166 | WorkspaceTxnMode::Force => unreachable!(), |
| 167 | } |
| 168 | .map_err(repository_error)?; |
| 169 | let start = repo |
| 170 | .begin_workspace_txn(mode) |
| 171 | .and_then(|start| match start { |
| 172 | WorkspaceTxnStart::Remediation(WorkspaceRemediation::Unanchored { |
| 173 | state: |
| 174 | UnanchoredWorkspace::AtomicCheckpointDrift { |
| 175 | ref desired_view, .. |
| 176 | }, |
| 177 | .. |
| 178 | }) if mode == WorkspaceTxnMode::Reconcile |
| 179 | && target == Some(desired_view.as_str()) => |
| 180 | { |
| 181 | repo.begin_workspace_txn(WorkspaceTxnMode::Force) |
no test coverage detected