diff options
author | Florian Klink <flokli@flokli.de> | 2024-04-16T10·50+0300 |
---|---|---|
committer | flokli <flokli@flokli.de> | 2024-04-16T18·45+0000 |
commit | 4d802fa0aefbc22b5f78bf7281c0028ad3bf2fff (patch) | |
tree | c03de336d9032c1084735b74914ec05def14d95b /tvix/castore/src | |
parent | bccde31e77ae304d599726a314325f025823e616 (diff) |
feat(tvix/castore/blob/chunked_reader): only reassemble on real seek r/7943
If the resulting offset equals to our current position, there's no need to recreate a reader. Change-Id: I855f0c79c514c16ca48a78e12978af2835fbbd6a Reviewed-on: https://cl.tvl.fyi/c/depot/+/11441 Tested-by: BuildkiteCI Reviewed-by: raitobezarius <tvl@lahfa.xyz>
Diffstat (limited to 'tvix/castore/src')
-rw-r--r-- | tvix/castore/src/blobservice/chunked_reader.rs | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/tvix/castore/src/blobservice/chunked_reader.rs b/tvix/castore/src/blobservice/chunked_reader.rs index 3f2949f1a73a..e193ff0295db 100644 --- a/tvix/castore/src/blobservice/chunked_reader.rs +++ b/tvix/castore/src/blobservice/chunked_reader.rs @@ -76,12 +76,9 @@ where #[instrument(skip(self), err(Debug))] fn start_seek(self: Pin<&mut Self>, position: std::io::SeekFrom) -> std::io::Result<()> { let total_len = self.chunked_blob.blob_length(); - let current_pos = self.pos; - let this = self.project(); - let pos: &mut u64 = this.pos; - let mut r: Pin<&mut Box<dyn AsyncRead + Send + Unpin>> = this.r; + let mut this = self.project(); - let new_position: u64 = match position { + let absolute_offset: u64 = match position { std::io::SeekFrom::Start(from_start) => from_start, std::io::SeekFrom::End(from_end) => { // note from_end is i64, not u64, so this is usually negative. @@ -94,7 +91,7 @@ where } std::io::SeekFrom::Current(from_current) => { // note from_end is i64, not u64, so this can be positive or negative. - current_pos + (*this.pos) .checked_add_signed(from_current) .ok_or_else(|| { std::io::Error::new( @@ -105,17 +102,20 @@ where } }; - // ensure the new position still is inside the file. - if new_position > total_len { - Err(std::io::Error::new( - std::io::ErrorKind::InvalidInput, - "seeked beyond EOF", - ))? - } + // check if the position actually did change. + if absolute_offset != *this.pos { + // ensure the new position still is inside the file. + if absolute_offset > total_len { + Err(std::io::Error::new( + std::io::ErrorKind::InvalidInput, + "seeked beyond EOF", + ))? + } - // Update the position and the internal reader. - *pos = new_position; - *r = this.chunked_blob.reader_skipped_offset(new_position); + // Update the position and the internal reader. + *this.pos = absolute_offset; + *this.r = this.chunked_blob.reader_skipped_offset(absolute_offset); + } Ok(()) } |