From 9ca1353122e6c1c5cf88d2ed5839fe385be1d5d0 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Sun, 31 Dec 2023 16:13:29 +0200 Subject: refactor(tvix/castore/blobsvc): return Box, not Arc While we currently mostly use it in an Arc, as we need to clone it inside PathInfoService, there might be other usecases not requiring it to be Clone. Change-Id: I7bd337cd2e4c2d4154b385461eefa62c9b78345d Reviewed-on: https://cl.tvl.fyi/c/depot/+/10482 Autosubmit: flokli Reviewed-by: raitobezarius Tested-by: BuildkiteCI --- tvix/castore/src/blobservice/from_addr.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'tvix/castore') diff --git a/tvix/castore/src/blobservice/from_addr.rs b/tvix/castore/src/blobservice/from_addr.rs index 8f8e59952662..db221f05ab3b 100644 --- a/tvix/castore/src/blobservice/from_addr.rs +++ b/tvix/castore/src/blobservice/from_addr.rs @@ -1,4 +1,3 @@ -use std::sync::Arc; use url::Url; use crate::{proto::blob_service_client::BlobServiceClient, Error}; @@ -16,7 +15,7 @@ use super::{ /// - `simplefs://` ([SimpleFilesystemBlobService]) /// /// See their `from_url` methods for more details about their syntax. -pub async fn from_addr(uri: &str) -> Result, crate::Error> { +pub async fn from_addr(uri: &str) -> Result, crate::Error> { let url = Url::parse(uri) .map_err(|e| crate::Error::StorageError(format!("unable to parse url: {}", e)))?; @@ -25,7 +24,7 @@ pub async fn from_addr(uri: &str) -> Result, crate::Error> if url.has_host() || !url.path().is_empty() { return Err(Error::StorageError("invalid url".to_string())); } - Arc::new(MemoryBlobService::default()) + Box::::default() } else if url.scheme() == "sled" { // sled doesn't support host, and a path can be provided (otherwise // it'll live in memory only). @@ -42,11 +41,11 @@ pub async fn from_addr(uri: &str) -> Result, crate::Error> // TODO: expose other parameters as URL parameters? if url.path().is_empty() { - return Ok(Arc::new( + return Ok(Box::new( SledBlobService::new_temporary().map_err(|e| Error::StorageError(e.to_string()))?, )); } - return Ok(Arc::new( + return Ok(Box::new( SledBlobService::new(url.path()).map_err(|e| Error::StorageError(e.to_string()))?, )); } else if url.scheme().starts_with("grpc+") { @@ -56,13 +55,13 @@ pub async fn from_addr(uri: &str) -> Result, crate::Error> // - 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 = BlobServiceClient::new(crate::tonic::channel_from_url(&url).await?); - Arc::new(GRPCBlobService::from_client(client)) + Box::new(GRPCBlobService::from_client(client)) } else if url.scheme() == "simplefs" { if url.path().is_empty() { return Err(Error::StorageError("Invalid filesystem path".to_string())); } - Arc::new(SimpleFilesystemBlobService::new(url.path().into()).await?) + Box::new(SimpleFilesystemBlobService::new(url.path().into()).await?) } else { Err(crate::Error::StorageError(format!( "unknown scheme: {}", -- cgit 1.4.1