Skip to content

Experimntal caching for v3 does not work with ByteRequest #3690

@dsparber

Description

@dsparber

Zarr version

3.1.2

Numcodecs version

0.16.5

Python Version

3.14

Operating System

Mac

Installation

using pip into virtual env

Description

The current caching implementation ignores the ByteRequest parameter when storing data to cache. This results in the wrong data being returned when loading different byte ranges of the same key.

This makes sharding incompatible with caching.

Steps to reproduce

import asyncio

from zarr.abc.store import RangeByteRequest
from zarr.core.buffer.cpu import Buffer, buffer_prototype
from zarr.experimental.cache_store import CacheStore
from zarr.storage import MemoryStore


async def main() -> None:
    source = MemoryStore()
    await source.set(key="foo", value=Buffer.from_bytes(b"bar baz"))

    cache = CacheStore(store=source, cache_store=MemoryStore())

    baz_range = RangeByteRequest(start=4, end=7)
    bar_range = RangeByteRequest(start=0, end=3)

    value_bar = await cache.get(
        key="foo",
        prototype=buffer_prototype,
        byte_range=bar_range,
    )

    value_baz = await cache.get(
        key="foo",
        prototype=buffer_prototype,
        byte_range=baz_range,
    )

    source_baz = await source.get(
        key="foo",
        prototype=buffer_prototype,
        byte_range=baz_range,
    )

    print(
        f"bar={value_bar.to_bytes()}, "
        f"baz={value_baz.to_bytes()}, "
        f"source_baz={source_baz.to_bytes()}"
    )
    # expected behaviour: bar=b'bar', baz=b'baz', source_baz=b'baz'
    # actual result: bar=b'bar', baz=b'', source_baz=b'baz'


if __name__ == "__main__":
    asyncio.run(main())

Additional output

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugPotential issues with the zarr-python library

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions