Skip to content

Resolve the 26.8 cherry-pick conflicts of #116723 - #120455

Merged
alexey-milovidov merged 29 commits into
ClickHouse:backport/26.8/116723from
groeneai:groeneai/cherrypick-26.8-116723-resolved
Sep 19, 2026
Merged

alexey-milovidov merged 29 commits into
ClickHouse:backport/26.8/116723from
groeneai:groeneai/cherrypick-26.8-116723-resolved

Conversation

@groeneai

Copy link
Copy Markdown
Collaborator

Related: #116723
Related: #120406

Changelog category (leave one):

  • Performance Improvement

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 (default 4) bounds how many manifests, delete and data alike, are decoded at a time; it replaces iceberg_delete_manifest_decode_concurrency, which is kept as an alias.

Description

@ scanhex12 asked me to resolve the conflicts in robot cherry-pick #120406 of @ aaron276h's merged
#116723. This is that cherry-pick finished by hand: cherrypick/26.8/116723 merged with
backport/26.8/116723, so the diff against this PR's base is exactly the parent's 19 files.

Five files needed a decision (PreparedSets.h only an include union); the other 14 land
as the merge produced them.

  • IcebergIterator.cpp: master's file plus two argument edits. 26.8's getManifestFile still takes
    the bytes_size parameter master dropped in Fix a crash on an Iceberg manifest list with a huge manifest_length #116564, so manifest_file_byte_size is passed;
    26.8's ManifestFileIterator::create has no row-lineage parameter, so first_row_id is not.
    Reverting either edit fails to compile.
  • ManifestFileIterator.cpp: the incoming constructor body is the format-version-3 first_row_id
    walk, absent on 26.8, so the empty branch side is taken. The cancellation check the parent adds
    between rows in next() sits outside the conflict and is kept.
  • SettingsChangesHistory.cpp: a plain merge imports master's whole "26.9" section, after which a
    26.8 server with compatibility in a profile exits with code 115 at startup (measured; fixed once
    already on this branch by 0debf7d4d0299). The two new entries go into the branch's own "26.8"
    block instead, so compatibility at or below 26.7 gives 2 and unpinned gives 4, for the setting
    and its alias alike, leaving the released delete-path default untouched.
  • The added integration test loses test_data_manifest_decode_concurrency_row_lineage, which selects
    _row_id, a virtual column 26.8 does not have (measured: UNKNOWN_IDENTIFIER). The other five
    tests are byte-identical.

Validated on a clang-22 Debug build of the resolved tree: 03999_stateless_settings_history passes
and fails without the entries, the 5 + 2 new integration tests pass, and the pre-existing
test_delete_manifest_decode_concurrency still passes.

I cannot push to cherrypick/26.8/116723 myself. Fast-forwarding it to this head makes #120406
non-conflicting, which lets the automation finish the chain on its own.

aaron276h and others added 29 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 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`.
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]>
…fest-decode-concurrency

Parallelize Iceberg data manifest decoding
Merge backport/26.8/116723 into cherrypick/26.8/116723 to finish the robot
cherry-pick of ClickHouse#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 ClickHouse#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: ClickHouse#116723
Related: ClickHouse#120406
@groeneai groeneai added the can be tested Allows running workflows for external contributors label Sep 16, 2026
@groeneai groeneai added the groeneai-origin-request PR origin: a maintainer pinged or directed groeneai label Sep 16, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review (click to expand)

An independent model reviewed the resolved tree cold (base backport/26.8/116723, diff 19 files / +996 / -233,
exactly the parent's paths). It raised 7 findings. All 7 are about @ aaron276h's design and tests in #116723 as
merged on master, not about the conflict resolution, so none of them changed the tree: a cherry-pick that edits
the change it is carrying is no longer that change, and it would conflict on every later cherry-pick of these
files. Each is answered below with the measurement that settles it. Two are worth reading anyway.

# Finding Verdict
❌ Reader/writer race on set_and_key->set: buildOrderedSetInplace publishes under the new mutex while get() reads unsynchronized Disagree. The whole PreparedSets change is +5/-0 and +4/-0 (the lock and the member, each with its comment); get() and the publication site are pre-existing 26.8 code, untouched, so this adds synchronization and removes none. The write is also unreachable through the new callback: ReadFromObjectStorageStep.cpp:94 already builds every non-GLOBAL IN filter set synchronously before the iterator exists, so buildOrderedSetsForDAG finds them built and returns.
❌ The new callback uses unrestricted buildOrderedSetsForDAG where the read step uses buildSetsForDAGExcludingGlobalIn Disagree. The asymmetry is identical on master: master's ReadFromObjectStorageStep.cpp:96 is the same ExcludingGlobalIn call as 26.8's :94, and the callback region is byte-identical between master and this tree. Not created or widened here.
❌ Delete-manifest jobs on the IO pool could recursively wait on the same pool Disagree. The pool is unchanged: getIOThreadPool() on the base (IcebergIterator.cpp:397) and after the port (:438); the only edits on that line are the batch type alias and the thread name. The unready-set precondition is defeated by the same synchronous pre-build. test_iceberg_manifest_decode_pool covers the nested-read class with a single-thread pool and passes 2/2.
⚠️ The subquery tests would pass with the prepare callback and mutex removed Disagree, but the premise is right and worth recording: on 26.8 that sub-mechanism is largely inert, because the read step pre-builds the sets. It does not make the tests dead (all 7 need iceberg_manifest_decode_concurrency to exist at all), and inert code master already has is exactly what a backport should carry unchanged.
❌ iceberg_file_entries_queue_size has no oracle separating 1 from the old hardcoded 100 Disagree. That state is not constructible: no literal capacity survives, and both consumers come from the one argument (chunk_size(queue_size_), queue(queue_size_)). test_data_manifest_decode_large_manifest drives a manifest holding three times the queue capacity, so pushes block mid-manifest.
❌ Nothing proves the legacy setting name still maps to the new one Disagree. DECLARE_WITH_ALIAS gives the alias no storage, so "accepted but unused" cannot exist; the alternative is UNKNOWN_SETTING, which reddens the pre-existing test_delete_manifest_decode_concurrency (it passes the legacy name to a running server at four values, and passes here 1/1). Measured at compatibility 26.7 / 26.8 / unpinned: 2/2, 4/4, 4/4 for both names.
⚠️ No test cancels a query, so the new stop check has no executing oracle Disagree on action (that is master's test set, byte-identical here), but this was the live hazard of the resolution and is verified, not assumed: master has two stop_flag checks in ManifestFileIterator.cpp (:506 inside the format-v3 first_row_id walk, :781 between rows in next()); this tree has one, :659, byte-identical to master's :781. The dropped one served only the walk, whose carriers grep 0 on the 26.8 base as well as here.

💡 Also noted, and deliberately not raised as work: findings 1 to 3 together read as a coherent question about the
merged master design (one filter DAG now shared by the data and delete decode paths, with a mutex that guards only
the builder). It applies to master and 26.9, not to this branch's copy, and I did not run anything that would
substantiate it, so I am not filing it. Recording it here where the people who own that code can see it.

Own cold review, separately: the file set is identical to the parent's own change set, 9 of 19 files are
byte-identical hunk for hunk and 3 more are byte-identical files, IcebergIterator.cpp is master's file plus
exactly the two prescribed argument edits, and no row-lineage, partition-spec or set-reuse carrier is imported.
4 nits, none actionable.

Gate B on the resolved tree: 7 findings, engine codex. Session id: cron:clickhouse-review-slot-11:20260916-181900

@clickhouse-gh clickhouse-gh Bot closed this Sep 16, 2026
@clickhouse-gh clickhouse-gh Bot reopened this Sep 16, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. The defect is mechanical (GitHub reports #120406 CONFLICTING), and every failure mode of the ported tree is deterministic and reproduced on demand: two compile errors when either IcebergIterator.cpp edit is reverted, 03999_stateless_settings_history naming both new settings when the history entries are removed, exit code 115 at server startup when master's "26.9" section is imported, and UNKNOWN_IDENTIFIER on _row_id for the excised test.
b Root cause explained? Yes. 26.8 was cut 2026-08-24 while the cherry-pick's merge base is 2026-09-05 master, so the two sides disagree in exactly four places: three master-only features 26.8 lacks (Iceberg row lineage, the partition-spec arity check, PreparedSets parallel-replicas set reuse) and one parameter 26.8 still requires that master removed in #116564. Those explain the four argument/include conflicts; the release-version blocks explain the settings-history hunk.
c Fix matches root cause? Yes. Each resolution is the branch-appropriate side of one divergence: pass the argument 26.8 requires, drop the argument 26.8 has no field for, union the includes, record the new settings in the branch's own current-version block, and scope the new test file to code that exists here. Nothing widened, nothing disabled, no no-random-* tag, no bound relaxed.
d Test intent preserved / new tests added? Yes. Five of the parent's six new tests are byte-identical and pass. The sixth pins per-entry first_row_id materialization, which has no implementation on 26.8, so it is excised; the excision is falsifiable and was falsified (it fails with UNKNOWN_IDENTIFIER on this tree). The pre-existing test_delete_manifest_decode_concurrency still passes, so the setting rename did not weaken existing coverage.
e Both directions demonstrated? Yes, five independent times: revert the manifest_file_byte_size argument (too few arguments to function call, expected 6, have 5), re-add first_row_id (no member named 'first_row_id' in 'DB::ManifestFileCacheKey'), delete the two history entries (03999 emits both PLEASE ADD THE NEW SETTING lines), import master's "26.9" section (Code: 115 Unknown setting 'cascades_aggregation_pushdown', and a server with compatibility in a profile exits 115), and restore the excised test (fails). Each is red without the resolution and green with it.
f Fix is general across code paths? Yes. The parent's rewrite consolidated both pre-existing manifest-iterator call sites into one createManifestIterator, so there is exactly one site to adapt (getManifestFile 1, ManifestFileIterator::create 1 in the resolved file). 26.8's own two pre-port call sites already passed the same manifest_file_byte_size value, so the port routes no new value anywhere. The sibling stop_flag propagation sites were audited: 5 present, including the between-rows check inside next() that does the actual cancelling.
g Fix generalizes across inputs (params/datatypes/wrappers)? Yes, over the dimensions this change has. Settings: measured at compatibility 26.7 / 26.8 / unpinned, for the new setting and its alias (2/2, 4/4, 4/4). Concurrency: the ported tests run at 1/2/4/16, including a single manifest with three times the queue capacity in entries, a fully pruned variant, and an IN (SELECT ...) filter evaluated from several decode tasks. Data types are not a dimension: the port adds no expression-level code.
h Backward compatible? (maintainer-approved exception only) Yes, and this is what the settings-history resolution turns on. No released 26.8 default moves: iceberg_delete_manifest_decode_concurrency keeps default 4 and its existing history entry untouched, and the new name is an alias of it. The two new settings are recorded in the branch's own "26.8" block, so compatibility keeps working (measured) and no "26.9" section is imported, which would otherwise make a 26.8 server exit 115 at startup.
i Invariants and contracts preserved? Yes. (1) The ported tree contains the parent's change and nothing else: 19 files, and every row-lineage, partition-spec and set-reuse carrier greps 0 (first_row_id, entry_first_row_ids, inherited_first_row_id, addRowLineageHyperrectangles, getMaterializedRowLineageRange, isColumnPresenceKnown, partition_spec_fields_count, FutureSetHashing, BuiltSetsByHash, UnorderedMapWithMemoryTracking, getSetAndKey). (2) 26.8's getManifestFile contract (six arguments, no default) is satisfied, so the metadata-cache weight is still supplied. (3) The cancellation contract survives the dropped walk. (4) The settings-history invariant holds in both the functional test and the style leg. (5) The committed tree carries the branch's submodule pins (0 contrib differences against the merge target).

Session id: cron:clickhouse-impl-slot-4:20260916-170600

@clickhouse-gh clickhouse-gh Bot added the comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. label Sep 16, 2026
@alexey-milovidov
alexey-milovidov merged commit f5cf4c4 into ClickHouse:backport/26.8/116723 Sep 19, 2026
@alexey-milovidov alexey-milovidov self-assigned this Sep 19, 2026
@clickhouse-gh clickhouse-gh Bot added comp-iceberg Apache Iceberg tables: reading and writing Iceberg metadata (snapshots, manifests, schema evoluti... and removed comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-iceberg Apache Iceberg tables: reading and writing Iceberg metadata (snapshots, manifests, schema evoluti... groeneai-origin-request PR origin: a maintainer pinged or directed groeneai

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants