Skip to content

Cherry pick #108872 to 26.5: Restore prefetch for small files read from object storage - #109123

Merged
fm4v merged 12 commits into
backport/26.5/108872from
cherrypick/26.5/108872
Jul 2, 2026
Merged

fm4v merged 12 commits into
backport/26.5/108872from
cherrypick/26.5/108872

Conversation

@robot-ch-test-poll

Copy link
Copy Markdown
Contributor

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-pick locally.
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:

  • delete the pr-cherrypick label from the PR
  • delete this branch from the repository

You also need to check the Original pull-request for pr-backports-created label, and delete if it's presented there

The PR source

The PR is created in the CI job

fm4v added 11 commits June 30, 2026 00:35
…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
@robot-ch-test-poll robot-ch-test-poll added pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! do not test disable testing on pull request labels Jul 2, 2026
# Conflicts:
#	src/Storages/ObjectStorage/StorageObjectStorageSource.cpp
@fm4v
fm4v merged commit b7e2671 into backport/26.5/108872 Jul 2, 2026
@fm4v
fm4v deleted the cherrypick/26.5/108872 branch July 2, 2026 08:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not test disable testing on pull request pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants