-
-
Notifications
You must be signed in to change notification settings - Fork 423
Use Store.get_many for whole-chunk reads in BatchedCodecPipeline #4113
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
Draft
TomNicholas
wants to merge
2
commits into
zarr-developers:main
Choose a base branch
from
TomNicholas:feat/pipeline-use-get-many
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+291
−15
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| `BatchedCodecPipeline` now fetches the encoded bytes for a whole (non-sharded) | ||
| read with a single `Store.get_many` call spanning the entire request, instead of | ||
| issuing one `Store.get` per chunk. This lets a store batch or coalesce the | ||
| underlying reads — for example `FsspecStore` coalesces nearby chunk reads via | ||
| `cat_ranges`, and a custom store (such as virtualizarr's `ManifestStore` or | ||
| icechunk's `IcechunkStore`) can override `get_many` to merge reads that resolve | ||
| into the same underlying object — independently of `codec_pipeline.batch_size`, | ||
| which still governs only decode batching. The sharding codec's partial-decode | ||
| path is unchanged, and stores without a specialized `get_many` fall back to the | ||
| previous concurrent per-chunk behavior. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| Add `zarr.abc.store.Store.get_many`, a bulk counterpart to `Store.get` that | ||
| retrieves many values — each a whole key or a `(key, byte_range)` pair — in a | ||
| single call. It generalizes `Store.get_ranges` (many ranges of one key) to many | ||
| keys, yielding `(request_index, Buffer | None)` batches in completion order so a | ||
| store can coalesce reads that land in the same underlying object. The method is | ||
| defined on the `Store` ABC with a default implementation that fetches the | ||
| requests concurrently with `Store.get`, so every store inherits a working | ||
| version; stores whose backend can retrieve many objects together should override | ||
| it (`FsspecStore` does, coalescing via `fsspec`'s `cat_ranges`). Coalescing | ||
| tuning is left to each store rather than exposed on the interface. This restores | ||
| and generalizes the batched-fetch capability of the v2 `getitems` Store API. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -237,6 +237,71 @@ async def get_partial_values( | |
| """ | ||
| ... | ||
|
|
||
| async def get_many( | ||
| self, | ||
| requests: Sequence[tuple[str, ByteRequest | None] | str], | ||
| *, | ||
| prototype: BufferPrototype, | ||
| ) -> AsyncIterator[Sequence[tuple[int, Buffer | None]]]: | ||
| """Retrieve many values, possibly from different keys, at once. | ||
|
|
||
| This is the bulk counterpart to :meth:`get`: the whole set of requests | ||
| is handed to the store in a single call, so an implementation can fetch | ||
| them together — for example by coalescing reads that land in the same | ||
| underlying object into fewer requests — rather than one at a time. It | ||
| generalizes :meth:`get_ranges` (which reads many ranges from a *single* | ||
| key) to many keys, each with an optional byte range. | ||
|
|
||
| Yields one batch per underlying I/O operation, each a sequence of | ||
| ``(request_index, Buffer | None)`` tuples where ``request_index`` is the | ||
| position of the request in ``requests``. Every request is reported | ||
| exactly once across all batches; a ``None`` buffer means that key is | ||
| absent. Batches arrive in completion order, not request order, so | ||
| callers use the indices to reassemble results. | ||
|
|
||
| The default implementation fetches each request concurrently with | ||
| :meth:`get`, so every store gets a working version for free; stores | ||
| whose backend can retrieve many objects together (e.g. | ||
| :class:`~zarr.storage.FsspecStore`, which coalesces nearby reads via | ||
| ``fsspec``) should override it. Anything specific to *how* a store | ||
| batches or coalesces (concurrency limits, gap thresholds, ...) is an | ||
| implementation concern of that store, not part of this interface. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| requests : Sequence[tuple[str, ByteRequest | None] | str] | ||
| The values to retrieve. Each request is either a bare key (the | ||
| whole value) or a ``(key, byte_range)`` tuple; a ``byte_range`` of | ||
| ``None`` also means the whole value. A key may appear more than | ||
| once with different ranges. | ||
| prototype : BufferPrototype | ||
| The prototype of the output buffers. Stores may support a default | ||
| buffer prototype. | ||
|
|
||
| Yields | ||
| ------ | ||
| Sequence[tuple[int, Buffer | None]] | ||
| One batch per underlying I/O operation, each a sequence of | ||
| ``(request_index, Buffer | None)`` tuples. | ||
| """ | ||
| # Local imports to avoid an import cycle at module load time. | ||
| from zarr.core.common import concurrent_map | ||
| from zarr.core.config import config | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what if the concurrency is a plain keyword-only parameter for this function? |
||
|
|
||
| indexed = [ | ||
| (i, req, None) if isinstance(req, str) else (i, req[0], req[1]) | ||
| for i, req in enumerate(requests) | ||
| ] | ||
|
|
||
| async def _fetch( | ||
| index: int, key: str, byte_range: ByteRequest | None | ||
| ) -> tuple[int, Buffer | None]: | ||
| return index, await self.get(key, prototype, byte_range) | ||
|
|
||
| results = await concurrent_map(indexed, _fetch, config.get("async.concurrency")) | ||
| for result in results: | ||
| yield [result] | ||
|
|
||
| @abstractmethod | ||
| async def exists(self, key: str) -> bool: | ||
| """Check if a key exists in the store. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rst-style docstring -> mkdocs-style docstring