From 52cad8619511b97c4bcd5768ce9b3579ff665505 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Sun, 17 Dec 2023 01:32:38 +0200 Subject: refactor(tvix/store): remove Arc<> from PathInfoService::from_addr MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This makes PathInfoService::from_addr return a Box, rather than an Arc, and leaves it up to the consumers to rewrap it into an Arc where needed. This allows us to drop the Arc for the tvix-store daemon subcommand. Change-Id: Ic83aa2ade6c51912281bd17c7eef7252e152b2d1 Reviewed-on: https://cl.tvl.fyi/c/depot/+/10409 Autosubmit: flokli Tested-by: BuildkiteCI Reviewed-by: sterni --- tvix/store/src/pathinfoservice/from_addr.rs | 12 ++++++------ tvix/store/src/pathinfoservice/grpc.rs | 5 ++--- 2 files changed, 8 insertions(+), 9 deletions(-) (limited to 'tvix/store/src/pathinfoservice') diff --git a/tvix/store/src/pathinfoservice/from_addr.rs b/tvix/store/src/pathinfoservice/from_addr.rs index 35f2bd3730e3..922cd3351548 100644 --- a/tvix/store/src/pathinfoservice/from_addr.rs +++ b/tvix/store/src/pathinfoservice/from_addr.rs @@ -31,7 +31,7 @@ pub async fn from_addr( uri: &str, blob_service: Arc, directory_service: Arc, -) -> Result, Error> { +) -> Result, Error> { let url = Url::parse(uri).map_err(|e| Error::StorageError(format!("unable to parse url: {}", e)))?; @@ -40,7 +40,7 @@ pub async fn from_addr( if url.has_host() || !url.path().is_empty() { return Err(Error::StorageError("invalid url".to_string())); } - Arc::new(MemoryPathInfoService::new(blob_service, directory_service)) + Box::new(MemoryPathInfoService::new(blob_service, directory_service)) } else if url.scheme() == "sled" { // sled doesn't support host, and a path can be provided (otherwise // it'll live in memory only). @@ -57,12 +57,12 @@ pub async fn from_addr( // TODO: expose other parameters as URL parameters? if url.path().is_empty() { - return Ok(Arc::new( + return Ok(Box::new( SledPathInfoService::new_temporary(blob_service, directory_service) .map_err(|e| Error::StorageError(e.to_string()))?, )); } - return Ok(Arc::new( + return Ok(Box::new( SledPathInfoService::new(url.path(), blob_service, directory_service) .map_err(|e| Error::StorageError(e.to_string()))?, )); @@ -92,7 +92,7 @@ pub async fn from_addr( } } - Arc::new(nix_http_path_info_service) + Box::new(nix_http_path_info_service) } else if url.scheme().starts_with("grpc+") { // schemes starting with grpc+ go to the GRPCPathInfoService. // That's normally grpc+unix for unix sockets, and grpc+http(s) for the HTTP counterparts. @@ -100,7 +100,7 @@ pub async fn from_addr( // - In the case of non-unix sockets, there must be a host, but no path. // Constructing the channel is handled by tvix_castore::channel::from_url. let client = PathInfoServiceClient::new(tvix_castore::tonic::channel_from_url(&url).await?); - Arc::new(GRPCPathInfoService::from_client(client)) + Box::new(GRPCPathInfoService::from_client(client)) } else { Err(Error::StorageError(format!( "unknown scheme: {}", diff --git a/tvix/store/src/pathinfoservice/grpc.rs b/tvix/store/src/pathinfoservice/grpc.rs index ef3b0b77ec54..9a8599bce26c 100644 --- a/tvix/store/src/pathinfoservice/grpc.rs +++ b/tvix/store/src/pathinfoservice/grpc.rs @@ -115,7 +115,6 @@ impl PathInfoService for GRPCPathInfoService { #[cfg(test)] mod tests { - use std::sync::Arc; use std::time::Duration; use tempfile::TempDir; @@ -151,11 +150,11 @@ mod tests { let mut server = tonic::transport::Server::builder(); let router = server.add_service( crate::proto::path_info_service_server::PathInfoServiceServer::new( - GRPCPathInfoServiceWrapper::from(Arc::new(MemoryPathInfoService::new( + GRPCPathInfoServiceWrapper::new(Box::new(MemoryPathInfoService::new( gen_blob_service(), gen_directory_service(), )) - as Arc), + as Box), ), ); router.serve_with_incoming(uds_stream).await -- cgit 1.4.1