Skip to content

Configurable coalesce ranges #6

Open

Description

@kylebarron

By default, object_store has a hard-coded coalesce range
https://github.com/apache/arrow-rs/blob/a0c3186c55ac8ed3f6b8a15d1305548fd6305ebb/object_store/src/lib.rs#L643-L650

However, coalesce_ranges is public, so we can allow users to override how to coalesce ranges. Ref #5

Activity

  1. feefladder commented on Mar 20, 2025

    @feefladder
    Contributor

    object_store is quite a large dependency. I would pull in coalesce_ranges (or ask object_store for a stub crate) and then be able to drop the object_store dependency.

  2. kylebarron commented on Mar 20, 2025

    @kylebarron
    MemberAuthor

    We can make object_store (and reqwest) optional dependencies.

    But we don't need to implement or vendor coalesce_ranges ourselves. The nice thing about having our AsyncFileReader trait is that the Rust user can decide how to implement get_byte_ranges, and they can implement range merging in their own code.

  3. feefladder commented on Mar 20, 2025

    @feefladder
    Contributor

    hmmm.. I may whip up some async-cog crate thing then that handles those things.... Will PR for optional deps then

  4. kylebarron commented on Mar 20, 2025

    @kylebarron
    MemberAuthor

    We can and should define some of those basic middlewares in this library, and then users can decide which they want to use.

  5. feefladder commented on Mar 21, 2025

    @feefladder
    Contributor

    ...so how could we implement a middleware that does coalesce_ranges without pulling its functionality in-tree? Would a user then do something like:

    struct MyReader {
        href: String
    }
    
    #[async_trait] // if not wasm
    impl AsyncFileReader for MyReader {
      fn get_bytes(&self, range: Range<u64>) -> AsyncTiffResult<Bytes> {
        let mut req = ehttp::Request::get(self.href);
        req.headers.insert("Range", write!("bytes={}-{}",range.start,range.end+1)
        Ok(Bytes::copy_from_slice(ehttp::fetch_async(req).await.unwrap().bytes) // no sanitizing
      }
    }
    
    type EhttpCogReader = PrefetchReader<CoalesceReader<MyReader>>
    
    pub struct CoalesceReader {
      inner: Arc<dyn AsyncFileReader>
    }
    
    #[async_trait] // if not wasm
    impl AsyncFileReader for CoalesceReader {
      fn get_bytes(&self, range: Range<u64>) -> AsyncTiffResult<Bytes> {
        self.inner.get_bytes(range).await
      }
    
      fn get_byte_ranges(&self, ranges: Vec<Range<u64>>) -> AsyncTiffResult<Vec<Bytes>> {
        coalesce_ranges(ranges, |range| self.get_bytes(range), 1024*1024)
      }
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions