Repository navigation
Read Iceberg manifest files on the IO thread pool and remove the manifest decode pool - #127100
alexey-milovidov merged 10 commits into
Conversation
… reading threads A manifest walk over an Iceberg table with many manifests was bounded by `iceberg_manifest_decode_concurrency`: fetching a manifest (a remote round trip) and parsing it (CPU, about 2 ms per manifest) were one task on a dedicated pool, so only that many round trips overlapped (issue ClickHouse#127061: 671 manifests, 9.6 s at 4, 4.0 s at 32). Manifest files are now read ahead on the IO thread pool, 64 at a time and at most 64 MiB of manifests not in the metadata files cache, and nothing is parsed there. The read goes through `getOrSetManifestFile` as before, so concurrent queries still share one read per manifest and `SYSTEM CLEAR ICEBERG METADATA CACHE` keeps its semantics; the cached cell holds the bytes and parses them on the first `getDeserializer()` call (`std::call_once`). The threads that call `IcebergIterator::next` parse the manifests: each one continues an idle partially read manifest or parses the next one, so parsing keeps the parallelism of the reading threads; with one reading thread the files come in the manifests' order as before. Delete manifests are parsed by the threads that need them, and the last one sorts the deletes. `totalRows` reads ahead and parses on the calling thread. Removed: the manifest decode thread pool and its metrics, the producer thread, the bounded queue and the stop flag of `ManifestFileIterator`, `ParallelManifestDecode.h`. The query settings `iceberg_manifest_decode_concurrency` (and its old name `iceberg_delete_manifest_decode_concurrency`) and `iceberg_file_entries_queue_size`, and the server settings `max_iceberg_manifest_decode_thread_pool_size`, `max_iceberg_manifest_decode_thread_pool_free_size` and `iceberg_manifest_decode_thread_pool_queue_size` are obsolete: accepted and ignored. The integration tests of the decode concurrency now vary `max_threads` instead; the test of the removed pool and the timing test of the removed setting are deleted. Closes ClickHouse#127061 Co-Authored-By: Claude Opus 5.5 <[email protected]>
The iterator built two manifest prefetchers, one for the delete manifests and one for the data manifests, so a snapshot with delete manifests had up to 128 reads and 128 MiB in flight instead of 64 and 64 MiB. Now one prefetcher reads the delete manifests followed by the data manifests: while a delete manifest is not taken, every leased slot belongs to a delete manifest that is in the window or being parsed, and the data reads fill the slots behind them. A stored exception is copied with `copyMutableException` before it is rethrown to another thread. The new test reads a table with more manifests than the read-ahead window, with one and with several reading threads, with and without the metadata cache. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…manifests Before any delete the snapshot summary carries `total-records` and zero delete totals, so the trivial count was answered from the summary and never read a manifest. After the deletes it has to walk the manifest list: it reads the 70 data manifests, more than the read-ahead window, before it meets a delete manifest and falls back to reading the table. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Shorten the ensureDeletesReady header comment to one line and drop a comment repeating the stored-exception note at the top of the same loop. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 3 findings over 3 rounds, 0 on the final head) plus my own review (4 findings).
Severity: ❌ blocker / |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-4:20261021-040400 |
|
cc @scanhex12 @hanfei1991, could you review this and add the |
|
Workflow [PR], commit [dad1ac0] Summary: ✅
AI ReviewSummaryMoves Iceberg manifest reads to a bounded window on the IO thread pool, parses manifests on reading threads, and makes the former decode-pool settings obsolete. No unresolved findings remain; the previous hand-off failure is addressed in the current code. Missing context / blind spots
Final VerdictStatus: ✅ Approve. No additional changes requested. |
Appending a parsed delete manifest's files, or a partially read data manifest, to the shared state allocates under the lock. If that throws, the counter of manifests in progress is already decremented but no exception is stored and nobody is notified, so another reader waiting for that manifest sleeps forever and the query hangs instead of failing. Treat a failure there like a parse failure: store it and notify on every exit. Checked with a local-only fault injection at both hand-offs (two readers, one manifest, slow manifest read): before, the query hangs; after, it fails with the injected error. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ahead is dropped The read-ahead window schedules up to 64 manifest reads on the IO thread pool, and its destructor waits for all of them. A query that stops early (LIMIT, cancellation, an exception) then performs every queued read and waits for it, which is slow when the IO pool is busy. The removed decode pool had stop flags for this. A shared flag set by the destructor makes a read that has not started return immediately. Measured on a debug build, 100 one-file manifests, cold read, 400 ms per manifest read (failpoint), IO pool of 4 threads, `LIMIT 1`: 7.0 s -> 0.98 s. With the default IO pool and for full reads the timings and results are unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A table keeps the metadata files cache of the context it was created with, so `use_iceberg_metadata_files_cache = 0` on a query to it still serves every manifest from the cache (measured: 0 manifest reads, 78 cache hits). Through `icebergLocal` the same reads miss the cache (73 manifest reads), so the read-ahead of more than 64 files on the IO thread pool is now exercised. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes60 object files changed (-33.02 KiB total), 0 added.
719 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 units550 translation units recompiled, 5154 s compile time in total, 549 of them have a recent master baseline. Median compile-time ratio to the baselines is ×1.06 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio. Translation units without a recent master baseline:
|
CI finish ledger - b3ae484Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
CIDB has no Session id: cron:our-pr-ci-monitor:20261021-140009 |
…sts-on-io-pool Co-Authored-By: Claude Opus 5.5 <[email protected]>
Interesting, why. 500 manifests per second sounds okay, but how many can we have in total? |
|
As it was bounded by IO and we make the effective IO parallelism better in this PR, the net effect is positive. But we are also declaring the manifest parsing thread pool obsolete, as we wanted. Let's double-check that this is okay. |
I profiled it (perf on the official 26.11.1.211 build, 200 manifests with one data file each, one decoding thread). The entries are cheap: one manifest with 2000 entries (451 KB) is read and parsed in 0.02 s for the whole query, under 10 us per entry. The ~2 ms is a fixed cost per manifest file, and ~80% of it is one thing:
A prototype that enumerates the subcolumns once per manifest (
For reference, the official master build does the full read in 0.25 s with the default How many manifests: the spec does not bound it. The Java library's merging append compacts small manifests toward 8 MB once 100 can be merged ( I'll send it as a separate PR, since the code is independent of this one and master's decode pool runs it too. If you prefer it here, I'll add it to this PR. |
|
@groeneai, This is great! This means that the original idea for adding a thread pool was wrong, and we should optimize the code instead - exactly as I suspected. Please send a new PR with these optimizations. |
|
|
||
| void ManifestFilesPrefetcher::fill() | ||
| { | ||
| auto runner = threadPoolCallbackRunnerUnsafe<ManifestFileCacheableInfo>(getIOThreadPool().get(), ThreadName::ICEBERG_ITERATOR); |
There was a problem hiding this comment.
However... can we use AsynchronousReadBuffer for that, so everything happens automatically?
There was a problem hiding this comment.
Because we already use it for reading files from S3, iirc.
There was a problem hiding this comment.
I checked, and it cannot do this part by itself. AsynchronousBoundedReadBuffer reads ahead inside one file: prefetch() submits one read of buffer_size at the current offset, at most one at a time, and nextImpl does not submit the next one. createReadBuffer calls prefetch() once, at creation, and only for a small object of known size (use_prefetch in StorageObjectStorageSource.cpp). For data files the overlap across files comes from the sources: each one creates the reader of its next file on its own one-thread pool (createReaderAsync) while it reads the current file.
A manifest is one buffer (19-45 KB in #127061), so there is nothing to read ahead inside it. The gain here comes from up to 64 manifests read at once, and something still has to open them ahead, in order, with a bound. The async buffer could only replace the body of the IO task: fill() would create the buffers and call prefetch() instead of running getManifestFile on the IO pool. That is not simpler, and it costs:
- a
HEADper manifest again: manifests are read without a size (dc0339b) becausemanifest_lengthis not reliable (8 of the 266 manifests in the Iceberg test fixtures record a shorter one), and the async buffer needs the size; - the read would start outside
getOrSetManifestFile, so concurrent queries would each read a manifest that is not cached yet; - dropping the read-ahead (e.g. after
LIMIT 1) waits for every submitted read, because the buffer's destructor waits for its prefetch; here a read that has not started is skipped (coldLIMIT 1, 100 manifests at 400 ms per read,max_io_thread_pool_size = 4: 7.0 s without the skip, 0.98 s with it).
So I'd keep it as is.
|
I sent the optimization as a separate PR: #127782 (200 one-file manifests, metadata cache off, one thread: 0.477 s -> 0.141 s). |
The test (added by ClickHouse#127100) needs more data manifests than the 64 that ManifestFilesPrefetcher reads ahead, so it writes 70 of them with 70 INSERTs and then reads them twice on one thread with a cold metadata cache. Under MSan in the parallel stateless job that costs 1.7-2.6 s per manifest. In master `Stateless tests (amd_msan, parallel, 3/3)` it ran 16 times since the merge: mean 280 s, p99 533 s, max 543 s of the 600 s per-test timeout, so a timeout kill is an ordinary tail event. Per-query time of the 543 s run (master c0e5c9a): 70 INSERTs 111 s, first ALTER DELETE (cold cache) 176 s, icebergLocal with max_threads = 1 193 s, with max_threads = 8 25 s. The mean is 4.7x the 60 s MSan cutoff of ClickHouse#115050. Same remedy as 0d02623 (01721_join_implicit_cast_long) and ClickHouse#125128 (05271_promql_label_matcher_pushdown). The test still runs under ASan, UBSan, TSan, debug and release. Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=c0e5c9ad4ad2ac0426f2d75bf4ef6764dfc01814&name_0=MasterCI&name_1=Stateless%20tests%20%28amd_msan%2C%20parallel%2C%203%2F3%29 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Short multi-threaded Iceberg queries in the performance tests have been slower since this merge, mostly on the aarch64 runners. Today's master runs still show it. Median
What changed in the iterator: before, the producer started decoding the data manifests when @groeneai, does this match what you see on CI hardware? |
|
Yes, it reproduces on the official parent vs merge binaries (Q6 0.039 -> 0.063 s at 16 CPUs): one manifest was handed out one entry per turn, so a stream's next-file read-ahead took a second file while other streams got none. The fix is #129558. |
Closes: #127061
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Iceberg manifest files are now read ahead on the IO thread pool, up to 64 at a time, and parsed by the threads that read the table, so a query over a table with many manifests on object storage overlaps more round trips (3.2x faster on 200 manifests with 400 ms per read). The thread pool for decoding manifests is removed, and the settings
iceberg_manifest_decode_concurrency(and its old nameiceberg_delete_manifest_decode_concurrency),iceberg_file_entries_queue_size,max_iceberg_manifest_decode_thread_pool_size,max_iceberg_manifest_decode_thread_pool_free_sizeandiceberg_manifest_decode_thread_pool_queue_sizeare obsolete and have no effect.Description
As proposed in #127061: fetch manifests on the IO thread pool without decoding there, and remove the decode pool and its settings.
Before, fetching a manifest and parsing it were one task on a dedicated pool, capped at
iceberg_manifest_decode_concurrency(16), so a walk over N uncached manifests cost about N / 16 round trips.Now the IO tasks only read, up to 64 manifests (64 MiB) ahead, through
getOrSetManifestFile, so concurrent queries still share one read per manifest. The cached cell parses its bytes on first use. Parsing costs about 2 ms per manifest, which caps a single parsing thread at ~500 manifests/s, so the threads reading the table do it: each continues an idle partially read manifest or parses the next one. With one reading thread the order is unchanged. Delete manifests are parsed the same way before the first data file is returned.Release build, 200 manifests, 16 CPUs (base / this PR):
max_threads = 1, cold: 0.118 s / 0.469 s (parsing is serial on one reading thread; the initiator of the*Clustertable functions also reads the iterator from one thread)The decode tests now vary
max_threads; the pool test and the timing test of the removed setting are deleted, and a new stateless test reads a table with more manifests than the read-ahead window. Validated with 103 local Iceberg stateless tests x3 and 193 Iceberg integration tests.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/127100]
Version info
26.11.1.765-master(included in26.11and later)