Repository navigation
Cherry pick #108872 to 26.3: Restore prefetch for small files read from object storage - #109121
Merged
Merged
Conversation
…ions The s3()/object-storage table-function read path skipped the small-object initial prefetch whenever the read buffer supported readBigAt, because the prefetch was gated on `!impl->supportsReadAt()`. After #71781 added readBigAt to the fs-cache buffer, reads of many tiny files became synchronous and latency-bound (e.g. low-concurrency s3() ingestion of lots of small files). readBigAt/parallel reading only helps large objects; `use_prefetch` already implies the object is small, so restore the prefetch for that case. Adds a stateless regression test.
Addresses review: the previous change issued the small-object initial prefetch unconditionally, which tripped AsynchronousBoundedReadBuffer::readBigAt's chassert(!prefetch_future.valid()) for small Parquet/ORC/Arrow files read via the s3() table function, aborting the server. Gate the prefetch on the format's access pattern instead of the buffer's supportsReadAt() capability: random-access formats (which use readBigAt) skip the prefetch; sequential formats (TSV/CSV/JSONEachRow/Native/...) get it back. Adds FormatFactory::checkIfFormatHasRandomAccessInputCreator.
Per review (@kssenii): instead of gating the small-object prefetch by format, keep prefetching all small objects and teach AsynchronousBoundedReadBuffer:: readBigAt to consume a pending prefetch - serve the requested range from the prefetched buffer when it is covered (the common case for a fully prefetched small file), otherwise drop the prefetch and fall back to a positioned read. This also extends the prefetch benefit to small Parquet/ORC/Arrow files and removes the FormatFactory coupling added in the previous revision.
- 04000: read with SELECT * FORMAT Null instead of count() (count() can be answered without reading the data via optimize_count_from_files and would not exercise the prefetch path). - gtest_readbuffer_s3 HavingZeroBytes: disable remote_filesystem_read_prefetch so createReadBuffer() does not inject an automatic initial prefetch, which would change the manual prefetch/seek sequence the test asserts.
…ctive The filesystem cache manages its own read-ahead and segment ranges, so issuing an extra initial prefetch over a cached buffer is redundant and interferes with it (this is what gtest_readbuffer_s3 HavingZeroBytes characterizes). Gate the prefetch on !use_filesystem_cache; the non-cached s3()/object-storage read path (the regression) still gets it. Reverts the previous gtest workaround.
…onsumed - readBigAt: when the prefetch covers the head of the requested range but not all of it, copy the covered prefix from the prefetched buffer and read only the missing suffix via impl->readBigAt (offsetting the progress callback so it stays cumulative over the whole range), instead of dropping the prefetch. - 04000 test: also assert RemoteFSPrefetchedReads > 0 to confirm the prefetch is actually consumed, not just issued.
- Move the supportsReadAt() correctness check to the top of readBigAt (it is a general precondition, needed for the prefetch path too). - Drop the separate prefix progress_callback call; only the suffix reports progress, shifted by the served prefix so the reported value stays cumulative and monotonic over the whole range.
The filesystem cache stage is only added when the object has an etag; without it we build a plain remote reader. Clear use_filesystem_cache in that branch so the flag reflects whether the cache stage was actually added. Otherwise the initial small-object prefetch guard (!use_filesystem_cache) would wrongly stay suppressed for the enable_filesystem_cache=1 + missing-etag case, reintroducing the synchronous tiny-file read path.
The fixture writes exactly 16 tiny files and the query reads all of them, so each must regain the initial prefetch. Assert RemoteFSPrefetches >= 16 and RemoteFSPrefetchedReads >= 16 instead of > 0, so a partial regression that prefetched only some files would still be caught.
…etch Restore prefetch for small files read from object storage
# Conflicts: # src/Storages/ObjectStorage/StorageObjectStorageSource.cpp
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.
Original pull-request #108872
Do not merge this PR manually
This pull-request is a first step of an automated backporting.
It contains changes similar to calling
git cherry-picklocally.If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.
The check results does not matter at this step - you can safely ignore them.
Troubleshooting
If the conflicts were resolved in a wrong way
If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job