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

Function commit_migration

atomic-repository/src/repository/migration.rs:406–569  ·  view source on GitHub ↗
(path: &Path, plan: MigrationPlan)

Source from the content-addressed store, hash-verified

404}
405
406fn commit_migration(path: &Path, plan: MigrationPlan) -> Result<(), RepositoryError> {
407 let db = redb::Builder::new()
408 .set_cache_size(8 * 1024 * 1024 * 1024)
409 .open(path)
410 .map_err(|error| RepositoryError::Database(error.to_string()))?;
411 let write = db
412 .begin_write()
413 .map_err(|error| RepositoryError::Database(error.to_string()))?;
414
415 {
416 let mut inodes = write
417 .open_table(INODES)
418 .map_err(|error| RepositoryError::Database(error.to_string()))?;
419 let mut reverse = write
420 .open_table(REV_INODES)
421 .map_err(|error| RepositoryError::Database(error.to_string()))?;
422 for (inode, position) in &plan.recovered_inodes {
423 let encoded = encode_position(position.change.get(), position.pos.get());
424 let existing_position = inodes
425 .get(inode.get())
426 .map_err(|error| RepositoryError::Database(error.to_string()))?
427 .map(|value| *value.value());
428 if existing_position.is_some_and(|existing| existing != encoded) {
429 return Err(RepositoryError::InvalidOperation {
430 message: format!(
431 "cannot restore inode {} at {}: INODES already has another position",
432 inode.get(),
433 position
434 ),
435 });
436 }
437 let existing_inode = reverse
438 .get(&encoded)
439 .map_err(|error| RepositoryError::Database(error.to_string()))?
440 .map(|value| value.value());
441 if existing_inode.is_some_and(|existing| existing != inode.get()) {
442 return Err(RepositoryError::InvalidOperation {
443 message: format!(
444 "cannot restore inode {} at {}: REV_INODES already has inode {}",
445 inode.get(),
446 position,
447 existing_inode.unwrap()
448 ),
449 });
450 }
451 inodes
452 .insert(inode.get(), &encoded)
453 .map_err(|error| RepositoryError::Database(error.to_string()))?;
454 reverse
455 .insert(&encoded, inode.get())
456 .map_err(|error| RepositoryError::Database(error.to_string()))?;
457 }
458 }
459
460 let claim_paths = {
461 let table = write
462 .open_multimap_table(PATH_CLAIMS)
463 .map_err(|error| RepositoryError::Database(error.to_string()))?;

Callers 1

Calls 14

encode_positionFunction · 0.85
encode_path_claim_eventFunction · 0.85
validate_raw_bijectionFunction · 0.85
record_migrationFunction · 0.85
begin_writeMethod · 0.80
valueMethod · 0.80
getMethod · 0.65
removeMethod · 0.65
openMethod · 0.45
insertMethod · 0.45
iterMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected