(
&mut self,
working_copy: WorkingCopyId,
view: &str,
kind: OperationKind,
relation: Option<OperationRelation>,
actor: ActorRef,
expected_head:
| 495 | } |
| 496 | |
| 497 | pub(super) fn switch_view_with_operation( |
| 498 | &mut self, |
| 499 | working_copy: WorkingCopyId, |
| 500 | view: &str, |
| 501 | kind: OperationKind, |
| 502 | relation: Option<OperationRelation>, |
| 503 | actor: ActorRef, |
| 504 | expected_head: Option<atomic_core::OperationId>, |
| 505 | ) -> Result<MaterializeResult, RepositoryError> { |
| 506 | let operation_lock = self.try_lock_operation(working_copy)?; |
| 507 | self.recover_pending_deferred_tree_alignment_locked(&operation_lock)?; |
| 508 | if let super::operation::OperationHeadState::Diverged(heads) = |
| 509 | self.consolidate_operation_heads_locked(&operation_lock)? |
| 510 | { |
| 511 | return Err(RepositoryError::OperationHeadsDiverged { |
| 512 | scope: OperationScope::WorkingCopy(working_copy).to_string(), |
| 513 | heads: heads.iter().map(ToString::to_string).collect(), |
| 514 | }); |
| 515 | } |
| 516 | self.recover_incomplete_operation(&operation_lock)?; |
| 517 | if let Some(expected_head) = expected_head { |
| 518 | let actual_head = |
| 519 | self.sole_operation_head(OperationScope::WorkingCopy(working_copy))?; |
| 520 | if actual_head != expected_head { |
| 521 | return Err(RepositoryError::InvalidOperation { |
| 522 | message: format!( |
| 523 | "operation head changed before inverse switch: expected {expected_head}, found {actual_head}" |
| 524 | ), |
| 525 | }); |
| 526 | } |
| 527 | } |
| 528 | |
| 529 | match self.switch_view_journaled( |
| 530 | &operation_lock, |
| 531 | working_copy, |
| 532 | view, |
| 533 | kind, |
| 534 | relation, |
| 535 | actor, |
| 536 | ) { |
| 537 | Ok(result) => Ok(result), |
| 538 | Err(operation_error) => match self.recover_incomplete_operation(&operation_lock) { |
| 539 | Ok(_) => Err(operation_error), |
| 540 | Err(recovery_error) => Err(RepositoryError::InvalidOperation { |
| 541 | message: format!( |
| 542 | "switch failed ({operation_error}); lease-safe recovery also failed ({recovery_error})" |
| 543 | ), |
| 544 | }), |
| 545 | }, |
| 546 | } |
| 547 | } |
| 548 | fn switch_view_journaled( |
| 549 | &mut self, |
| 550 | operation_lock: &super::locks::WorkingCopyOperationLockGuard, |
no test coverage detected