Skip to content

Cherry pick #116723 to 26.8: Parallelize Iceberg data manifest decoding - #120406

Merged
alexey-milovidov merged 28 commits into
backport/26.8/116723from
cherrypick/26.8/116723
Sep 19, 2026
Merged

alexey-milovidov merged 28 commits into
backport/26.8/116723from
cherrypick/26.8/116723

Conversation

@robot-clickhouse-ci-1

Copy link
Copy Markdown
Contributor

Original pull-request #116723

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.

Before you resolve anything

Conflicts are often caused by a prerequisite change that has not been backported yet, rather than by a real divergence. The bot re-tries this cherry-pick against the release branch on every run, so if that is the case here it will merge itself as soon as the prerequisite lands, and you will see a comment saying so. Manual resolution is only needed while the conflict persists.

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

aaron276h and others added 28 commits August 27, 2026 09:40
Reading an Iceberg snapshot's data files walked the data manifests one
at a time in the producer thread: the one-ahead prefetch overlapped the
next manifest's fetch with the current parse, but the decode itself -
the Avro parse plus per-entry partition and min-max pruning - stayed
serial. On tables with many manifest files this dominates the time
before all data files are known.

Follow up #112679, which introduced a bounded sliding window of decode
tasks on the IO pool for delete manifests, by decoding data manifests
through the same pattern: each task owns the full pipeline for one
manifest (fetch, deserialize, prune), futures are consumed in manifest
list order, and entries stream into the existing bounded queue, whose
blocking `push` bounds read-ahead. The per-manifest decode body is
shared between the delete and data paths (`decodeManifest`), and
`SingleThreadIcebergKeysIterator` with its one-manifest prefetch is
removed: a window of size 2 gives the closest equivalent of the
previous overlap, and 1 decodes the manifests one at a time.

The new setting `iceberg_data_manifest_decode_concurrency` (default 4)
bounds the window, mirroring `iceberg_delete_manifest_decode_concurrency`.
Concurrent index analyses can share one `FutureSetFromSubquery`
through cloned filter DAGs: `ActionsDAG::clone` keeps the underlying
sets shared, and the delete- and data-manifest decode tasks in
`IcebergIterator` evaluate such clones simultaneously. Nothing
synchronized `buildOrderedSetInplace`: two builders raced on
`set_and_key->set`, and one could reset `source` while the other's
speculative pipeline still relied on the resources the source plan
keeps alive.

Guard the build with a per-set mutex: the winner builds, later callers
take the created-set fast path under the lock. A mutex rather than
`callOnce` (the `FutureSetFromTuple` fix) because a build that
stopped without creating the set may legitimately be retried while
`source` is preserved.

Also cover `IN (SELECT ...)` under parallel manifest decode in the
integration test; literal tuple `IN` goes through the already-guarded
`FutureSetFromTuple` and was covered before.
With `iceberg_data_manifest_decode_concurrency = 1` decode the
manifests on the producer thread and push each entry as it is produced,
instead of materializing a whole manifest's batch first. The bounded
queue's backpressure then applies within a manifest, keeping the
previous serial iterator's memory profile: at most the queue capacity
plus one entry (and one decoded manifest) are held, however many
entries a manifest has. The windowed path keeps whole-manifest tasks.

Also cover a single manifest with three times the queue capacity in
entries in the integration test.
A data-manifest decode task drained its whole manifest even after the
query was cancelled or delete decoding failed, so teardown waited for
up to `iceberg_data_manifest_decode_concurrency` full manifest
decodes. The drain loop now checks `blocking_queue.isFinished()` every
256 entries and returns early; the check takes the queue's mutex, so it
stays off the per-entry path, bounding the wait at a few milliseconds
of decoding per task.

Delete-manifest decodes deliberately keep draining: the data producer
finishes the queue once everything is pushed while the query is still
consuming, and the lazy delete decode may run only after that, so a
finished queue does not mean the delete entries are unneeded.
`ManifestFileIterator::next` skips pruned rows internally, so the
teardown check between yielded entries never fired while a manifest was
being fully pruned - and fully pruned manifests are the shape this
setting exists for. `ManifestFileIterator` now takes an optional stop
condition, checked every 256 claimed rows inside the loop, and returns
nullptr as on EOF once it fires. The data-manifest paths pass the
queue's finished state; delete decodes still pass nothing and always
drain fully.

Also cover a fully pruned large manifest in the integration test.
A decode task queued behind its siblings can begin after the queue is
already finished; it still fetched its manifest before the row-loop
stop check could fire. Check the stop condition once before the fetch,
so only fetches already in flight are waited for on teardown.
Each decode task now pushes entries into the bounded queue as they are
produced instead of materializing a whole manifest's batch first, so
the queue's backpressure applies within a manifest at every concurrency
and peak memory is the in-flight manifests' decoded contents plus the
queue - a task blocked on `push` holds its pool slot only while the
query is not consuming. The dedicated serial branch for a concurrency
of `1` is gone: a window of one streaming task now has the same memory
profile. Entries from concurrently decoded manifests interleave in the
queue; nothing consumes their relative order.

Delete manifests keep the batch helper - they are collected, not
streamed.

Also add the review-requested comment at the stop check in
`ManifestFileIterator::next`.
One setting, `iceberg_manifest_decode_concurrency`, now bounds both
the delete- and data-manifest decode windows.
`iceberg_delete_manifest_decode_concurrency` (released in 26.8) is
kept as an alias, so existing configurations keep working and
`compatibility` below 26.8 still restores its old default through the
26.8 history entry.
…st-decode-concurrency

# Conflicts:
#	src/Storages/ObjectStorage/DataLakes/Iceberg/IcebergIterator.cpp
On format-version 3 tables the manifest iterator's constructor
materializes every entry's inherited `first_row_id` before `next` is
ever entered, so the walk must honor the stop condition itself; `next`
then stops on its first row and the incomplete ids are never read.

Also cover a format-version 3 table in the integration test: the
`_row_id` column and the result must not depend on the concurrency.
…urrency' into iceberg-data-manifest-decode-concurrency
The bounded queue, the producer thread, the decode window and the
per-manifest streaming now live in one class; `IcebergIterator` keeps
the delete machinery and delegates. The producer also iterates the
snapshot's manifest list by index instead of copying the DATA entries
into a separate vector.
A streaming decode task can block until the query consumes the entries
it has produced, while `ensureDeletesReady` waits for the delete decode
tasks it schedules on the IO pool before any entry is consumed. With
both kinds of tasks on the IO pool, enough queries could park their
data tasks there to leave no thread for the delete tasks whose
completion would unblock them.

The new pool is sized by `max_iceberg_manifest_decode_thread_pool_size`
(default 100), with the usual free-size and queue-size companions.
The queue between the data manifest decode tasks and the query had a
hardcoded capacity of 100 entries; it is now
`iceberg_file_entries_queue_size`, keeping 100 as the default. The
decode tasks pause once it is full, so it also bounds the read-ahead.
`compatibility` applies `previous_value` only from rows strictly newer
than the pinned version, so with `4` a query pinned to 26.8 kept the
new 4-way data decode - a memory and concurrency envelope that did not
exist in 26.8 - with no escape hatch. `2` approximates the old data
path (one manifest decoded, the next one's fetch in flight); the delete
decode under such pins drops from its released 4 to 2, which is the
lesser harm.
The pool now follows `SYSTEM RELOAD CONFIG` like the other shared
thread pools, and its three settings report live values and
changeability in `system.server_settings`.
A decode task pruning with an `IN (SELECT ...)` predicate built the
subquery set synchronously on its pool thread; when the subquery read
another Iceberg table, the nested read scheduled its own decode tasks
on the same pool and the outer task could wait forever behind itself
once the pool was saturated. The producer now builds all of the filter
DAG's sets before scheduling any task, so nested reads run on the
producer thread instead.

Also give the delete decode tasks their own thread name.
The instance pins `max_iceberg_manifest_decode_thread_pool_size` to 1,
so before the prewarm a pruning subquery reading another Iceberg table
deadlocked the pool; now the query completes.
Every creation and destruction of a pooled serialization took the
pool's single write lock, so any parallel path building serializations
- such as the concurrent Iceberg manifest decode tasks - serialized on
it. The pool is now split into 256 cache line aligned shards indexed by
the key's low bits; the allocated-bytes metric is maintained through a
shared atomic instead of one map's capacity.
…st-decode-concurrency

# Conflicts:
#	src/DataTypes/Serializations/SerializationObjectPool.cpp
`DataFileEntriesStream::run` default-constructed `InFlightManifest`, which
made the implicit default constructor of `ManifestFileCacheKey` defined and
tripped `cppcoreguidelines-pro-type-member-init`: five of its fields have no
initializer.

Construct the key instead of assigning it afterwards, so it never exists in
an uninitialized state and `content_type` does not get a meaningless `DATA`
default.

Co-Authored-By: Claude Opus 5 <[email protected]>
…e-concurrency

Parallelize Iceberg data manifest decoding
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 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 Sep 16, 2026
@scanhex12

Copy link
Copy Markdown
Member

@groeneai could you please resolve the conflicts?

@groeneai

Copy link
Copy Markdown
Collaborator

I measured all three cherry-picks of #116723 against their backport/* bases with a per file three way merge (merge base 24916a76301e^1). This 26.8 arm is the only one that is a genuine conflict resolution: 4 files, 7 hunks. The 26.7 and 26.6 arms are blocked on missing prerequisites, which I wrote up on #120405 and #120404.

Everything 26.8 conflicts on comes from two later master additions, both argument level:

  • manifest_list_entry.first_row_id in the ManifestFileIterator::create calls (Iceberg row lineage). inherited_first_row_id and entry_first_row_ids have zero occurrences on 26.8, so the single hunk in ManifestFileIterator.cpp has nothing to guard on this branch and drops out. It is the one hunk with an empty branch side, so it has to be dropped deliberately: the tree compiles either way, which is exactly how a half applied hunk hides.
  • manifest_file_byte_size in getManifestFile and ManifestFileCacheKey (Fix a crash on an Iceberg manifest list with a huge manifest_length #116564, merged 2026-08-28, four days after the 26.8 cut).

The remaining two hunks are an include union in PreparedSets.h and a SettingsChangesHistory.cpp version block that is 26.9 on master and does not exist on 26.8. IcebergIterator.h on 26.8 is byte identical to the parent commit, so its rewrite applies clean.

I have push: false on this repository and maintainer_can_modify is false here, so I cannot push onto cherrypick/26.8/116723. I will publish the resolved two parent merge as a pull request against backport/26.8/116723, the same shape as #116636 and #116104, and link it in this thread.

One point to settle first: the change renames iceberg_delete_manifest_decode_concurrency, which 26.8 shipped with default 4, to iceberg_manifest_decode_concurrency with the old name as an alias, and its settings history entry pins the value to 2 for compatibility at or below 26.8. Imported verbatim that lowers delete decode concurrency on 26.8 for anyone who pins compatibility, so I plan to leave that history entry out and keep the branch's own block. Tell me if you want it kept instead.

@groeneai

Copy link
Copy Markdown
Collaborator

Resolved 26.8 cherry-pick: #120455 (base backport/26.8/116723, head is the two-parent
merge of this PR's head with that base, so its diff is exactly the 19 files of #116723).

Two corrections to my earlier comment here, both measured on a build of the resolved tree:

  1. manifest_file_byte_size is not a later master addition to drop. It is the opposite: 26.8's
    Iceberg::getManifestFile still takes a required 6th size_t bytes_size, and master REMOVED it in
    Fix a crash on an Iceberg manifest list with a huge manifest_length #116564 (merged 2026-08-28, four days after the 26.8 cut). So the argument must be passed, and
    dropping it does not compile: IcebergIterator.cpp:392:47: error: too few arguments to function call, expected 6, have 5.
  2. The two settings-history entries are not left out; they are appended to the branch's own "26.8"
    block. Leaving them out makes 03999_stateless_settings_history emit PLEASE ADD THE NEW SETTING TO SettingsChangesHistory.cpp for iceberg_manifest_decode_concurrency and
    iceberg_file_entries_queue_size (verified by removing them and rerunning). Importing master's
    "26.9" section instead is worse: a server with compatibility in a profile then exits with code
    115 at startup (Unknown setting 'cascades_aggregation_pushdown'), the same breakage
    0debf7d4d0299 had to undo on this branch on 2026-09-10.

The concern I raised about the delete path does not materialize with that shape: 26.8 already yields
2 for iceberg_delete_manifest_decode_concurrency under compatibility at or below 26.7 through its
own entry, so after the port compatibility <= 26.7 gives 2 for both paths and an unpinned server
gives 4 for both. Measured on the resolved build, for the setting and its alias alike.

One test is excised from the added integration file: test_data_manifest_decode_concurrency_row_lineage
writes a format-version 3 table and selects _row_id, a virtual column 26.8 does not have (it fails
here with UNKNOWN_IDENTIFIER). The other five tests are byte-identical and pass, as do the two
tests of test_iceberg_manifest_decode_pool and the pre-existing
test_delete_manifest_decode_concurrency.

I cannot push to cherrypick/26.8/116723 (no push permission, and maintainer_can_modify is false),
so the PR is the surface I can offer. If you prefer the cheaper route, fast-forwarding this PR's
branch to the same head makes it non-conflicting and the automation finishes the chain by itself:

git fetch https://github.com/groeneai/ClickHouse groeneai/cherrypick-26.8-116723-resolved
git push origin FETCH_HEAD:cherrypick/26.8/116723

If you would rather have the "26.9" section imported after all, or the entries left out, say so and
I will follow that instead.

One aside, no action needed from me: 26.8 does not carry #116564, so it still derives the Iceberg
metadata cache weight from the declared manifest_length and keeps the crash that PR fixed. It is
merged and unlabelled, so v26.8-must-backport on it would let the robot bring the fix here.

@alexey-milovidov
alexey-milovidov merged commit 34b9212 into backport/26.8/116723 Sep 19, 2026
180 of 185 checks passed
@alexey-milovidov
alexey-milovidov deleted the cherrypick/26.8/116723 branch September 19, 2026 17:15
@alexey-milovidov

alexey-milovidov commented Sep 19, 2026 •

Copy link
Copy Markdown
Member

@groeneai, this PR appears merged, but we can't merge cherry-picks. They should be merged with an automation, that subsequently creates a backport PR.

@groeneai

Copy link
Copy Markdown
Collaborator

The backport PR the automation is meant to produce does exist: #121060 (backport/26.8/116723 into 26.8, one squashed commit, 19 files, +996/-233), opened by robot-clickhouse-ci-1 at 17:23:42Z, about eight minutes after the merge, with full CI running on it now. create_backport() squashed the staging branch onto merge-base(26.8, backport/26.8/116723) and force-pushed it, and the resulting tree 36bc65dabf50b3 is byte-identical to the one I had reviewed, so the resolution survived the squash intact and nothing needs recreating.

The "merged" state on this PR is a reachability artifact rather than a second merge: its recorded merge commit is 34b92127250a, which is the head of #120455, and that commit's second parent is cherrypick/26.8/116723. Merging #120455 into the staging branch made this PR's head reachable from its base, so GitHub flipped it to Merged three seconds later.

Why I resolved beside the cherry-pick branch instead of on it: I have push: false on this repository, and these cherry-pick PRs report maintainer_can_modify: false because their head branch lives here rather than in a fork. So I had no way to put a resolution onto cherrypick/26.8/116723, which is what cherrypick_pr.mergeable (tests/ci/cherry_pick.py:283) needs before the bot merges the PR and calls create_backport() itself. A PR from my fork against the staging branch was the only write surface available to me.

On the next conflicting cherry-pick I will not open a PR of my own. I will push the resolved commit to a ref on my fork and post one line in the cherry-pick thread:

git fetch https://github.com/groeneai/ClickHouse <ref> && git push origin FETCH_HEAD:cherrypick/<X.Y>/<N>

so whoever has push makes the robot's PR mergeable and the bot does both steps itself. I offered that as the alternative here on 16 September; I will make it the only thing I offer. And if you would rather I stayed out of conflicting cherry-picks entirely, say so and I will leave them to the assignee.

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.

5 participants