refactor(tvix/castore/directorysvc): 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: Ia05bb370340792a048e2036be30e285ef1e63870 Reviewed-on: https://cl.tvl.fyi/c/depot/+/10483 Autosubmit: flokli <flokli@flokli.de> Reviewed-by: raitobezarius <tvl@lahfa.xyz> Tested-by: BuildkiteCI
This commit is contained in:
parent
9ca1353122
commit
41935fab70
3 changed files with 26 additions and 11 deletions
|
@ -1,4 +1,3 @@
|
|||
use std::sync::Arc;
|
||||
use url::Url;
|
||||
|
||||
use crate::{proto::directory_service_client::DirectoryServiceClient, Error};
|
||||
|
@ -19,7 +18,7 @@ use super::{DirectoryService, GRPCDirectoryService, MemoryDirectoryService, Sled
|
|||
/// Connects to a local tvix-store gRPC service via Unix socket.
|
||||
/// - `grpc+http://host:port`, `grpc+https://host:port`
|
||||
/// Connects to a (remote) tvix-store gRPC service.
|
||||
pub async fn from_addr(uri: &str) -> Result<Arc<dyn DirectoryService>, crate::Error> {
|
||||
pub async fn from_addr(uri: &str) -> Result<Box<dyn DirectoryService>, crate::Error> {
|
||||
let url = Url::parse(uri)
|
||||
.map_err(|e| crate::Error::StorageError(format!("unable to parse url: {}", e)))?;
|
||||
|
||||
|
@ -28,7 +27,7 @@ pub async fn from_addr(uri: &str) -> Result<Arc<dyn DirectoryService>, crate::Er
|
|||
if url.has_host() || !url.path().is_empty() {
|
||||
return Err(Error::StorageError("invalid url".to_string()));
|
||||
}
|
||||
Arc::new(MemoryDirectoryService::default())
|
||||
Box::<MemoryDirectoryService>::default()
|
||||
} else if url.scheme() == "sled" {
|
||||
// sled doesn't support host, and a path can be provided (otherwise
|
||||
// it'll live in memory only).
|
||||
|
@ -45,12 +44,12 @@ pub async fn from_addr(uri: &str) -> Result<Arc<dyn DirectoryService>, crate::Er
|
|||
// TODO: expose compression and other parameters as URL parameters?
|
||||
|
||||
if url.path().is_empty() {
|
||||
return Ok(Arc::new(
|
||||
return Ok(Box::new(
|
||||
SledDirectoryService::new_temporary()
|
||||
.map_err(|e| Error::StorageError(e.to_string()))?,
|
||||
));
|
||||
}
|
||||
return Ok(Arc::new(
|
||||
return Ok(Box::new(
|
||||
SledDirectoryService::new(url.path())
|
||||
.map_err(|e| Error::StorageError(e.to_string()))?,
|
||||
));
|
||||
|
@ -61,7 +60,7 @@ pub async fn from_addr(uri: &str) -> Result<Arc<dyn DirectoryService>, crate::Er
|
|||
// - 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 = DirectoryServiceClient::new(crate::tonic::channel_from_url(&url).await?);
|
||||
Arc::new(GRPCDirectoryService::from_client(client))
|
||||
Box::new(GRPCDirectoryService::from_client(client))
|
||||
} else {
|
||||
Err(crate::Error::StorageError(format!(
|
||||
"unknown scheme: {}",
|
||||
|
|
|
@ -80,7 +80,10 @@ async fn construct_services(
|
|||
let blob_service: Arc<dyn BlobService> = blobservice::from_addr(blob_service_addr.as_ref())
|
||||
.await?
|
||||
.into();
|
||||
let directory_service = directoryservice::from_addr(directory_service_addr.as_ref()).await?;
|
||||
let directory_service: Arc<dyn DirectoryService> =
|
||||
directoryservice::from_addr(directory_service_addr.as_ref())
|
||||
.await?
|
||||
.into();
|
||||
let path_info_service = pathinfoservice::from_addr(
|
||||
path_info_service_addr.as_ref(),
|
||||
blob_service.clone(),
|
||||
|
|
|
@ -14,6 +14,7 @@ use tracing_subscriber::prelude::*;
|
|||
use tvix_castore::blobservice;
|
||||
use tvix_castore::blobservice::BlobService;
|
||||
use tvix_castore::directoryservice;
|
||||
use tvix_castore::directoryservice::DirectoryService;
|
||||
use tvix_castore::import;
|
||||
use tvix_castore::proto::blob_service_server::BlobServiceServer;
|
||||
use tvix_castore::proto::directory_service_server::DirectoryServiceServer;
|
||||
|
@ -197,7 +198,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
// initialize stores
|
||||
let blob_service: Arc<dyn BlobService> =
|
||||
blobservice::from_addr(&blob_service_addr).await?.into();
|
||||
let directory_service = directoryservice::from_addr(&directory_service_addr).await?;
|
||||
let directory_service: Arc<dyn DirectoryService> =
|
||||
directoryservice::from_addr(&directory_service_addr)
|
||||
.await?
|
||||
.into();
|
||||
let path_info_service = pathinfoservice::from_addr(
|
||||
&path_info_service_addr,
|
||||
blob_service.clone(),
|
||||
|
@ -253,7 +257,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
// FUTUREWORK: allow flat for single files?
|
||||
let blob_service: Arc<dyn BlobService> =
|
||||
blobservice::from_addr(&blob_service_addr).await?.into();
|
||||
let directory_service = directoryservice::from_addr(&directory_service_addr).await?;
|
||||
let directory_service: Arc<dyn DirectoryService> =
|
||||
directoryservice::from_addr(&directory_service_addr)
|
||||
.await?
|
||||
.into();
|
||||
let path_info_service = pathinfoservice::from_addr(
|
||||
&path_info_service_addr,
|
||||
blob_service.clone(),
|
||||
|
@ -356,7 +363,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
} => {
|
||||
let blob_service: Arc<dyn BlobService> =
|
||||
blobservice::from_addr(&blob_service_addr).await?.into();
|
||||
let directory_service = directoryservice::from_addr(&directory_service_addr).await?;
|
||||
let directory_service: Arc<dyn DirectoryService> =
|
||||
directoryservice::from_addr(&directory_service_addr)
|
||||
.await?
|
||||
.into();
|
||||
let path_info_service = pathinfoservice::from_addr(
|
||||
&path_info_service_addr,
|
||||
blob_service.clone(),
|
||||
|
@ -401,7 +411,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
} => {
|
||||
let blob_service: Arc<dyn BlobService> =
|
||||
blobservice::from_addr(&blob_service_addr).await?.into();
|
||||
let directory_service = directoryservice::from_addr(&directory_service_addr).await?;
|
||||
let directory_service: Arc<dyn DirectoryService> =
|
||||
directoryservice::from_addr(&directory_service_addr)
|
||||
.await?
|
||||
.into();
|
||||
let path_info_service = pathinfoservice::from_addr(
|
||||
&path_info_service_addr,
|
||||
blob_service.clone(),
|
||||
|
|
Loading…
Reference in a new issue