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

Method import_skeleton

atomic-core/src/pristine/slice.rs:512–563  ·  view source on GitHub ↗

Replace the tree tables with `slice`'s, keeping inodes this cache allocated itself (at or above [`LOCAL_INODE_FLOOR`]); add its ids.

(&mut self, slice: &GraphSlice)

Source from the content-addressed store, hash-verified

510 /// Replace the tree tables with `slice`'s, keeping inodes this cache
511 /// allocated itself (at or above [`LOCAL_INODE_FLOOR`]); add its ids.
512 pub fn import_skeleton(&mut self, slice: &GraphSlice) -> PristineResult<()> {
513 let local = |inode: u64| inode >= LOCAL_INODE_FLOOR;
514 // A path the cache added itself that the repository now has (its
515 // change landed) is the repository's inode from here on.
516 let arrived: std::collections::HashSet<&str> =
517 slice.tree.iter().map(|(path, _)| path.as_str()).collect();
518 let mut superseded = BTreeSet::new();
519 for row in self.txn.open_table(REV_TREE)?.iter()? {
520 let (inode, path) = row?;
521 if local(inode.value()) && arrived.contains(path.value()) {
522 superseded.insert(inode.value());
523 }
524 }
525 let local = |inode: u64| local(inode) && !superseded.contains(&inode);
526 {
527 let mut tree = self.txn.open_table(TREE)?;
528 tree.retain(|_, inode| local(inode))?;
529 for (path, inode) in &slice.tree {
530 tree.insert(path.as_str(), *inode)?;
531 }
532 }
533 {
534 let mut rev_tree = self.txn.open_table(REV_TREE)?;
535 rev_tree.retain(|inode, _| local(inode))?;
536 for (inode, path) in &slice.rev_tree {
537 rev_tree.insert(*inode, path.as_str())?;
538 }
539 }
540 {
541 let mut inodes = self.txn.open_table(INODES)?;
542 inodes.retain(|inode, _| local(inode))?;
543 let mut rev = self.txn.open_table(REV_INODES)?;
544 rev.retain(|_, inode| local(inode))?;
545 for (inode, pos) in &slice.inodes {
546 inodes.insert(*inode, pos)?;
547 rev.insert(pos, *inode)?;
548 }
549 }
550 {
551 let mut dirs = self.txn.open_table(DIRECTORIES)?;
552 dirs.retain(|inode, _| local(inode))?;
553 for (inode, flags) in &slice.directories {
554 dirs.insert(*inode, *flags)?;
555 }
556 }
557 self.import_ids(&slice.ids)?;
558 // From here on this cache's own inodes (`atomic add`) come from above
559 // the floor, clear of every inode the repository has or will hand out.
560 self.next_inode
561 .fetch_max(LOCAL_INODE_FLOOR, std::sync::atomic::Ordering::SeqCst);
562 Ok(())
563 }
564
565 /// Drop every graph, CRDT and conflict row, then write `slice`'s.
566 /// Conflicts are written for `view_id`.

Callers 1

Calls 7

valueMethod · 0.80
import_idsMethod · 0.80
collectMethod · 0.45
iterMethod · 0.45
as_strMethod · 0.45
containsMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected