From 5d0189227446accf97f9effdab2221a34f4d2c8f Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Sat, 17 Aug 2024 12:43:23 +0300 Subject: refactor(tvix/castore): add `name` back to edge weights 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 Autosubmit: flokli Tested-by: BuildkiteCI --- .../src/directoryservice/directory_graph.rs | 33 ++++++++++++++-------- 1 file changed, 22 insertions(+), 11 deletions(-) (limited to 'tvix/castore') 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 { // // 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>, + graph: DiGraph, Option>, // A lookup table from directory digest to node index. digest_to_node_ix: HashMap, @@ -64,18 +67,18 @@ pub struct DirectoryGraph { } pub struct ValidatedDirectoryGraph { - graph: DiGraph, Option>, + graph: DiGraph, Option>, root: Option, } -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 DirectoryGraph { 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 DirectoryGraph { .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 -- cgit 1.4.1