diff options
author | Connor Brewster <cbrewster@hey.com> | 2024-04-18T18·51-0500 |
---|---|---|
committer | Connor Brewster <cbrewster@hey.com> | 2024-04-19T20·37+0000 |
commit | 259d7a3cfa214e7eab7b0862024d595489e92592 (patch) | |
tree | f6f52a334d5e5d26e6f3c323db0f8e56beaf56c8 /tvix/glue/src/tvix_store_io.rs | |
parent | 150106610e60e95267c0968a9679797b05db7f3d (diff) |
refactor(tvix/castore): generalize store ingestion streams r/7979
Previously the store ingestion code was coupled to `walkdir::DirEntry`s produced by the `walkdir` crate which made it impossible to reuse ingesting from other sources like tarballs or NARs. This introduces a `IngestionEntry` which carries enough information for store ingestion and a future for computing the Blake3 digest of files. This allows the producer to perform file uploads in a way that makes sense for the source, ie. the filesystem upload could concurrently upload multiple files at the same time, while the NAR ingestor will need to ingest the entire blob before yielding the next blob in the stream. In the future we can buffer small blobs and upload them concurrently, but the full blob still needs to be read from the NAR before advancing. Change-Id: I6d144063e2ba5b05e765bac1f27d41b3c8e7b283 Reviewed-on: https://cl.tvl.fyi/c/depot/+/11462 Reviewed-by: flokli <flokli@flokli.de> Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/glue/src/tvix_store_io.rs')
-rw-r--r-- | tvix/glue/src/tvix_store_io.rs | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/tvix/glue/src/tvix_store_io.rs b/tvix/glue/src/tvix_store_io.rs index 10a59027852f..46575743c462 100644 --- a/tvix/glue/src/tvix_store_io.rs +++ b/tvix/glue/src/tvix_store_io.rs @@ -2,13 +2,11 @@ use async_recursion::async_recursion; use bytes::Bytes; -use futures::Stream; use futures::{StreamExt, TryStreamExt}; use nix_compat::nixhash::NixHash; use nix_compat::store_path::{build_ca_path, StorePathRef}; use nix_compat::{nixhash::CAHash, store_path::StorePath}; use sha2::{Digest, Sha256}; -use std::marker::Unpin; use std::rc::Rc; use std::{ cell::RefCell, @@ -20,6 +18,7 @@ use std::{ use tokio_util::io::SyncIoBridge; use tracing::{error, instrument, warn, Level}; use tvix_build::buildservice::BuildService; +use tvix_castore::import::dir_entry_iter_to_ingestion_stream; use tvix_eval::{ErrorKind, EvalIO, FileType, StdIO}; use tvix_store::utils::AsyncIoBridge; use walkdir::DirEntry; @@ -278,17 +277,19 @@ impl TvixStoreIO { /// This forwards the ingestion to the [`tvix_castore::import::ingest_entries`], /// passing the blob_service and directory_service that's used. /// The error is mapped to std::io::Error for simplicity. - pub(crate) async fn ingest_entries<S>(&self, entries_stream: S) -> io::Result<Node> + pub(crate) async fn ingest_dir_entries<'a, I>( + &'a self, + iter: I, + root: &Path, + ) -> io::Result<Node> where - S: Stream<Item = DirEntry> + Unpin, + I: Iterator<Item = Result<DirEntry, walkdir::Error>> + Send + Sync + 'a, { - tvix_castore::import::ingest_entries( - &self.blob_service, - &self.directory_service, - entries_stream, - ) - .await - .map_err(|err| std::io::Error::new(io::ErrorKind::Other, err)) + let entries_stream = dir_entry_iter_to_ingestion_stream(&self.blob_service, iter, root); + + tvix_castore::import::ingest_entries(&self.directory_service, entries_stream) + .await + .map_err(|err| std::io::Error::new(io::ErrorKind::Other, err)) } pub(crate) async fn node_to_path_info( |