From b5e37869e6ddddf0575bdc98e0f4cc05753f0fc0 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Mon, 12 Jun 2023 16:04:56 +0300 Subject: refactor(tvix/store/pathinfosvc): use Arc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This removes the use of generics, like previously done with Blob and Directory services. Change-Id: I7cc8bd1439b026c88e80c11e38aafc63c74e5e84 Reviewed-on: https://cl.tvl.fyi/c/depot/+/8751 Tested-by: BuildkiteCI Autosubmit: flokli Reviewed-by: tazjin --- tvix/store/src/bin/tvix-store.rs | 9 +++++---- tvix/store/src/fuse/mod.rs | 10 +++++----- tvix/store/src/pathinfoservice/mod.rs | 2 +- tvix/store/src/proto/grpc_pathinfoservice_wrapper.rs | 13 ++++++------- tvix/store/src/proto/tests/grpc_pathinfoservice.rs | 8 ++++++-- tvix/store/src/store_io.rs | 10 +++++----- tvix/store/src/tests/utils.rs | 4 ++-- 7 files changed, 30 insertions(+), 26 deletions(-) (limited to 'tvix/store/src') diff --git a/tvix/store/src/bin/tvix-store.rs b/tvix/store/src/bin/tvix-store.rs index ae72559d39..b95f408a55 100644 --- a/tvix/store/src/bin/tvix-store.rs +++ b/tvix/store/src/bin/tvix-store.rs @@ -13,6 +13,7 @@ use tvix_store::directoryservice::DirectoryService; use tvix_store::directoryservice::GRPCDirectoryService; use tvix_store::directoryservice::SledDirectoryService; use tvix_store::pathinfoservice::GRPCPathInfoService; +use tvix_store::pathinfoservice::PathInfoService; use tvix_store::pathinfoservice::SledPathInfoService; use tvix_store::proto::blob_service_client::BlobServiceClient; use tvix_store::proto::blob_service_server::BlobServiceServer; @@ -104,11 +105,11 @@ async fn main() -> Result<(), Box> { Arc::new(SledBlobService::new("blobs.sled".into())?); let directory_service: Arc = Arc::new(SledDirectoryService::new("directories.sled".into())?); - let path_info_service = SledPathInfoService::new( + let path_info_service: Arc = Arc::new(SledPathInfoService::new( "pathinfo.sled".into(), blob_service.clone(), directory_service.clone(), - )?; + )?); let listen_address = listen_address .unwrap_or_else(|| "[::]:8000".to_string()) @@ -156,7 +157,7 @@ async fn main() -> Result<(), Box> { let io = Arc::new(TvixStoreIO::new( Arc::new(blob_service), Arc::new(directory_service), - path_info_service, + Arc::new(path_info_service), )); let tasks = paths @@ -193,7 +194,7 @@ async fn main() -> Result<(), Box> { let f = FUSE::new( Arc::new(blob_service), Arc::new(directory_service), - path_info_service, + Arc::new(path_info_service), ); fuser::mount2(f, &dest, &[]) }) diff --git a/tvix/store/src/fuse/mod.rs b/tvix/store/src/fuse/mod.rs index d28e2b309c..7206cf3076 100644 --- a/tvix/store/src/fuse/mod.rs +++ b/tvix/store/src/fuse/mod.rs @@ -3,17 +3,17 @@ use crate::{ }; use std::sync::Arc; -pub struct FUSE { +pub struct FUSE { blob_service: Arc, directory_service: Arc, - path_info_service: PS, + path_info_service: Arc, } -impl FUSE { +impl FUSE { pub fn new( blob_service: Arc, directory_service: Arc, - path_info_service: PS, + path_info_service: Arc, ) -> Self { Self { blob_service, @@ -23,4 +23,4 @@ impl FUSE { } } -impl fuser::Filesystem for FUSE {} +impl fuser::Filesystem for FUSE {} diff --git a/tvix/store/src/pathinfoservice/mod.rs b/tvix/store/src/pathinfoservice/mod.rs index 2483909a11..937d8f2a11 100644 --- a/tvix/store/src/pathinfoservice/mod.rs +++ b/tvix/store/src/pathinfoservice/mod.rs @@ -10,7 +10,7 @@ pub use self::sled::SledPathInfoService; /// The base trait all PathInfo services need to implement. /// This is a simple get and put of [proto::Directory], returning their digest. -pub trait PathInfoService { +pub trait PathInfoService: Send + Sync { /// Retrieve a PathInfo message by the output digest. fn get(&self, digest: [u8; 20]) -> Result, Error>; diff --git a/tvix/store/src/proto/grpc_pathinfoservice_wrapper.rs b/tvix/store/src/proto/grpc_pathinfoservice_wrapper.rs index 645f4aa605..9f26da213b 100644 --- a/tvix/store/src/proto/grpc_pathinfoservice_wrapper.rs +++ b/tvix/store/src/proto/grpc_pathinfoservice_wrapper.rs @@ -1,15 +1,16 @@ use crate::nar::RenderError; use crate::pathinfoservice::PathInfoService; use crate::proto; +use std::sync::Arc; use tonic::{async_trait, Request, Response, Result, Status}; use tracing::{instrument, warn}; -pub struct GRPCPathInfoServiceWrapper { - path_info_service: PS, +pub struct GRPCPathInfoServiceWrapper { + path_info_service: Arc, } -impl From for GRPCPathInfoServiceWrapper { - fn from(value: PS) -> Self { +impl From> for GRPCPathInfoServiceWrapper { + fn from(value: Arc) -> Self { Self { path_info_service: value, } @@ -17,9 +18,7 @@ impl From for GRPCPathInfoServiceWrapper { } #[async_trait] -impl proto::path_info_service_server::PathInfoService - for GRPCPathInfoServiceWrapper -{ +impl proto::path_info_service_server::PathInfoService for GRPCPathInfoServiceWrapper { #[instrument(skip(self))] async fn get( &self, diff --git a/tvix/store/src/proto/tests/grpc_pathinfoservice.rs b/tvix/store/src/proto/tests/grpc_pathinfoservice.rs index 8b7038ccbc..186461d165 100644 --- a/tvix/store/src/proto/tests/grpc_pathinfoservice.rs +++ b/tvix/store/src/proto/tests/grpc_pathinfoservice.rs @@ -8,6 +8,7 @@ use crate::tests::fixtures::DUMMY_OUTPUT_HASH; use crate::tests::utils::gen_blob_service; use crate::tests::utils::gen_directory_service; use crate::tests::utils::gen_pathinfo_service; +use std::sync::Arc; use tonic::Request; /// generates a GRPCPathInfoService out of blob, directory and pathinfo services. @@ -15,10 +16,13 @@ use tonic::Request; /// We only interact with it via the PathInfo GRPC interface. /// It uses the NonCachingNARCalculationService NARCalculationService to /// calculate NARs. -fn gen_grpc_service() -> impl GRPCPathInfoService { +fn gen_grpc_service() -> Arc { let blob_service = gen_blob_service(); let directory_service = gen_directory_service(); - GRPCPathInfoServiceWrapper::from(gen_pathinfo_service(blob_service, directory_service)) + Arc::new(GRPCPathInfoServiceWrapper::from(gen_pathinfo_service( + blob_service, + directory_service, + ))) } /// Trying to get a non-existent PathInfo should return a not found error. diff --git a/tvix/store/src/store_io.rs b/tvix/store/src/store_io.rs index c35da49da9..fcbc5842a3 100644 --- a/tvix/store/src/store_io.rs +++ b/tvix/store/src/store_io.rs @@ -29,18 +29,18 @@ use crate::{ /// This is to both cover cases of syntactically valid store paths, that exist /// on the filesystem (still managed by Nix), as well as being able to read /// files outside store paths. -pub struct TvixStoreIO { +pub struct TvixStoreIO { blob_service: Arc, directory_service: Arc, - path_info_service: PS, + path_info_service: Arc, std_io: StdIO, } -impl TvixStoreIO { +impl TvixStoreIO { pub fn new( blob_service: Arc, directory_service: Arc, - path_info_service: PS, + path_info_service: Arc, ) -> Self { Self { blob_service, @@ -179,7 +179,7 @@ fn calculate_nar_based_store_path(nar_sha256_digest: &[u8; 32], name: &str) -> S build_regular_ca_path(name, &nar_hash_with_mode, Vec::::new(), false).unwrap() } -impl EvalIO for TvixStoreIO { +impl EvalIO for TvixStoreIO { #[instrument(skip(self), ret, err)] fn path_exists(&self, path: &Path) -> Result { if let Ok((store_path, sub_path)) = diff --git a/tvix/store/src/tests/utils.rs b/tvix/store/src/tests/utils.rs index 171919e4e7..9ccd3dcc65 100644 --- a/tvix/store/src/tests/utils.rs +++ b/tvix/store/src/tests/utils.rs @@ -17,6 +17,6 @@ pub fn gen_directory_service() -> Arc { pub fn gen_pathinfo_service( blob_service: Arc, directory_service: Arc, -) -> impl PathInfoService { - MemoryPathInfoService::new(blob_service, directory_service) +) -> Arc { + Arc::new(MemoryPathInfoService::new(blob_service, directory_service)) } -- cgit 1.4.1