From 28e98af9bc4c4a29676dbe5e7d0c7614fba410a6 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Tue, 16 Apr 2024 16:30:49 +0300 Subject: fix(tvix/castore/blobservice/chunk_rd): only skip *first* chunk bytes When (re)initializing a chunked reader, we were erroneously skipping the first n bytes from all chunks, not just the first one. Fix this, by passing in an enumerated list of chunks, and only calling SeekFrom::Start() on the first chunk in the stream. With this, I'm able to invoke b3sum on bin/bash successfully. Change-Id: I52ea480569267e093b0ac9d6bcd5c2d1b4db25f7 Reviewed-on: https://cl.tvl.fyi/c/depot/+/11443 Reviewed-by: raitobezarius Tested-by: BuildkiteCI --- tvix/castore/src/blobservice/chunked_reader.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'tvix/castore/src/blobservice/chunked_reader.rs') diff --git a/tvix/castore/src/blobservice/chunked_reader.rs b/tvix/castore/src/blobservice/chunked_reader.rs index e193ff0295..2aaea385ae 100644 --- a/tvix/castore/src/blobservice/chunked_reader.rs +++ b/tvix/castore/src/blobservice/chunked_reader.rs @@ -209,8 +209,8 @@ where let blob_service = self.blob_service.clone(); let chunks: Vec<_> = self.chunks[start_chunk_idx..].to_vec(); - let readers_stream = tokio_stream::iter(chunks).map( - move |(_chunk_start_offset, _chunk_size, chunk_digest)| { + let readers_stream = tokio_stream::iter(chunks.into_iter().enumerate()).map( + move |(nth_chunk, (_chunk_start_offset, _chunk_size, chunk_digest))| { let chunk_digest = chunk_digest.to_owned(); let blob_service = blob_service.clone(); async move { @@ -223,7 +223,8 @@ where std::io::Error::new(std::io::ErrorKind::NotFound, "chunk not found") })?; - if skip_first_chunk_bytes > 0 { + // iff this is the first chunk in the stream, skip by skip_first_chunk_bytes + if nth_chunk == 0 && skip_first_chunk_bytes > 0 { blob_reader .seek(std::io::SeekFrom::Start(skip_first_chunk_bytes as u64)) .await?; -- cgit 1.4.1