Skip to content

Exponential overflow header buffer #83

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

kylebarron
Copy link
Member

Changes

  • Updates AsyncFileReader to use &mut self instead of &self on the trait methods. This is necessary so that the buffer can be mutated when fetching the overflow, while also adding it to the cached buffers
  • Use Box instead of Arc in reader code, now that we need mutability of the reader.
  • Updates the tokio integration to implement AsyncFileReader directly on anything that implements AsyncRead and AsyncSeek. We don't need a wrapper object now that we use &mut self ourselves.
  • Add test to verify overflow handling

This PR is not made on top of #82, but I think some mix of this and #82 makes sense.

src/reader.rs Outdated
Comment on lines 250 to 259
async fn expand_prefetch(&mut self, range: Range<u64>) -> AsyncTiffResult<Bytes> {
let existing_buffer_length = self.buffer_length() as u64;
let additional_fetch =
(existing_buffer_length as f64).powf(self.overflow_fetch_exponent) as u64;

// Make sure that we fetch at least the entire desired range
let new_range =
existing_buffer_length..range.end.max(existing_buffer_length + additional_fetch);
let buffer = self.reader.get_metadata_bytes(new_range).await?;
self.buffers.push(buffer);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is where we request the overflow and add it to the existing buffering (self.buffers.push(buffer))

src/reader.rs Outdated
/// ## Panics
///
/// If the range does not fall completely within the pre-cached buffers.
fn buffer_slice(&self, range: Range<u64>) -> Bytes {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reads from the existing buffers, handling a cross-buffer merge in case the input request overlaps multiple of self.buffers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant