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

Function apply_restore

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

Applies a Restore operation to restore a deleted token. # Behavior 1. Verifies the leaf exists 2. Verifies the leaf is currently deleted 3. Updates the leaf's state to Alive # Errors - `LeafNotFound` - The leaf doesn't exist - `InvalidLeafState` - The leaf is not deleted

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

Source from the content-addressed store, hash-verified

313/// - `LeafNotFound` - The leaf doesn't exist
314/// - `InvalidLeafState` - The leaf is not deleted
315fn apply_restore<T: MutCrdtTxnT>(
316 txn: &mut T,
317 context: &mut ApplyContext,
318 leaf_id: LeafId,
319) -> ApplyResult<()> {
320 // Verify leaf exists
321 let leaf = txn
322 .get_leaf(leaf_id)
323 .map_err(|e| storage_err(e, "getting leaf"))?
324 .ok_or_else(|| ApplyError::leaf_not_found(leaf_id))?;
325
326 // Check current state
327 if !leaf.state().is_deleted() {
328 if context.options().allow_duplicate_ids() {
329 context.record_skipped();
330 return Ok(());
331 }
332 return Err(ApplyError::invalid_leaf_state(leaf_id, "alive", "restore"));
333 }
334
335 // Update state to alive
336 txn.update_leaf_state(leaf_id, LeafState::Alive)
337 .map_err(|e| storage_err(e, "updating leaf state"))?;
338
339 context.record_leaf_restored();
340 Ok(())
341}
342
343// Validation Helpers
344

Callers 1

apply_leaf_opFunction · 0.70

Calls 9

storage_errFunction · 0.85
allow_duplicate_idsMethod · 0.80
record_leaf_restoredMethod · 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