Repository navigation
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 ClickHouse#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`.
|
Workflow [PR], commit [1ace1b6] Summary: ❌
AI ReviewSummaryThe PR replaces the serial Iceberg data-manifest walk with a pooled Findings❌ Blockers
Tests
Final VerdictChanges required. LLVM Coverage ReportMeasured on commit 1ace1b6.
Changed lines: Changed C/C++ lines covered: 262/269 (97.40%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes70 object files changed (-5.23 KiB total), 0 added.
716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units640 translation units recompiled, 5063 s compile time in total, 640 of them have a recent master baseline. |
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]>
scanhex12
left a comment
There was a problem hiding this comment.
Thanks for your contribution!
I wrote some comments
| {"min_rows_ratio_for_hash_join_row_store", 5.0, 5.0, "New setting to control the minimum estimated ratio of join output rows to build-side rows to enable transforming hash join payload to row-major. 0 means the transformation is always allowed."}, | ||
| {"enable_sharding_aggregator", false, false, "Obsolete setting, the sharded aggregator has been removed in favor of the adaptive aggregator (`enable_adaptive_aggregator`)."}, | ||
| {"query_plan_fuse_filter_into_array_join", false, true, "New optimization to fuse a filter on ARRAY JOINed columns into the ARRAY JOIN step, enabled by default."}, | ||
| {"iceberg_data_manifest_decode_concurrency", 2, 4, "New setting bounding how many Iceberg data manifest files are decoded concurrently while the list of data files for a query is produced. Before 26.9 one manifest was decoded at a time with the next one's fetch already in flight, so `2` is the closest equivalent of the previous behavior."}, |
There was a problem hiding this comment.
As I remember there was a similar setting to decode delete manifest, maybe we can somehow unite them? Having both is inconvenient.
There was a problem hiding this comment.
Good call, switched everything over to iceberg_manifest_decode_concurrency
|
|
||
| void IcebergIterator::decodeDataManifests() | ||
| { | ||
| std::vector<ManifestFileCacheKey> data_manifests; |
There was a problem hiding this comment.
I think such materialization can be rich in terms of RAM
There was a problem hiding this comment.
We should do it in a streaming way as it was before, but we also need to keep max_in_flight in RAM to prefetch them
There was a problem hiding this comment.
Reworked in fdccaf5, each decode task now pushes entries into the bounded queue as they are produced, so nothing materializes a manifest's entries and the queue's backpressure applies within a manifest at every concurrency. This also helped us simplify and get rid of the iceberg_manifest_decode_concurrency=1 workaround.
There was a problem hiding this comment.
The current refactor is back to chunk materialization. chunk_size is set to queue_size_ at src/Storages/ObjectStorage/DataLakes/Iceberg/IcebergIterator.cpp:193, and each pool task fills manifest.chunk up to that size before the producer touches the queue (src/Storages/ObjectStorage/DataLakes/Iceberg/IcebergIterator.cpp:307-324).
So with iceberg_manifest_decode_concurrency = 4 and iceberg_file_entries_queue_size = 1, four manifests can each hold one unread entry off-queue at the same time; the "second data file ... has to wait for the query to consume the first one" claim in tests/integration/test_iceberg_manifest_decode_pool/test.py:88-90 is no longer true. That means the earlier streaming/backpressure fix does not hold on the current head: iceberg_file_entries_queue_size no longer bounds unread entries the way the setting docs and the previous comment describe.
| <create_query>CREATE TABLE perf_iceberg_data_manifests (id Int64, data String) ENGINE = IcebergLocal(concat(getServerSetting('user_files_path'), '/perf_iceberg_data_manifests/'))</create_query> | ||
| <create_query>INSERT INTO perf_iceberg_data_manifests SELECT number + {n} * 500, toString(number) FROM numbers(500) SETTINGS allow_insert_into_iceberg = 1</create_query> | ||
|
|
||
| <query>SELECT max(id) FROM perf_iceberg_data_manifests SETTINGS use_iceberg_metadata_files_cache = 0</query> |
|
|
||
| ProcessedManifestFileEntryPtr ManifestFileIterator::next() | ||
| { | ||
| static constexpr size_t stop_check_period = 256; |
There was a problem hiding this comment.
why do we need this? Could you please write a comment?
There was a problem hiding this comment.
Added a comment. We want to be able to notice cancellation while a manifest file is being processed, including while its rows are being pruned, which yields no entries the caller could check on. Checking on every row would be needless overhead, so it runs every 256 rows.
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
scanhex12
left a comment
There was a problem hiding this comment.
Ok looks much better, thanks
| /// Cap concurrency: each in-flight manifest holds its decoded contents. | ||
| const size_t max_in_flight = local_context->getSettingsRef()[Setting::iceberg_manifest_decode_concurrency]; | ||
|
|
||
| auto stream_runner = threadPoolCallbackRunnerUnsafe<void>(getIOThreadPool().get(), DB::ThreadName::ICEBERG_ITERATOR); |
There was a problem hiding this comment.
Let's use another pool for data files. As I understood there could be deadlock as we use the same pool as in delete manifest decoding
There was a problem hiding this comment.
yeah great catch, added a separate pool
|
|
||
| void IcebergIterator::decodeDataManifests() | ||
| { | ||
| std::vector<ManifestFileCacheKey> data_manifests; |
There was a problem hiding this comment.
Is it possible to store only indices from data_snapshot->manifest_list_entries to reduce RAM consumption?
| data_snapshot_, | ||
| persistent_components_) | ||
| , manifest_filter_dag(makeManifestFilterDag(filter_dag_, local_context_)) | ||
| , blocking_queue(100) |
There was a problem hiding this comment.
I know that it's not your code, but could you please do a separate setting for this 100?
| return batch; | ||
| } | ||
|
|
||
| void IcebergIterator::streamManifest(const ManifestFileCacheKey & manifest_list_entry) |
There was a problem hiding this comment.
For now seems much better - it's streaming for data files
But I want to propose a small refactoring
Is it possible to move the logic with blocking queue, streamManifest, decodeDataManifests to a separate class?
…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.
`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]>
| auto & manifest = *in_flight.front(); | ||
| manifest.future.get(); | ||
|
|
||
| auto fetch = [this, path = manifest_list_entry.manifest_file_path]() | ||
| for (auto & entry : manifest.chunk) | ||
| { | ||
| return Iceberg::getManifestFile(object_storage, persistent_components, local_context, log, path); | ||
| }; | ||
| prefetched_manifest = PrefetchedManifest{index, prefetch_runner(std::move(fetch), Priority{})}; | ||
| return; | ||
| if (!queue.push(std::move(entry))) | ||
| return; | ||
| } | ||
| manifest.chunk.clear(); | ||
|
|
||
| if (manifest.exhausted) | ||
| in_flight.pop_front(); | ||
| else | ||
| manifest.future = stream_runner([this, scheduled = &manifest] { decodeChunk(*scheduled); }, Priority{}); |
There was a problem hiding this comment.
iceberg_manifest_decode_concurrency stops buying you parallel decode as soon as a manifest needs a second chunk. This loop always waits on in_flight.front(), pushes that chunk, and then reschedules the same manifest, while the later manifests sit in the deque with their first chunks already ready. With chunk_size = iceberg_file_entries_queue_size, any manifest larger than the queue size ends up being decoded essentially serially after the warm-up chunk, so the expensive per-entry pruning path is still single-threaded on exactly the multi-entry-manifest shape this PR is meant to speed up.
I think the producer needs to drain whichever future becomes ready, or the workers need to stream directly into the bounded queue, instead of pinning progress to manifest-list order here.
|
📊 Cloud Performance Report
1 query inconclusive (baseline era shift, segment too thin). K_source=6 K_base=30 flagged=0/65 clickbench🟢 No significant changes tpch_adapted_1_officialFlagged queries (1 of 22)
Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. Debug info
|
24916a7
|
@scanhex12 thank you for the reviews and your help landing this, it is very appreciated! |
|
@aaron276h nice to hear, thanks for your contribution once again!) |
Merge backport/26.8/116723 into cherrypick/26.8/116723 to finish the robot cherry-pick of #116723 "Parallelize Iceberg data manifest decoding", which GitHub reports as CONFLICTING. Five of the nineteen paths needed a decision; the other fourteen land as the merge produced them. src/Storages/ObjectStorage/DataLakes/Iceberg/IcebergIterator.cpp: the rewrite consolidated both manifest-iterator call sites into createManifestIterator, so the resolved file is master's file plus two argument-level edits. 26.8's Iceberg::getManifestFile still takes the bytes_size parameter that master dropped in #116564, so manifest_list_entry.manifest_file_byte_size is passed; 26.8's ManifestFileIterator::create has no row-lineage parameter, so manifest_list_entry.first_row_id is not passed. src/Storages/ObjectStorage/DataLakes/Iceberg/ManifestFileIterator.cpp: the incoming constructor body materializes per-entry first_row_id values for format-version 3 manifests. Iceberg row lineage does not exist on 26.8, so the 26.8 (empty) side is taken. The cancellation check the PR adds between rows in next() sits outside the conflict and is kept, so the new stop flag still reaches the decode loop rather than being dropped with the walk. src/Interpreters/PreparedSets.h: include union only. 26.8 keeps its own include block plus <mutex> for the mutex member the PR adds. src/Core/SettingsChangesHistory.cpp: a plain merge resolves this file by importing master's whole "26.9" section, which names settings that do not exist on 26.8, so applyCompatibilitySetting() throws UNKNOWN_SETTING for every SET compatibility and a server with compatibility in a profile exits with code 115 at startup. That was fixed once already on this branch, by 0debf7d. The imported section is therefore dropped and the two new entries are appended to the branch's own "26.8" block, without master's "pre-26.9" and "compatibility at or below 26.8" clauses, which are false here. The branch's existing iceberg_delete_manifest_decode_concurrency entry is unchanged, so compatibility at or below 26.7 yields 2 for both the data and the delete path, and an unpinned server yields 4 for both. Leaving the entries out entirely is not an option: 03999_stateless_settings_history requires every setting absent from the frozen baseline to be recorded, and neither new setting is in the baseline. tests/integration/test_storage_iceberg_with_spark/test_data_manifest_decode_concurrency.py: 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 is excised and the other five tests are unchanged. Nothing on 26.8 loses coverage, because the behavior it pins, per-entry first_row_id materialization under concurrency, has no implementation on this branch. Related: #116723 Related: #120406
…723-resolved Resolve the 26.8 cherry-pick conflicts of #116723
Backport #116723 to 26.8: Parallelize Iceberg data manifest decoding
Related: #106127
Related: #112679
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Decode Iceberg data manifest files concurrently while the list of data files for a query is produced. The setting
iceberg_manifest_decode_concurrency(default4) bounds how many manifests — delete and data alike — are decoded at a time; it replacesiceberg_delete_manifest_decode_concurrency, which is kept as an alias.Description
On tables with many data manifests, the walk that produces the list of data files is dominated by per-manifest decode work — the Avro parse plus the per-entry partition/min-max pruning in
ManifestFileIterator— which ran serially in the single producer thread. The one-ahead prefetch (#108543) overlapped only the next manifest's fetch, not its decode. Benchmarked in #106127 against a production table (18 data manifests, 113 MB, ~75k entries, 82 columns) with the metadata cache disabled: the serial walk took 8.45 s, of which the raw Avro parse was only ~0.8 s; the rest was per-entry processing. Parallel decode brought it to 2.55 s at 4 threads and 1.68 s at 16.What this PR does:
Iceberg::DataFileEntriesStream: its producer thread keeps up toiceberg_manifest_decode_concurrencydecode tasks in flight, and each task owns the full pipeline for oneDATAmanifest — fetch (getManifestFile), deserialize, per-entry pruning — and streams each surviving entry into a bounded queue as it is produced (capacityiceberg_file_entries_queue_size, default 100). Backpressure therefore applies within a manifest at every concurrency, no batch of entries is ever materialized, and peak memory is the in-flight manifests' decoded contents plus the queue. The producer iterates the snapshot's manifest list by index — no copies. Entries from concurrently decoded manifests interleave in the queue; nothing consumes their relative order.max_iceberg_manifest_decode_thread_pool_size, default 100) rather than the IO pool: a streaming task can block until the query consumes its entries, whileensureDeletesReadywaits for delete decode tasks it schedules on the IO pool before any entry is consumed — on one shared pool, enough queries parking data tasks could leave no thread for the delete tasks whose completion would unblock them.iceberg_manifest_decode_concurrency(NonZeroUInt64, default4) is read by the delete-manifest window from Parallelize delete manifests reads #112679 and by the new data-manifest window.iceberg_delete_manifest_decode_concurrencybecomes an alias, so existing configurations keep working andcompatibilitybelow 26.8 still restores its old default through the existing 26.8 history entry.createManifestIterator, shared by the delete and data paths (both already evaluated identical filter DAG clones; they now share onemanifest_filter_dag). Sharing one clone is no wider than before:ActionsDAG::cloneshares the underlyingColumnSet/FutureSetobjects between clones anyway, and Parallelize delete manifests reads #112679 already evaluates a single clone from several concurrent tasks. Delete manifests keep the collect-into-batch helper — they must all be decoded before the first row.SingleThreadIcebergKeysIteratorand its prefetch machinery are removed — the streaming window subsumes them (1decodes one manifest at a time, like the old walk).ManifestFileIteratortakes an optional stop condition checked every 256 rows inside its row loop (so long stretches of pruned rows cannot hide it); the data paths pass the queue's finished state. Cancellation waits for at most the in-flight fetches plus a few milliseconds of decoding per task. Delete decodes deliberately keep draining — the data producer finishes the queue during normal execution, before the lazy delete decode may even start. Constructor failure handling is also simpler than in Add iceberg_parallel_manifest_decode_threads for parallel manifest decoding #106127: only one thread is spawned, and the tasks are created inside it.FutureSetFromSubquery::buildOrderedSetInplaceis serialized with a per-set mutex. Concurrent decode tasks build per-manifestKeyConditions against the shared DAG, and for anIN (SELECT ...)predicate they could enter the unguarded in-place build simultaneously — racing onset_and_key->setand onsource(one caller resets it while another's speculative pipeline still relies on the resources it keeps alive). This shape is already reachable on master through the delete-manifest window of Parallelize delete manifests reads #112679 (merge-on-read table + subquery filter); this PR makes it reachable for any Iceberg read, so it fixes the shared class the same way Fix data race in FutureSetFromTuple #104673 fixed the tuple sibling. A mutex rather thancallOncebecause a build that stopped without creating the set (for example a subquery timeout withoverflow_mode = 'break') may legitimately be retried whilesourceis preserved.Tests:
test_data_manifest_decode_concurrency.py(integration): result invariance across concurrency 1/2/4/16 on a Spark-written table with one manifest per commit, including a partition-columnINfilter so every concurrent decode task evaluates the shared filter DAG; manifest count is verified throughsystem.iceberg_metadata_log. A merge-on-read case runs concurrent delete- and data-manifest decode together against the shared DAG. A subquery case runspart IN (SELECT ...)under concurrency, exercising the now-serializedFutureSetFromSubquerybuild from several decode tasks. A large-manifest case reads a single manifest with three times the queue capacity in entries (pushes block mid-manifest at every concurrency) and a fully pruned variant of it keeps the row loop busy without yielding. A failpoint case proves the setting drives the window: withiceberg_slow_manifest_readactive,= 1cannot finish faster than one delay per manifest (lower bound), and= 16must beat the measured serial run (comparative bound); timing asserts are skipped on instrumented builds. Modeled ontest_delete_manifest_decode_concurrency.pyandtest_manifest_read_performance.py.tests/performance/iceberg_data_manifests.xml: sibling oficeberg_delete_manifests.xml, 200 single-commit inserts, query with the metadata cache disabled.test_manifest_read_performance.pyfailpoint test now guards the window's fetch overlap instead of the prefetch.Workflow [PR]
Sync PR [sync-upstream/pr/116723]
Version info
26.9.1.797(included in26.9and later)26.8.9.5