Skip to content

Iceberg: hand data files to next calls in arrival order - #129558

Open
groeneai wants to merge 1 commit into
ClickHouse:masterfrom
groeneai:iceberg-iterator-files-in-arrival-order
Open

groeneai wants to merge 1 commit into
ClickHouse:masterfrom
groeneai:iceberg-iterator-files-in-arrival-order

Conversation

@groeneai

@groeneai groeneai commented Nov 5, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #127100

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Description

Since #127100, short multi-threaded scans of Iceberg tables whose files come from few data manifests are slower: MasterCI
arm iceberg_suite_local_tpch query 5 (TPC-H Q6) went from 0.037 to 0.062 s and iceberg_suite_*_read query 20
(max_threads = 16) is +33%, reported in #127100 (comment).

Cause: in IcebergIterator::nextDataFileEntry a thread holding a manifest iterator produced one entry and put it back, so
the entries of one manifest came out one turn at a time and each turn went to whichever thread got the mutex first. A
stream's read-ahead next (issued once its first reader exists) then often took a second file while other streams
were still waiting for their first: with the CI lineitem (one manifest, 12 files after pruning, 16 streams) only 8-11
streams got a file and the query read ~2 files sequentially.

Change: each next call takes a number, produced files are numbered, and the n-th call gets the n-th produced file, so a
read-ahead call can no longer take a file produced for an earlier call. A call keeps reading the manifest until its own file
is produced, so one turn serves every call that came before it. With one thread the order is unchanged. No new thread or
pool.

Validation (release builds, x86, 16 CPUs, base vs fix): Q6 0.062 -> 0.042 s (pre-#127100: 0.040 s; on MinIO 0.071 ->
0.041 s), query 20 0.032 -> 0.025 s, max_threads = 1 unchanged; 20 of 20 traced Q6 runs read one file per stream (base:
1 of 20). 200 manifests, a 20000-entry manifest (all pruned, all read, early matches) and 1/4/16/64 threads are within
noise or faster. Exactly-once stress at 2-64 threads, fault injection at both hand-offs, and the Iceberg stateless and
integration suites pass.

The regression is master-only (#127100 is in no release branch), hence Not for changelog.


Workflow [PR]
Sync PR [sync-upstream/pr/129558]

Since ClickHouse#127100 the threads reading an Iceberg table share the data manifest
iterators, and a thread holding one produced a single entry and put it back.
With one data manifest (e.g. TPC-H `lineitem` of the CI dataset: 84 entries,
12 left after partition pruning) the entries came out one turn at a time, and
each turn went to whichever thread got the mutex first. A stream's read-ahead
`next` (issued right after its first reader is created) competed on equal terms
with streams still waiting for their first file, so it often took a second file:
only 8-11 of 16 streams got a file and the query read ~2 files sequentially.

Now each call takes a number on entry, produced files are numbered in
production order, and the n-th call returns the n-th produced file. A call
keeps calling `ManifestFileIterator::next` until its own file exists, so one
turn serves every earlier waiting call. With one thread the order is the
manifests' order as before.

x86, 16 CPUs, release build, medians: TPC-H Q6 0.062 -> 0.042 s,
`iceberg_suite_shared_read` threads_16 0.032 -> 0.025 s, threads_1 unchanged;
traced Q6: 20/20 runs with 12 streams reading one file each (was 1/20).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

groeneai commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator Author

cc @kssenii @scanhex12, could you review this and add the can be tested label so CI runs? It fixes the Iceberg read slowdown from #127100: IcebergIterator::nextDataFileEntry handed the files of one manifest out one per turn, so a stream's read-ahead next often took a second file while other streams had none; now the n-th call gets the n-th produced file.

@clickhouse-gh

clickhouse-gh Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [a1796b9]

Summary: ✅


AI Review

Summary

IcebergIterator assigns produced data files to concurrent nextDataFileEntry calls in request order, preventing reader prefetch from taking files reserved for earlier calls. Reviewed head a1796b91d69712c7c6a1b3d07e8c94ed72469331; no actionable correctness, concurrency, or safety findings.

Missing context / blind spots
  • ⚠️ Iceberg-specific CI results are not available for this head yet. The PR supplies before/after timings and reports stress and fault-injection validation; these runs were not independently reproduced during this review. Completed Iceberg CI results would provide independent confirmation.
Final Verdict

✅ Approve — no unresolved code findings.

@clickhouse-gh clickhouse-gh Bot added pr-not-for-changelog This PR should not be mentioned in the changelog can be tested Allows running workflows for external contributors comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. labels Nov 5, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing a1796b91d with master 6d71bd180 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

31 translation units recompiled, 345 s compile time in total, 31 of them have a recent master baseline.

Median compile-time ratio to the baselines is ×0.94 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio.
The matched translation units cost -23.2 s (-6%) in total before that adjustment.

Job report

@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 19, 2026

This branch has not been deployed

No deployments
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... pr-not-for-changelog This PR should not be mentioned in the changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant