Fix range reads on whole-file caches - #2101
Open
nvbkdw wants to merge 1 commit into
Open
Conversation
`filecache` and `simplecache` serve range reads from the local copy of a file rather than from the remote, and three things go wrong there: 1. Negative `start`/`end` are documented on `AbstractFileSystem.cat_file` to count backwards from the end of the file, and remote backends implement them as HTTP suffix ranges. `_cat_file` instead passed the value straight to `f.seek()`, so a negative offset raised `OSError(EINVAL)` after the whole file had already been downloaded. 2. The sync path reached `AbstractFileSystem.cat_file`, which needs `f.size` to resolve negative offsets. Both `_open` implementations return a bare `io.BufferedReader`, so it raised `AttributeError`. `LocalFileOpener` already attaches `size` to the raw file this way. 3. `WholeFileCacheFileSystem._check_file` returns a `(detail, path)` tuple while the `SimpleCacheFileSystem` override returns the path alone. `_cat_file` and `_cat_ranges` assumed the latter, so on `filecache` they raised `TypeError`/`AttributeError` for a cached path, and `_cat_ranges` never downloaded an uncached one (the miss sentinel is `False`, not `None`). This surfaced with zarr v3 sharded arrays, whose chunk index lives at the end of each object and is read with a suffix range: every read through `simplecache` downloaded the full shard and then failed on the seek. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
filecacheandsimplecacheserve range reads from the local copy of a file rather than from the remote, and three things go wrong there:Negative
start/endare documented onAbstractFileSystem.cat_fileto count backwards from the end of the file, and remote backends implement them as HTTP suffix ranges._cat_fileinstead passed the value straight tof.seek(), so a negative offset raisedOSError(EINVAL)after the whole file had already been downloaded.The sync path reached
AbstractFileSystem.cat_file, which needsf.sizeto resolve negative offsets. Both_openimplementations return a bareio.BufferedReader, so it raisedAttributeError.LocalFileOpeneralready attachessizeto the raw file this way.WholeFileCacheFileSystem._check_filereturns a(detail, path)tuple while theSimpleCacheFileSystemoverride returns the path alone._cat_fileand_cat_rangesassumed the latter, so onfilecachethey raisedTypeError/AttributeErrorfor a cached path, and_cat_rangesnever downloaded an uncached one (the miss sentinel isFalse, notNone).This surfaced with zarr v3 sharded arrays, whose chunk index lives at the end of each object and is read with a suffix range: every read through
simplecachedownloaded the full shard and then failed on the seek.