Index a registered change under the same transaction as its namespace and view publication. Root inode bindings must come from the namespace writer. The caller must abort the transaction if this function returns an error.
(
txn: &mut WriteTxn<'_>,
store: &S,
view_name: &str,
hash: Hash,
change: &Change,
root_inodes: &BTreeMap<u32, Inode>,
)
| 54 | /// view publication. Root inode bindings must come from the namespace writer. |
| 55 | /// The caller must abort the transaction if this function returns an error. |
| 56 | pub fn index_change<S: ChangeStore>( |
| 57 | txn: &mut WriteTxn<'_>, |
| 58 | store: &S, |
| 59 | view_name: &str, |
| 60 | hash: Hash, |
| 61 | change: &Change, |
| 62 | root_inodes: &BTreeMap<u32, Inode>, |
| 63 | ) -> Result<()> { |
| 64 | ensure!(change.hash()? == hash, "change/hash mismatch"); |
| 65 | let patch = change |
| 66 | .hashed |
| 67 | .span |
| 68 | .as_ref() |
| 69 | .context("typed span section missing")?; |
| 70 | patch.validate_content_ranges(change.contents.len().try_into()?)?; |
| 71 | let id = txn |
| 72 | .get_internal(&hash)? |
| 73 | .context("change is not registered")?; |
| 74 | ensure!( |
| 75 | txn.get_external(id)? == Some(hash), |
| 76 | "change identity mismatch" |
| 77 | ); |
| 78 | let view = txn.get_view(view_name)?.context("view not found")?; |
| 79 | let visible = |
| 80 | EffectiveProjectionClosure::try_from_membership(txn, &txn.view_membership_set(&view)?)?; |
| 81 | let mut dep_ids = Vec::new(); |
| 82 | for dep in change.dependencies() { |
| 83 | let dep_id = txn.get_internal(dep)?.context("missing dependency")?; |
| 84 | ensure!(visible.contains(dep_id), "dependency outside target view"); |
| 85 | dep_ids.push(dep_id); |
| 86 | } |
| 87 | let dependencies = EffectiveProjectionClosure::try_from_membership( |
| 88 | txn, |
| 89 | &ViewMembershipSet::from_ordered(dep_ids), |
| 90 | )?; |
| 91 | validate_projected_semantics(txn, store, change, &dependencies)?; |
| 92 | let already = txn.txn.open_table(APPLIED)?.get(id.get())?.is_some(); |
| 93 | if already { |
| 94 | return Ok(()); |
| 95 | } |
| 96 | |
| 97 | let mut ordinals = BTreeSet::new(); |
| 98 | let mut inodes = BTreeSet::new(); |
| 99 | for op in &patch.ops { |
| 100 | match op { |
| 101 | SpanOp::Root { |
| 102 | ordinal, |
| 103 | start, |
| 104 | end, |
| 105 | .. |
| 106 | } => { |
| 107 | let inode = *root_inodes.get(ordinal).context("missing root inode")?; |
| 108 | ensure!(ordinals.insert(*ordinal), "duplicate root ordinal"); |
| 109 | ensure!(inodes.insert(inode.get()), "multiple roots for inode"); |
| 110 | ensure!(*start <= *end, "reversed root"); |
| 111 | ensure!( |
| 112 | txn.txn.open_table(ROOTS)?.get(inode.get())?.is_none(), |
| 113 | "root already exists" |