refactor(tvix/store): use composition in tvix_store crate
Change-Id: Ie6290b296baba2b987f1a61c9bb4c78549ac11f1 Reviewed-on: https://cl.tvl.fyi/c/depot/+/11983 Reviewed-by: flokli <flokli@flokli.de> Autosubmit: yuka <yuka@yuka.dev> Tested-by: BuildkiteCI
This commit is contained in:
parent
6180a7cecf
commit
8b77c7fcd7
20 changed files with 569 additions and 251 deletions
|
|
@ -16,7 +16,6 @@ use tracing::{info, info_span, instrument, Level, Span};
|
|||
use tracing_indicatif::span_ext::IndicatifSpanExt as _;
|
||||
use tvix_castore::import::fs::ingest_path;
|
||||
use tvix_store::nar::NarCalculationService;
|
||||
use tvix_store::pathinfoservice::CachePathInfoService;
|
||||
use tvix_store::proto::NarInfo;
|
||||
use tvix_store::proto::PathInfo;
|
||||
|
||||
|
|
@ -210,31 +209,38 @@ async fn run_cli(cli: Cli) -> Result<(), Box<dyn std::error::Error + Send + Sync
|
|||
remote_path_info_service_addr,
|
||||
} => {
|
||||
// initialize stores
|
||||
let (blob_service, directory_service, path_info_service, nar_calculation_service) =
|
||||
tvix_store::utils::construct_services(
|
||||
blob_service_addr,
|
||||
directory_service_addr,
|
||||
path_info_service_addr,
|
||||
)
|
||||
.await?;
|
||||
let mut configs = tvix_store::utils::addrs_to_configs(
|
||||
blob_service_addr,
|
||||
directory_service_addr,
|
||||
path_info_service_addr,
|
||||
)?;
|
||||
|
||||
// if remote_path_info_service_addr has been specified,
|
||||
// update path_info_service to point to a cache combining the two.
|
||||
let path_info_service = if let Some(addr) = remote_path_info_service_addr {
|
||||
let remote_path_info_service = tvix_store::pathinfoservice::from_addr(
|
||||
&addr,
|
||||
blob_service.clone(),
|
||||
directory_service.clone(),
|
||||
)
|
||||
.await?;
|
||||
if let Some(addr) = remote_path_info_service_addr {
|
||||
use tvix_store::composition::{with_registry, DeserializeWithRegistry, REG};
|
||||
use tvix_store::pathinfoservice::CachePathInfoServiceConfig;
|
||||
|
||||
let path_info_service =
|
||||
CachePathInfoService::new(path_info_service, remote_path_info_service);
|
||||
let remote_url = url::Url::parse(&addr)?;
|
||||
let remote_config = with_registry(®, || remote_url.try_into())?;
|
||||
|
||||
Box::new(path_info_service) as Box<dyn PathInfoService>
|
||||
} else {
|
||||
path_info_service
|
||||
};
|
||||
let local = configs.pathinfoservices.insert(
|
||||
"default".into(),
|
||||
DeserializeWithRegistry(Box::new(CachePathInfoServiceConfig {
|
||||
near: "local".into(),
|
||||
far: "remote".into(),
|
||||
})),
|
||||
);
|
||||
configs
|
||||
.pathinfoservices
|
||||
.insert("local".into(), local.unwrap());
|
||||
configs
|
||||
.pathinfoservices
|
||||
.insert("remote".into(), remote_config);
|
||||
}
|
||||
|
||||
let (blob_service, directory_service, path_info_service, nar_calculation_service) =
|
||||
tvix_store::utils::construct_services_from_configs(configs).await?;
|
||||
|
||||
let mut server = Server::builder().layer(
|
||||
ServiceBuilder::new()
|
||||
|
|
@ -257,7 +263,7 @@ async fn run_cli(cli: Cli) -> Result<(), Box<dyn std::error::Error + Send + Sync
|
|||
GRPCDirectoryServiceWrapper::new(directory_service),
|
||||
))
|
||||
.add_service(PathInfoServiceServer::new(GRPCPathInfoServiceWrapper::new(
|
||||
Arc::from(path_info_service),
|
||||
path_info_service,
|
||||
nar_calculation_service,
|
||||
)));
|
||||
|
||||
|
|
@ -302,8 +308,7 @@ async fn run_cli(cli: Cli) -> Result<(), Box<dyn std::error::Error + Send + Sync
|
|||
)
|
||||
.await?;
|
||||
|
||||
// Arc PathInfoService and NarCalculationService, as we clone it .
|
||||
let path_info_service: Arc<dyn PathInfoService> = path_info_service.into();
|
||||
// Arc NarCalculationService, as we clone it .
|
||||
let nar_calculation_service: Arc<dyn NarCalculationService> =
|
||||
nar_calculation_service.into();
|
||||
|
||||
|
|
@ -365,9 +370,6 @@ async fn run_cli(cli: Cli) -> Result<(), Box<dyn std::error::Error + Send + Sync
|
|||
let reference_graph: ReferenceGraph<'_> =
|
||||
serde_json::from_slice(reference_graph_json.as_slice())?;
|
||||
|
||||
// Arc the PathInfoService, as we clone it .
|
||||
let path_info_service: Arc<dyn PathInfoService> = path_info_service.into();
|
||||
|
||||
let lookups_span = info_span!(
|
||||
"lookup pathinfos",
|
||||
"indicatif.pb_show" = tracing::field::Empty
|
||||
|
|
@ -475,7 +477,7 @@ async fn run_cli(cli: Cli) -> Result<(), Box<dyn std::error::Error + Send + Sync
|
|||
let fs = make_fs(
|
||||
blob_service,
|
||||
directory_service,
|
||||
Arc::from(path_info_service),
|
||||
path_info_service,
|
||||
list_root,
|
||||
show_xattr,
|
||||
);
|
||||
|
|
@ -523,7 +525,7 @@ async fn run_cli(cli: Cli) -> Result<(), Box<dyn std::error::Error + Send + Sync
|
|||
let fs = make_fs(
|
||||
blob_service,
|
||||
directory_service,
|
||||
Arc::from(path_info_service),
|
||||
path_info_service,
|
||||
list_root,
|
||||
show_xattr,
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue