From aa7bdc1199bfbb69091dda942a82812257e30bc4 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Fri, 9 Jun 2023 18:22:25 +0300 Subject: refactor(tvix/store): use Arc instead of Box This allows us to blob services without closing them before putting them in a box. We currently need to use Arc<_>, not Rc<_>, because the GRPC wrappers require Sync. Change-Id: I679c5f06b62304f5b0456cfefe25a0a881de7c84 Reviewed-on: https://cl.tvl.fyi/c/depot/+/8738 Reviewed-by: tazjin Tested-by: BuildkiteCI Autosubmit: flokli --- tvix/store/src/store_io.rs | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'tvix/store/src/store_io.rs') diff --git a/tvix/store/src/store_io.rs b/tvix/store/src/store_io.rs index ee302f3b58ba..c35da49da998 100644 --- a/tvix/store/src/store_io.rs +++ b/tvix/store/src/store_io.rs @@ -8,7 +8,7 @@ use nix_compat::{ store_path::{build_regular_ca_path, StorePath}, }; use smol_str::SmolStr; -use std::{io, path::Path, path::PathBuf}; +use std::{io, path::Path, path::PathBuf, sync::Arc}; use tracing::{error, instrument, warn}; use tvix_eval::{EvalIO, FileType, StdIO}; @@ -30,16 +30,16 @@ use crate::{ /// on the filesystem (still managed by Nix), as well as being able to read /// files outside store paths. pub struct TvixStoreIO { - blob_service: Box, - directory_service: Box, + blob_service: Arc, + directory_service: Arc, path_info_service: PS, std_io: StdIO, } impl TvixStoreIO { pub fn new( - blob_service: Box, - directory_service: Box, + blob_service: Arc, + directory_service: Arc, path_info_service: PS, ) -> Self { Self { @@ -86,7 +86,7 @@ impl TvixStoreIO { } }; - directoryservice::traverse_to(&self.directory_service, root_node, sub_path) + directoryservice::traverse_to(self.directory_service.clone(), root_node, sub_path) } /// Imports a given path on the filesystem into the store, and returns the @@ -100,13 +100,20 @@ impl TvixStoreIO { path: &std::path::Path, ) -> Result { // Call [import::ingest_path], which will walk over the given path and return a root_node. - let root_node = import::ingest_path(&self.blob_service, &self.directory_service, path) - .expect("error during import_path"); + let root_node = import::ingest_path( + self.blob_service.clone(), + self.directory_service.clone(), + path, + ) + .expect("error during import_path"); // Render the NAR - let (nar_size, nar_sha256) = - calculate_size_and_sha256(&root_node, &self.blob_service, &self.directory_service) - .expect("error during nar calculation"); // TODO: handle error + let (nar_size, nar_sha256) = calculate_size_and_sha256( + &root_node, + self.blob_service.clone(), + self.directory_service.clone(), + ) + .expect("error during nar calculation"); // TODO: handle error // For given NAR sha256 digest and name, return the new [StorePath] this would have. let nar_hash_with_mode = -- cgit 1.4.1