MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / index_change

Function index_change

atomic-core/src/pristine/span_patch_storage.rs:56–257  ·  view source on GitHub ↗

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>,
)

Source from the content-addressed store, hash-verified

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.
56pub 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"

Callers 4

add_changeFunction · 0.85
newMethod · 0.85

Calls 15

wordsFunction · 0.85
file_keyFunction · 0.85
span_keyFunction · 0.85
as_refMethod · 0.80
view_membership_setMethod · 0.80
getMethod · 0.65
contextMethod · 0.45
lenMethod · 0.45
get_internalMethod · 0.45
get_viewMethod · 0.45

Tested by 1

newMethod · 0.68