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

Method from_table

atomic-core/src/pristine/txn/read.rs:2538–2584  ·  view source on GitHub ↗

Pre-load using an already-opened INODE_GRAPH table handle. This avoids the per-file `open_multimap_table` overhead when processing many files in parallel — the caller opens the table once and passes the handle to each file's preloader.

(
        txn: &'txn ReadTxn,
        inode: Inode,
        table: &redb::ReadOnlyMultimapTable<&'static [u8; 32], &'static [u8; 24]>,
    )

Source from the content-addressed store, hash-verified

2536 /// processing many files in parallel — the caller opens the table
2537 /// once and passes the handle to each file's preloader.
2538 pub fn from_table(
2539 txn: &'txn ReadTxn,
2540 inode: Inode,
2541 table: &redb::ReadOnlyMultimapTable<&'static [u8; 32], &'static [u8; 24]>,
2542 ) -> PristineResult<Self> {
2543 let inode_id = inode.get();
2544 let start_key = encode_inode_vertex(inode_id, 0, 0, 0);
2545 let end_key = encode_inode_vertex(inode_id, u64::MAX, u64::MAX, u64::MAX);
2546
2547 let mut edges: std::collections::HashMap<GraphNode<NodeId>, Vec<SerializedGraphEdge>> =
2548 std::collections::HashMap::new();
2549 let mut vertex_set: std::collections::HashSet<GraphNode<NodeId>> =
2550 std::collections::HashSet::new();
2551
2552 for result in table.range::<&[u8; 32]>(&start_key..=&end_key)? {
2553 let (key, values) = result?;
2554 let (_, v_change, v_start, v_end) = decode_inode_vertex(key.value());
2555
2556 let vertex = GraphNode {
2557 change: NodeId::new(v_change),
2558 start: ChangePosition::new(v_start),
2559 end: ChangePosition::new(v_end),
2560 };
2561 vertex_set.insert(vertex);
2562
2563 let edge_list = collect_preload_edges(values, |value| {
2564 let bytes: &[u8; 24] = value.value();
2565 deserialize_edge(bytes)
2566 })?;
2567 edges.entry(vertex).or_default().extend(edge_list);
2568 }
2569
2570 let mut vertices: Vec<GraphNode<NodeId>> = vertex_set.into_iter().collect();
2571 vertices.sort_by(|a, b| {
2572 a.change
2573 .get()
2574 .cmp(&b.change.get())
2575 .then(a.start.get().cmp(&b.start.get()))
2576 .then(a.end.get().cmp(&b.end.get()))
2577 });
2578
2579 Ok(Self {
2580 txn,
2581 edges,
2582 vertices,
2583 })
2584 }
2585
2586 /// Whether any pre-loaded edge for this inode is a DELETED edge whose
2587 /// introducing change is in the validated visibility closure.

Callers

nothing calls this directly

Calls 11

encode_inode_vertexFunction · 0.85
decode_inode_vertexFunction · 0.85
collect_preload_edgesFunction · 0.85
extendMethod · 0.80
deserialize_edgeFunction · 0.70
getMethod · 0.65
valueMethod · 0.45
insertMethod · 0.45
collectMethod · 0.45
into_iterMethod · 0.45
cmpMethod · 0.45

Tested by

no test coverage detected