From 5774117d5ea4115a33923640a39a553eb57df59a Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Thu, 11 May 2023 18:01:17 +0300 Subject: feat(tvix/store): implement TvixStoreIO This providesEvalIO, asking given PathInfoService, DirectoryService and BlobService. Change-Id: I32f210f5a7aa8173ad9a7d53e8a5ac03619f527a Reviewed-on: https://cl.tvl.fyi/c/depot/+/8561 Tested-by: BuildkiteCI Autosubmit: flokli Reviewed-by: tazjin --- tvix/store/src/bin/tvix-store.rs | 54 +++++++++++----------------------------- 1 file changed, 15 insertions(+), 39 deletions(-) (limited to 'tvix/store/src/bin/tvix-store.rs') diff --git a/tvix/store/src/bin/tvix-store.rs b/tvix/store/src/bin/tvix-store.rs index a6bda8c1873b..dbd9e2986e24 100644 --- a/tvix/store/src/bin/tvix-store.rs +++ b/tvix/store/src/bin/tvix-store.rs @@ -1,16 +1,9 @@ use clap::Subcommand; use data_encoding::BASE64; -use nix_compat::derivation::Derivation; -use nix_compat::derivation::Output; -use nix_compat::nixhash::HashAlgo; -use nix_compat::nixhash::NixHash; -use nix_compat::nixhash::NixHashWithMode; use std::path::PathBuf; use tracing_subscriber::prelude::*; use tvix_store::blobservice::SledBlobService; use tvix_store::directoryservice::SledDirectoryService; -use tvix_store::import::ingest_path; -use tvix_store::nar::NARCalculationService; use tvix_store::nar::NonCachingNARCalculationService; use tvix_store::pathinfoservice::SledPathInfoService; use tvix_store::proto::blob_service_server::BlobServiceServer; @@ -19,6 +12,7 @@ use tvix_store::proto::path_info_service_server::PathInfoServiceServer; use tvix_store::proto::GRPCBlobServiceWrapper; use tvix_store::proto::GRPCDirectoryServiceWrapper; use tvix_store::proto::GRPCPathInfoServiceWrapper; +use tvix_store::TvixStoreIO; #[cfg(feature = "reflection")] use tvix_store::proto::FILE_DESCRIPTOR_SET; @@ -85,8 +79,8 @@ async fn main() -> Result<(), Box> { tracing::subscriber::set_global_default(subscriber).expect("Unable to set global subscriber"); // initialize stores - let mut blob_service = SledBlobService::new("blobs.sled".into())?; - let mut directory_service = SledDirectoryService::new("directories.sled".into())?; + let blob_service = SledBlobService::new("blobs.sled".into())?; + let directory_service = SledDirectoryService::new("directories.sled".into())?; let path_info_service = SledPathInfoService::new("pathinfo.sled".into())?; match cli.command { @@ -134,37 +128,19 @@ async fn main() -> Result<(), Box> { directory_service.clone(), ); + let mut io = TvixStoreIO::new( + blob_service, + directory_service, + path_info_service, + nar_calculation_service, + ); + for path in paths { - let root_node = ingest_path(&mut blob_service, &mut directory_service, &path)?; - - let nar_hash = NixHashWithMode::Recursive(NixHash::new( - HashAlgo::Sha256, - nar_calculation_service - .calculate_nar(&root_node)? - .1 - .to_vec(), - )); - - let mut drv = Derivation::default(); - drv.outputs.insert( - "out".to_string(), - Output { - path: "".to_string(), - hash_with_mode: Some(nar_hash), - }, - ); - drv.calculate_output_paths( - path.file_name() - .expect("path must not be ..") - .to_str() - .expect("path must be valid unicode"), - // Note the derivation_or_fod_hash argument is *unused* for FODs, so it doesn't matter what we pass here. - &NixHash::new(HashAlgo::Sha256, vec![]), - )?; - - println!("{}", drv.outputs.get("out").unwrap().path); - - match root_node { + let path_info = io + .import_path_with_pathinfo(&path) + .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?; + + match path_info.node.unwrap().node.unwrap() { tvix_store::proto::node::Node::Directory(directory_node) => { info!( path = ?path, -- cgit 1.4.1