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

Function index_change

atomic-core/src/pristine/span_patch_storage.rs:122–361  ·  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

120/// view publication. Root inode bindings must come from the namespace writer.
121/// The caller must abort the transaction if this function returns an error.
122pub fn index_change<S: ChangeStore>(
123 txn: &mut WriteTxn<'_>,
124 store: &S,
125 view_name: &str,
126 hash: Hash,
127 change: &Change,
128 root_inodes: &BTreeMap<u32, Inode>,
129) -> Result<()> {
130 let verified = store.get_verified_change(&hash)?;
131 verified.check_hash(&hash)?;
132 ensure!(
133 verified.change().hashed == change.hashed && verified.change().contents == change.contents,
134 "change differs from its verified original encoding"
135 );
136 let patch = change
137 .hashed
138 .span
139 .as_ref()
140 .context("typed span section missing")?;
141 patch.validate_content_ranges(change.contents.len().try_into()?)?;
142 let id = txn
143 .get_internal(&hash)?
144 .context("change is not registered")?;
145 ensure!(
146 txn.get_external(id)? == Some(hash),
147 "change identity mismatch"
148 );
149 let view = txn.get_view(view_name)?.context("view not found")?;
150 let visible =
151 EffectiveProjectionClosure::try_from_membership(txn, &txn.view_membership_set(&view)?)?;
152 let mut dep_ids = Vec::new();
153 for dep in change.dependencies() {
154 let dep_id = txn.get_internal(dep)?.context("missing dependency")?;
155 ensure!(visible.contains(dep_id), "dependency outside target view");
156 dep_ids.push(dep_id);
157 }
158 let dependencies = EffectiveProjectionClosure::try_from_membership(
159 txn,
160 &ViewMembershipSet::from_ordered(dep_ids),
161 )?;
162 prepare_legacy_files(txn, store, change)?;
163 validate_projected_semantics(txn, store, change, &dependencies)?;
164 let already = txn.txn.open_table(APPLIED)?.get(id.get())?.is_some();
165 if already {
166 return Ok(());
167 }
168
169 let mut ordinals = BTreeSet::new();
170 let mut inodes = BTreeSet::new();
171 for op in &patch.ops {
172 match op {
173 SpanOp::Root {
174 ordinal,
175 start,
176 end,
177 ..
178 } => {
179 let inode = *root_inodes.get(ordinal).context("missing root inode")?;

Callers 4

add_changeFunction · 0.85
newMethod · 0.85

Calls 15

prepare_legacy_filesFunction · 0.85
wordsFunction · 0.85
file_keyFunction · 0.85
span_keyFunction · 0.85
check_hashMethod · 0.80
as_refMethod · 0.80
view_membership_setMethod · 0.80
is_noneMethod · 0.80
legacy_record_stateMethod · 0.80
getMethod · 0.65
metadataFunction · 0.50

Tested by 1

newMethod · 0.68