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

Function apply_delete

atomic-core/src/crdt/apply/leaf.rs:224–250  ·  view source on GitHub ↗

Applies a Delete operation to mark a token as deleted. # Behavior 1. Verifies the leaf exists 2. Verifies the leaf is not already deleted 3. Updates the leaf's state to Deleted Note: The leaf entry remains in the database (tombstone). # Errors - `LeafNotFound` - The leaf doesn't exist - `InvalidLeafState` - The leaf is already deleted

(
    txn: &mut T,
    context: &mut ApplyContext,
    leaf_id: LeafId,
)

Source from the content-addressed store, hash-verified

222/// - `LeafNotFound` - The leaf doesn't exist
223/// - `InvalidLeafState` - The leaf is already deleted
224fn apply_delete<T: MutCrdtTxnT>(
225 txn: &mut T,
226 context: &mut ApplyContext,
227 leaf_id: LeafId,
228) -> ApplyResult<()> {
229 // Verify leaf exists
230 let leaf = txn
231 .get_leaf(leaf_id)
232 .map_err(|e| storage_err(e, "getting leaf"))?
233 .ok_or_else(|| ApplyError::leaf_not_found(leaf_id))?;
234
235 // Check current state
236 if leaf.state().is_deleted() {
237 if context.options().allow_duplicate_ids() {
238 context.record_skipped();
239 return Ok(());
240 }
241 return Err(ApplyError::invalid_leaf_state(leaf_id, "deleted", "delete"));
242 }
243
244 // Update state to deleted
245 txn.update_leaf_state(leaf_id, LeafState::Deleted)
246 .map_err(|e| storage_err(e, "updating leaf state"))?;
247
248 context.record_leaf_deleted();
249 Ok(())
250}
251
252// Replace Operation
253

Callers 1

apply_leaf_opFunction · 0.70

Calls 9

storage_errFunction · 0.85
allow_duplicate_idsMethod · 0.80
record_leaf_deletedMethod · 0.80
get_leafMethod · 0.45
is_deletedMethod · 0.45
stateMethod · 0.45
optionsMethod · 0.45
record_skippedMethod · 0.45
update_leaf_stateMethod · 0.45

Tested by

no test coverage detected