Skip to content

Add iceberg_parallel_manifest_decode_threads for parallel manifest decoding - #106127

Closed
aaron276h wants to merge 15 commits into
ClickHouse:masterfrom
aaron276h:iceberg-parallel-manifest-decode
Closed

aaron276h wants to merge 15 commits into
ClickHouse:masterfrom
aaron276h:iceberg-parallel-manifest-decode

Conversation

@aaron276h

Copy link
Copy Markdown
Contributor

Reading an Iceberg snapshot's data files requires walking the snapshot's manifest list and decoding each manifest file. IcebergIterator currently does this with a single background producer thread, so for tables with many manifest files the manifest walk is serial and can dominate query planning time.

This adds an opt-in, experimental setting iceberg_parallel_manifest_decode_threads (UInt64, default 1). At the default value of 1 behavior is unchanged. With a value greater than 1, IcebergIterator builds N data-file iterators that share one atomic counter over the snapshot's manifest_list_entries and spawns N producer tasks; each producer claims the next manifest index via fetch_add, so manifests are decoded cooperatively with no overlap, and the last producer to finish closes the queue. The effective thread count is clamped to the number of manifest files. Delete-file manifests are still drained serially, since data-file pruning depends on the full delete set. A new ProfileEvent IcebergParallelManifestDecodeThreadsSpawned reports how many producer threads were spawned.

Tests: a unit test for the shared-index claim contract, a stateless test for the setting, and an integration test asserting result parity across thread counts (including a query with an IN filter, which exercises concurrent lazy materialization of the shared filter set).

Changelog category:

  • Experimental Feature

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

Added an experimental setting iceberg_parallel_manifest_decode_threads that decodes Iceberg manifest files using multiple threads during query planning, speeding up reads of tables with many manifest files.

@aaron276h
aaron276h marked this pull request as ready for review May 29, 2026 19:51
@aaron276h
aaron276h force-pushed the iceberg-parallel-manifest-decode branch from c25fe90 to 88cfea7 Compare June 3, 2026 13:23
@aaron276h

Copy link
Copy Markdown
Contributor Author

Hi @kssenii — first-time contributor here, so I think CI needs a maintainer to enable it on this PR. Could you kick off CI or point me to the right reviewer?

It's a small, opt-in change to IcebergIterator: a new experimental setting iceberg_parallel_manifest_decode_threads (default 1 = current behavior) that decodes a snapshot's data manifests across N threads, improving performance for tables with many manifest files. Happy to address any feedback, thanks!

…coding

Reading an Iceberg snapshot's data files requires walking the snapshot's
manifest list and decoding each manifest file. IcebergIterator does this
with a single background producer thread, so for tables with many manifest
files the manifest walk is serial and can dominate query planning time.

Add a setting iceberg_parallel_manifest_decode_threads (UInt64, default 1,
EXPERIMENTAL). With the default value of 1 the behavior is unchanged: a
single producer walks the manifest list as before. With a value greater
than 1, IcebergIterator builds N SingleThreadIcebergKeysIterator instances
that share one atomic counter over the snapshot's manifest_list_entries and
spawns N producer tasks; each producer claims the next manifest index via
fetch_add, so the manifests are decoded cooperatively with no overlap. The
last producer to finish closes the queue. The effective thread count is
clamped to the number of manifest files, so an oversized value has no extra
effect.

SingleThreadIcebergKeysIterator takes an optional shared atomic index; when
null (the default) it uses its private index, preserving the single-threaded
path exactly. Delete-file manifests are still drained serially on the
calling thread, since the data-file pruning logic depends on the full
delete set.

If spawning a producer throws (for example, the global thread pool is
saturated), the constructor drains and joins the producers already started
before rethrowing, so a partially-constructed iterator does not abort the
process via ThreadFromGlobalPool's destructor.

Add a ProfileEvent IcebergParallelManifestDecodeThreadsSpawned counting the
producer threads spawned, a unit test for the shared-index claim contract,
a stateless test for the setting, and an integration test that checks result
parity across thread counts (including a query with an IN filter, which
exercises concurrent lazy materialization of the shared filter set).
@aaron276h
aaron276h force-pushed the iceberg-parallel-manifest-decode branch from 88cfea7 to 3a0a1fc Compare June 17, 2026 13:39
@aaron276h

Copy link
Copy Markdown
Contributor Author

Friendly bump, this has been open ~3 weeks and waiting on CI be enabled. @Algunenano, would you be able to kick off CI or point me to the right reviewer? It's a small, opt-in IcebergIterator change: a new experimental setting `iceberg_parallel_manifest_decode_threads. Happy to address any feedback, thanks!

@Diskein Diskein self-assigned this Jul 3, 2026
@Diskein Diskein added the can be tested Allows running workflows for external contributors label Jul 3, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 3, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [d155c84]

Summary: ❌

job_name test_name status info comment
Integration tests (amd_asan_ubsan, db disk, old analyzer, 5/6) FAIL
test_check_table/test.py::test_check_all_tables FAIL cidb, issue
Stress test (amd_asan_ubsan) FAIL
Cannot start clickhouse-server FAIL cidb
Check failed FAIL cidb

AI Review

Summary

This PR adds the experimental setting iceberg_parallel_manifest_decode_threads and rewires IcebergIterator to decode Iceberg data manifests with multiple cooperative producer tasks while keeping the default 1-thread path unchanged. After reviewing the current PR-head diff, the existing thread discussion, and the current CI evidence, I did not find any remaining correctness, safety, or coverage issues that warrant new review comments.

Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-experimental Experimental Feature label Jul 3, 2026
aaron276h and others added 2 commits July 6, 2026 13:51
The previous clamp used the total size of manifest_list_entries, which
includes delete manifests. Delete manifests are drained serially before
the producers start and never participate in the parallel decode, so on
delete-heavy snapshots the clamp allowed spawning producers that could
never claim useful work while still occupying global thread pool slots.
Count only content_type == DATA entries instead; the content type is
already available in the in-memory manifest list, so this is a single
pass over a vector. Update the setting docstring and test comments to
describe the tighter bound.
@alexey-milovidov

Copy link
Copy Markdown
Member

Updating the branch to fix the 04001_join_reorder_through_expression test, which was broken today in master.

The fixture previously contained only data manifests, so the spawn-counter
assertion could not distinguish clamping on the DATA manifest count from
clamping on the total manifest-list entry count. Create the table with
write.delete.mode = merge-on-read and add a final phase that deletes one
row, producing a snapshot with 8 data manifests plus 1 positional-delete
manifest. The phase asserts that the spawn counter at 16 requested threads
still equals 8 (the DATA count) rather than 9 (the total), and that query
results match the serial run in the presence of positional deletes.
@@ -0,0 +1,203 @@
"""

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The contract of this PR is lower planning latency on manifest-heavy Iceberg snapshots, but this suite only proves result parity and the IcebergParallelManifestDecodeThreadsSpawned accounting. Because the new path adds extra scheduling, queueing, and manifest-list scanning, we still need focused before/after evidence that it actually improves the intended workload instead of just moving work around.

Please add a small benchmark or representative threads=1 vs threads>1 measurements for a table with many manifests.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added measurements. Setup: single node, this PR's CI binary, synthetic Iceberg v2 table with 8000 data files across 295 manifests (one bulk Spark insert with REPARTITION_BY_RANGE, then commit.manifest.target-size-bytes=1024 + rewrite_manifests to fan out the manifest list). Query is a selective point lookup (WHERE id = ..., prunes to a single file) with use_iceberg_metadata_files_cache = 0 so every run pays the full manifest walk. Two storage configurations: minio directly (near-zero RTT), and the same minio behind a forwarding proxy adding a fixed 25 ms per request to emulate object-storage round-trip latency. Median of 3 runs, server-side query_duration_ms:

threads 25 ms RTT direct minio
1 (default, old code path) 18.3 s 0.93 s
4 4.9 s (3.7x) 0.53 s
8 2.7 s (6.7x) 0.67 s
16 1.7 s (10.7x) 1.09 s

The serial walk pays ~(requests x RTT) against the metadata store, and the producers divide exactly that term, so the speedup tracks per-request latency: large on real object storage, modest on a local store — and at high thread counts against a zero-latency store the extra scheduling shows up as mild overhead, which is why the setting defaults to 1 and is opt-in per query. IcebergMetadataReadWaitTimeMicroseconds (consumer wait on the manifest queue) shows the same shape: 88 s cumulative at threads=1 vs 5.6 s at threads=16 in the delayed configuration. Happy to share the exact Spark statements if useful.

aaron276h added 4 commits July 7, 2026 11:55
At the default iceberg_parallel_manifest_decode_threads = 1 the
constructor no longer scans manifest_list_entries to count DATA
manifests before concluding that no parallelism is needed: the setting
is read first and the count runs only when the query asks for more than
one thread. The clamp semantics for the parallel case are unchanged.
aaron276h added 2 commits July 9, 2026 10:19
…path

The constructor's catch block that drains and joins already-started
producers when a later ThreadFromGlobalPool spawn throws was untested.
Add a ONCE failpoint (iceberg_parallel_manifest_decode_spawn_failure)
that makes the second producer spawn throw CANNOT_SCHEDULE_TASK while
the first producer is already running, and extend the integration test
to verify the query fails with a regular catchable exception, the
server stays up, and the same query succeeds immediately afterwards.
A bare SELECT count() on an iceberg table is answered from snapshot
metadata by the trivial-count optimization, so the data-file iterator is
never constructed and the spawn-failure failpoint never fires, making
the pytest.raises assertion fail with DID NOT RAISE in the flaky check.
Use the same full-scan query shape as the other phases for the probe,
and disable the failpoint explicitly after the expected failure so the
recovery check does not depend on ONCE semantics.
@aaron276h

Copy link
Copy Markdown
Contributor Author

Hi @Diskein, friendly ping, this one should be ready for review. All the automated review comments have been addressed, and CI finished. The two remaining failures look unrelated to the change: test_rabbitmq_mv_combo and the stress test hung check, which caught a fuzzer query slow under ASan with no iceberg frames in the stack. Happy to address any feedback, thanks!

@clickhouse-gh

clickhouse-gh Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.20% 86.20% +0.00%
Functions 92.00% 92.00% +0.00%
Branches 78.30% 78.30% +0.00%

Changed lines: Changed C/C++ lines covered: 167/168 (99.40%) · Uncovered code

Full report · Diff report

@asya-ch

asya-ch commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

Hey, thanks so much for the hard work here — appreciate the time to benchmark and add fault-injection coverage.

My main concern with this approach is that the producer threads spend most of their time parked rather than doing work, and they stay alive for most of the scan duration. We could avoid this by instead implementing a worker pool that only occupies threads when there is work to do. I'm already working on this for #105044.

Because of the overlap (and in the interest of keeping the code and settings surface area maintainable), I would prefer to not merge this diff. Thanks again for the effort here, happy to discuss further.

@asya-ch

asya-ch commented Jul 28, 2026 •

Copy link
Copy Markdown
Collaborator

@aaron276h, I just merged an optimization for manifest downloads in #108543. Would this fit your use case? One alternative to using a worker pool for data manifests would be to expand that optimization to prefetch multiple manifests instead of just one.

@aaron276h

Copy link
Copy Markdown
Contributor Author

Hi @asya-ch, thanks for taking a look, really appreciate the review.

On whether #108543 covers this use case: I benchmarked against one of our production tables and I don't think it does. The current snapshot has 18 data manifests totaling 113 MB, 82 columns, holding ~75k entries with ~1.5 KB of per-column bounds each. To isolate the walk from data reads I mirrored the snapshot's metadata locally and ran a binary with this PR's change, using a predicate on the identity partition column that prunes every file, with the metadata cache disabled and files in page cache:

iceberg_parallel_manifest_decode_threads walk time (median of 3)
1 8.45 s
4 2.55 s
8 2.07 s
16 1.68 s

Splitting that 8.45 s: since the #108543 prefetch task runs getManifestFile, and AvroForIcebergDeserializer deserializes the whole file in its constructor, expanding the prefetch to K manifests would parallelize the download and the Avro parse. But on this table those are the small terms, the raw Avro parse of all 18 manifests is only ~0.8 s , and fetching 113 MB in-region is maybe another 1–2 s. The remaining ~7.6 s is per-entry work after deserialization, ManifestFileIterator::processRow building entries and evaluating partition/min-max pruning over 75k entries, which happens on the consumer side of the prefetch and would stay serial. So multi-manifest prefetch caps out around ~20% here, versus the 4–5× above. Wide-schema tables with large manifests need the entry processing to fan out too.

Given that, would it make sense to extend the #105044 worker-pool direction to the data-manifest walk, with each pool task owning fetch + deserialize + entry-processing for one manifest, scheduled only while the output queue has room? It would avoid long-lived parked threads entirely, and could reuse whatever knob your pool introduces, I'd happily drop iceberg_parallel_manifest_decode_threads in favor of that. Depending on where your #105044 work stands, I'm glad to either build the data-manifest side on top of your pool once it lands, or take a first pass now, generalizing the #108543 prefetch structure (threadPoolCallbackRunner on the IO pool) from prefetching one manifest's bytes to K tasks that each own the full per-manifest pipeline: fetch, deserialize, and entry processing; whichever avoids stepping on your work.

Happy to close this PR in favor of that direction. Thanks!

@asya-ch

asya-ch commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

I see, thanks for providing the benchmark.

Given that, would it make sense to extend the #105044 worker-pool direction to the data-manifest walk, with each pool task owning fetch + deserialize + entry-processing for one manifest, scheduled only while the output queue has room?

I think this would be good! We might want to make it more granular than each task = "processing for the whole manifest" in order to quickly output the ProcessedManifestFileEntryPtr from next(),

I will implement #105044 first, and if you would like to build the data-manifest side on top, that would be great! I will ping you once it lands.

@aaron276h

Copy link
Copy Markdown
Contributor Author

@asya-ch sounds great, I'll wait for your ping on #105044 and build the data-manifest side on top. Thank you!

@clickhouse-gh

clickhouse-gh Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Dear @Diskein, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself.

@asya-ch asya-ch self-assigned this Aug 6, 2026
@asya-ch asya-ch closed this Aug 6, 2026
@asya-ch

asya-ch commented Aug 20, 2026

Copy link
Copy Markdown
Collaborator

@aaron276h, #105044 has merged, feel free to proceed with the data-manifest side!

(Also, never mind to what I said earlier about "might want to make it more granular than each task = "processing for the whole manifest" in order to quickly output the ProcessedManifestFileEntryPtr from next()", I think that would be overly complicated.)

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 pr-experimental Experimental Feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants