From 639ee1910180d8e69787b85d6ab0034ede7e2a07 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Fri, 12 Jan 2024 15:28:48 +0200 Subject: refactor(tvix/glue/tvix_store_io): async store_path_to_node Provide a store_path_to_node_sync function which uses the runtime handle to block on the async function internally, but make store_path_to_node itself async, so it can call async functions internally. We'll use that later when triggering builds and waiting on their results. Change-Id: Idae9da7aa5b0878e0d3a2eba34ea2623e1ba84b2 Reviewed-on: https://cl.tvl.fyi/c/depot/+/10607 Tested-by: BuildkiteCI Autosubmit: flokli Reviewed-by: raitobezarius --- tvix/glue/src/tvix_store_io.rs | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) (limited to 'tvix/glue/src/tvix_store_io.rs') diff --git a/tvix/glue/src/tvix_store_io.rs b/tvix/glue/src/tvix_store_io.rs index 178bf6c777..251023ba3e 100644 --- a/tvix/glue/src/tvix_store_io.rs +++ b/tvix/glue/src/tvix_store_io.rs @@ -60,20 +60,16 @@ where /// In case there is no PathInfo yet, this means we need to build it /// (which currently is stubbed out still). #[instrument(skip(self), ret, err)] - fn store_path_to_node( + async fn store_path_to_node( &self, store_path: &StorePath, sub_path: &Path, ) -> io::Result> { let root_node = match self - .tokio_handle - .block_on(async { - self.path_info_service - .as_ref() - .get(*store_path.digest()) - .await - }) - .unwrap() + .path_info_service + .as_ref() + .get(*store_path.digest()) + .await? { // if we have a PathInfo, we know there will be a root_node (due to validation) Some(path_info) => path_info.node.expect("no node").node.expect("no node"), @@ -90,11 +86,18 @@ where }; // with the root_node and sub_path, descend to the node requested. - Ok(self.tokio_handle.block_on({ - async { - directoryservice::descend_to(&self.directory_service, root_node, sub_path).await - } - })?) + directoryservice::descend_to(&self.directory_service, root_node, sub_path) + .await + .map_err(|e| std::io::Error::new(io::ErrorKind::Other, e)) + } + + fn store_path_to_node_sync( + &self, + store_path: &StorePath, + sub_path: &Path, + ) -> io::Result> { + self.tokio_handle + .block_on(async { self.store_path_to_node(store_path, sub_path).await }) } } @@ -109,7 +112,10 @@ where if let Ok((store_path, sub_path)) = StorePath::from_absolute_path_full(&path.to_string_lossy()) { - if self.store_path_to_node(&store_path, &sub_path)?.is_some() { + if self + .store_path_to_node_sync(&store_path, &sub_path)? + .is_some() + { Ok(true) } else { // As tvix-store doesn't manage /nix/store on the filesystem, @@ -127,7 +133,7 @@ where if let Ok((store_path, sub_path)) = StorePath::from_absolute_path_full(&path.to_string_lossy()) { - if let Some(node) = self.store_path_to_node(&store_path, &sub_path)? { + if let Some(node) = self.store_path_to_node_sync(&store_path, &sub_path)? { // depending on the node type, treat read_to_string differently match node { Node::Directory(_) => { @@ -195,7 +201,7 @@ where if let Ok((store_path, sub_path)) = StorePath::from_absolute_path_full(&path.to_string_lossy()) { - if let Some(node) = self.store_path_to_node(&store_path, &sub_path)? { + if let Some(node) = self.store_path_to_node_sync(&store_path, &sub_path)? { match node { Node::Directory(directory_node) => { // fetch the Directory itself. -- cgit 1.4.1