Skip to main content

BlockCache

Struct BlockCache 

Source
pub struct BlockCache<F: AsyncFileReader> { /* private fields */ }
Expand description

A caching wrapper that fetches fixed-size aligned blocks around each accessed offset.

Unlike a sequential readahead cache, a block cache handles the scattered access patterns of HDF5 metadata efficiently: the superblock is at offset 0, object headers and B-tree nodes are scattered across the file, and a sequential cache would waste bandwidth fetching unneeded array data between metadata structures.

When a byte range is requested, the cache fetches any aligned blocks that overlap the range and caches them for future reads. Nearby metadata reads (e.g., an object header and its continuation chunk, or adjacent B-tree nodes) naturally share blocks.

Default block size is 8 MiB, which typically resolves all metadata for a GOES-16 MCMIPF file (~164 datasets) in about 10 requests.

Implementations§

Source§

impl<F: AsyncFileReader> BlockCache<F>

Source

pub fn new(inner: F) -> Self

Create a new BlockCache wrapping the given reader. Default block size: 8 MiB.

Source

pub fn inner(&self) -> &F

Access the inner reader.

Source

pub fn with_block_size(self, block_size: u64) -> Self

Set the block size in bytes.

Source§

impl<F: AsyncFileReader> BlockCache<F>

Source

pub async fn pre_warm(&self, file_size: u64, max_bytes: u64) -> Result<()>

Pre-fetch blocks in parallel to eliminate sequential cache misses during metadata traversal (B-tree parsing, object headers, etc.).

  • If max_bytes covers the entire file, every block is fetched.
  • Otherwise only the first max_bytes / block_size blocks are fetched (HDF5 metadata — superblock, root group, B-tree nodes — is typically concentrated near the beginning of the file).

Issues a single batched get_byte_ranges call so that the backend can coalesce and parallelize the fetches.

Trait Implementations§

Source§

impl<F: AsyncFileReader + Send + Sync> AsyncFileReader for BlockCache<F>

Source§

fn get_bytes<'life0, 'async_trait>( &'life0 self, range: Range<u64>, ) -> Pin<Box<dyn Future<Output = Result<Bytes>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Fetch the bytes in the given range.
Source§

fn get_byte_ranges<'life0, 'async_trait>( &'life0 self, ranges: Vec<Range<u64>>, ) -> Pin<Box<dyn Future<Output = Result<Vec<Bytes>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Fetch multiple byte ranges. The default implementation calls get_bytes sequentially; ObjectReader overrides this with get_ranges().
Source§

fn file_size<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Option<u64>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Return the total file size, if known. Used by BlockCache::pre_warm to fetch all blocks in parallel. The default returns None.
Source§

impl<F: Debug + AsyncFileReader> Debug for BlockCache<F>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<F> Freeze for BlockCache<F>
where F: Freeze,

§

impl<F> !RefUnwindSafe for BlockCache<F>

§

impl<F> Send for BlockCache<F>

§

impl<F> Sync for BlockCache<F>

§

impl<F> Unpin for BlockCache<F>
where F: Unpin,

§

impl<F> UnsafeUnpin for BlockCache<F>
where F: UnsafeUnpin,

§

impl<F> !UnwindSafe for BlockCache<F>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more