Repository navigation
Cherry pick #116723 to 26.7: Parallelize Iceberg data manifest decoding - #120405
robot-clickhouse-ci-1 wants to merge 28 commits into
Conversation
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.
Co-Authored-By: Claude Fable 5 <[email protected]>
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
…st-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
|
@groeneai could you please resolve the conflicts? |
|
I measured this arm against
Resolving that textually means reimplementing the change against a different architecture and rewriting the delete path with it, which is no longer a cherry-pick. Two ways forward:
I would pick 2: both prerequisites are performance changes with no version label today, and The 26.8 arm (#120406) is a genuine conflict resolution and I am preparing that one there. |
|
Dear @scanhex12, this cherry-pick PR has not been updated for 3d0h3m48s. Please resolve the conflicts to backport #116723, or close this PR if the backport is no longer needed. This PR will be automatically closed after 7 days of inactivity. |
|
Dear @scanhex12, this cherry-pick PR has not been updated for 7d0h1m11s. Closing automatically. If you still want to backport #116723, please resolve the conflicts and reopen this PR. |
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-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.
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:
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