Simulate the entire closure in an aborted transaction before preparing any operation. This validates incoming indexes and the prospective render without publishing a partial multi-change insertion.
(
&self,
view_name: &str,
roots: &[Hash],
require_existing_dependencies: bool,
)
| 59 | // any operation. This validates incoming indexes and the prospective |
| 60 | // render without publishing a partial multi-change insertion. |
| 61 | fn preflight_span_references( |
| 62 | &self, |
| 63 | view_name: &str, |
| 64 | roots: &[Hash], |
| 65 | require_existing_dependencies: bool, |
| 66 | ) -> Result<(), RepositoryError> { |
| 67 | use atomic_core::change::span_patch::{ExternalFile, SpanOp}; |
| 68 | use atomic_core::pristine::span_patch_storage::{SpanPatchReadTxn, SpanRenderContext}; |
| 69 | use atomic_core::pristine::{CapabilityTxnT, PathClaimMutTxnT, SPAN_RANGE_CAPABILITY}; |
| 70 | let mut txn = self |
| 71 | .pristine |
| 72 | .write_txn() |
| 73 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 74 | txn.enable_abort_only_allocations() |
| 75 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 76 | txn.get_view(view_name) |
| 77 | .map_err(|e| RepositoryError::Database(e.to_string()))? |
| 78 | .ok_or_else(|| RepositoryError::ViewNotFound { |
| 79 | name: view_name.to_string(), |
| 80 | })?; |
| 81 | if require_existing_dependencies { |
| 82 | for hash in roots { |
| 83 | let change = self.load_change(hash)?; |
| 84 | for dep in change.dependencies() { |
| 85 | let id = txn |
| 86 | .get_internal(dep) |
| 87 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 88 | if !matches!(id, Some(id) if txn.was_change_applied(id).map_err(|e| RepositoryError::Database(e.to_string()))?) |
| 89 | { |
| 90 | return Err(RepositoryError::Apply(format!( |
| 91 | "missing applied dependency {}", |
| 92 | dep.to_base32() |
| 93 | ))); |
| 94 | } |
| 95 | } |
| 96 | } |
| 97 | } |
| 98 | let mut stack: Vec<_> = roots.iter().rev().map(|hash| (*hash, false)).collect(); |
| 99 | let mut active = HashSet::new(); |
| 100 | let mut done = HashSet::new(); |
| 101 | let mut ordered = Vec::new(); |
| 102 | while let Some((hash, expanded)) = stack.pop() { |
| 103 | if expanded { |
| 104 | active.remove(&hash); |
| 105 | if done.insert(hash) { |
| 106 | ordered.push(hash); |
| 107 | } |
| 108 | continue; |
| 109 | } |
| 110 | if done.contains(&hash) { |
| 111 | continue; |
| 112 | } |
| 113 | if !active.insert(hash) { |
| 114 | return Err(RepositoryError::Apply("cyclic change dependency".into())); |
| 115 | } |
| 116 | // A change's identity is the hash of its stored encoding. One |
| 117 | // recorded before file-header version 2 gets a different hash when |
| 118 | // the current writer re-encodes it, so the stored bytes are what |
no test coverage detected