From 4c062d5c9242d9c63e104e58db52ee780e0eefa6 Mon Sep 17 00:00:00 2001 From: Yureka Date: Thu, 16 May 2024 22:44:23 +0200 Subject: fix(castore/directory/objectstore): fix responses for deduplicated dirs Using remove_node messed up the extraction of nodes from the graph. Use into_nodes_edges() instead, to remove the nodes without cloning. Change-Id: Id76c7935d082d6f26192cc3cd490483594f1d1e2 Reviewed-on: https://cl.tvl.fyi/c/depot/+/11684 Tested-by: BuildkiteCI Autosubmit: yuka Reviewed-by: flokli --- .../src/directoryservice/closure_validator.rs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'tvix/castore/src/directoryservice/closure_validator.rs') diff --git a/tvix/castore/src/directoryservice/closure_validator.rs b/tvix/castore/src/directoryservice/closure_validator.rs index 6281d24702..b9746a5a05 100644 --- a/tvix/castore/src/directoryservice/closure_validator.rs +++ b/tvix/castore/src/directoryservice/closure_validator.rs @@ -141,20 +141,26 @@ impl ClosureValidator { /// In case no elements have been inserted, returns an empty list. #[instrument(level = "trace", skip_all, err)] pub(crate) fn finalize_root_to_leaves(self) -> Result, Error> { - let (mut graph, root) = match self.finalize_raw()? { + let (graph, root) = match self.finalize_raw()? { None => return Ok(vec![]), Some(v) => v, }; // do a BFS traversal of the graph, starting with the root node to get - // (the count of) all nodes reachable from there. + // all nodes reachable from there. let traversal = Bfs::new(&graph, root); - Ok(traversal - .iter(&graph) - .collect::>() - .into_iter() - .filter_map(|i| graph.remove_node(i)) + let order = traversal.iter(&graph).collect::>(); + + let (nodes, _edges) = graph.into_nodes_edges(); + + // Convert to option, so that we can take individual nodes out without messing up the + // indices + let mut nodes = nodes.into_iter().map(Some).collect::>(); + + Ok(order + .iter() + .map(|i| nodes[i.index()].take().unwrap().weight) .collect()) } -- cgit 1.4.1