diff options
author | Florian Klink <flokli@flokli.de> | 2024-08-17T09·43+0300 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2024-08-17T15·59+0000 |
commit | 5d0189227446accf97f9effdab2221a34f4d2c8f (patch) | |
tree | 30c255f844771f902ccd7a7e5d58a5ec66d172d4 /tvix/castore/src | |
parent | 21ceef4934b28a0c3a4f6faa2035021dfe8b3c3d (diff) |
refactor(tvix/castore): add `name` back to edge weights r/8508
Make this a proper struct with named fields. We apparently never access B3Digest in there, so it can be removed. Change-Id: Ifc07310393e1afb0a835778eae137a19b54070b9 Reviewed-on: https://cl.tvl.fyi/c/depot/+/12224 Reviewed-by: Connor Brewster <cbrewster@hey.com> Autosubmit: flokli <flokli@flokli.de> Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/castore/src')
-rw-r--r-- | tvix/castore/src/directoryservice/directory_graph.rs | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/tvix/castore/src/directoryservice/directory_graph.rs b/tvix/castore/src/directoryservice/directory_graph.rs index 3c2d54702973..d8d8e7370510 100644 --- a/tvix/castore/src/directoryservice/directory_graph.rs +++ b/tvix/castore/src/directoryservice/directory_graph.rs @@ -16,7 +16,10 @@ pub enum Error { ValidationError(String), } -type Edge = (B3Digest, u64); +struct EdgeWeight { + name: PathComponent, + size: u64, +} /// This can be used to validate and/or re-order a Directory closure (DAG of /// connected Directories), and their insertion order. @@ -55,7 +58,7 @@ pub struct DirectoryGraph<O> { // // The option in the edge weight tracks the pending validation state of the respective edge, for example if // the child has not been added yet. - graph: DiGraph<Option<Directory>, Option<Edge>>, + graph: DiGraph<Option<Directory>, Option<EdgeWeight>>, // A lookup table from directory digest to node index. digest_to_node_ix: HashMap<B3Digest, NodeIndex>, @@ -64,18 +67,18 @@ pub struct DirectoryGraph<O> { } pub struct ValidatedDirectoryGraph { - graph: DiGraph<Option<Directory>, Option<Edge>>, + graph: DiGraph<Option<Directory>, Option<EdgeWeight>>, root: Option<NodeIndex>, } -fn check_edge(dir: &Edge, dir_name: &PathComponent, child: &Directory) -> Result<(), Error> { +fn check_edge(edge: &EdgeWeight, child: &Directory) -> Result<(), Error> { // Ensure the size specified in the child node matches our records. - if dir.1 != child.size() { + if edge.size != child.size() { return Err(Error::ValidationError(format!( "'{}' has wrong size, specified {}, recorded {}", - dir_name, - dir.1, + edge.name, + edge.size, child.size(), ))); } @@ -151,10 +154,19 @@ impl<O: OrderValidator> DirectoryGraph<O> { let pending_edge_check = match &self.graph[child_ix] { Some(child) => { // child is already available, validate the edge now - check_edge(&(digest.to_owned(), *size), name, child)?; + check_edge( + &EdgeWeight { + name: name.clone(), + size: *size, + }, + child, + )?; None } - None => Some((digest.to_owned(), *size)), // pending validation + None => Some(EdgeWeight { + name: name.clone(), + size: *size, + }), // pending validation }; self.graph.add_edge(ix, child_ix, pending_edge_check); } @@ -176,8 +188,7 @@ impl<O: OrderValidator> DirectoryGraph<O> { .take() .expect("edge is already validated"); - // TODO: where's the name here? - check_edge(&edge_weight, &"??".try_into().unwrap(), &directory)?; + check_edge(&edge_weight, &directory)?; } // finally, store the directory information in the node weight |