about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2024-04-16T13·30+0300
committerflokli <flokli@flokli.de>2024-04-16T18·45+0000
commit28e98af9bc4c4a29676dbe5e7d0c7614fba410a6 (patch)
tree8d7bdd22f323229926614a5e1da7d7b6af077c47
parent9398bc46b60d809aac679157fe4c491586e649ff (diff)
fix(tvix/castore/blobservice/chunk_rd): only skip *first* chunk bytes r/7945
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 <tvl@lahfa.xyz>
Tested-by: BuildkiteCI
-rw-r--r--tvix/castore/src/blobservice/chunked_reader.rs7
1 files changed, 4 insertions, 3 deletions
diff --git a/tvix/castore/src/blobservice/chunked_reader.rs b/tvix/castore/src/blobservice/chunked_reader.rs
index e193ff0295db..2aaea385aed2 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?;