Repository navigation
Build Iceberg manifest filter sets on the query thread instead of the manifest reader thread - #118486
Conversation
… manifest reader thread
`IcebergIterator`'s constructor handed `DataFileEntriesStream` a `prepare` callback that called
`VirtualColumnUtils::buildOrderedSetsForDAG` on the manifest filter DAG, and that stream's
constructor immediately spawns its producer thread, whose `run()` invoked the callback as its first
real statement. The constructing thread meanwhile returned into `createFileIterator`, which wraps the
iterator in `ObjectIteratorWithPathAndFileFilter`, whose member initialiser reaches
`buildSetsForDAG` -> `FutureSetFromSubquery::buildSetInplace` -> `build()`, where
`auto plan = std::move(source)` writes `source` while holding no lock.
Both DAGs are clones of one `filter_actions_dag`, so a `ColumnSet` present in both hands out the same
`FutureSetFromSubquery`. The producer reads that `source` at `PreparedSets.cpp:544` under
`inplace_build_mutex`, then dereferences it at `:549` and `:596`; the writer never takes that mutex,
so a move landing between the check and either dereference is a null dereference on the producer
thread. ThreadSanitizer reports the pair as a race on `unique_ptr<QueryPlan>::release()`.
Two shapes reach the iterator with a set that nothing has prepared yet, because
`ReadFromObjectStorageStep::applyFilters` prewarms the sets on the query thread for the ordinary read
path but not for these: a cluster read, whose coordinator (`IStorageCluster.cpp`) prewarms nothing,
and the `GLOBAL IN` family, which the eager build skips on purpose. In every other shape the callback
was already a no-op, which is why the hoist costs nothing there.
Deleting the parameter rather than relocating the call is deliberate: `DataFileEntriesStream` can then
run no caller-supplied code on its producer thread, so this cannot be reintroduced by the next caller.
The `data_snapshot` guard mirrors `run()`'s own early return, so a snapshot-less read still never
executes the subquery.
Measured with a thread-attribution probe on both shapes, with the producer deliberately delayed by
300 ms in each arm: one set object is touched by two threads before this change and by one thread
after it, and the ordered build now precedes the unordered one on the query thread. That is the
ordering `ReadFromMergeTree.cpp` already enforces for the same shared-`ColumnSet` shape.
`IcebergPartitionPrunedFiles` is unchanged, and delete-manifest decoding, the one overlap this
serialises, measures single-digit milliseconds warm.
Alternatives rejected: a mutex around the sibling builder in `PreparedSets` puts a lock on every
`IN (subquery)` path to compensate for one caller's asynchrony, and is incomplete anyway because both
dispatchers call `future_set->get()` before either builder's lock; `callOnce` is refused by the code's
own comment, since a build may stop without creating the set and must stay retryable; an atomic
pointer gives no lifetime guarantee across `source->clone()`.
One observable change: a set-build failure now propagates out of the constructor with its original
message rather than being re-thrown by `IcebergIterator::next` wrapped as "Iceberg iterator is failed
with exception: {}". No test asserts that wrapper text.
…ares eagerly Covers the two read shapes that reach `IcebergIterator` with a `_path IN (subquery)` filter set that no eager build has prepared: a cluster read, whose coordinator prewarms nothing, and `GLOBAL IN`, which `ReadFromObjectStorageStep::applyFilters` skips on purpose. There was no cluster-based Iceberg stateless test before this one. The fixture is built through the SQL API, one insert per partition, so the snapshot has several data manifests and manifest decoding has real work to do while the sets are prepared. No fixture data is committed and no MinIO is required. Both assertions are fixed values, and `groupArray` is wrapped in `arraySort` because the row order of a parallel read is not stable. The test is therefore a stable functional test everywhere, while the concurrency it sets up is judged by the sanitizer and stress arms, which run this file too. It is not claimed to fail deterministically on an unfixed build. Partition-column variants are deliberately absent. A partition-key set is consumed by `ManifestFilesPruning`'s `KeyCondition` on the manifest decode pool, a route left untouched here, and those threads were measured still entering `buildOrderedSetInplace` on an uncreated set, so such arms could report a race that this change does not claim to fix. `no-fasttest` is the convention for every Iceberg test. No `no-parallel`: the test waits on no failpoint, and its table name and path are derived from the test database.
Internal second-model review: one finding declined with evidence, one noted
💡 Noted, not fixed: the added comment says the sets are shared with a reader "which prepares them |
|
cc @scanhex12 @Michicosun, could you review this? |
|
Workflow [PR], commit [96d5f29] Summary: ❌
AI ReviewSummaryThis PR moves Iceberg manifest-filter set preparation, and the merged-in Final Verdict✅ No new review findings. LLVM Coverage ReportMeasured on commit 96d5f29.
Changed lines: Changed C/C++ lines covered: 29/29 (100.00%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units29 translation units recompiled, 324 s compile time in total, 29 of them have a recent master baseline. |
|
Measurement on the second residual in the description (a partition-key set consumed by a pruning Probe on this branch's binary, Of the reports carrying That is why I am not opening a follow-up for the decode-pool route. |
`Stateless tests (amd_llvm_coverage, old analyzer, s3 storage, DBReplicated, parallel, 2/3)`
failed this file deterministically, 3 of 3 reruns, on its first arm only, while all 250
flaky-check runs and every other configuration passed:
cluster, path filter:
-2 ['v2','v3']
+0 []
That is the old analyzer, and it predates this branch. Reproduced with `enable_analyzer=0`
installed in the server's default profile, which is how that job sets it: the arm reads no rows
on a binary built from this branch and on one built without its source diff, identically. With
the old analyzer nothing prepares the set for this shape, so the coordinator's path filter drops
every listed object and the shards receive no files, while a literal `_path IN ('...', '...')`
over the same cluster function still returns the two rows there, so the filter itself works.
The arm also measures nothing under the old analyzer, which is why pinning fits better than a
`no-old-analyzer` tag that would drop the whole file from that job. On the pre-change binary with
a set-touching probe, the unpinned query enters one mutator on one thread and never calls
`build()`, while the same query with the analyzer pinned, on that same old-analyzer server,
reaches the pair this test exists for: two threads on one set object, one of them the destructive
move. The `GLOBAL IN` arm passes unpinned and stays unpinned.
|
Pushed
It is the old analyzer, and it is not this branch. With The arm also measures nothing under the old analyzer, which is why I pinned rather than tagging the Verified through |
CI finish ledger - 31f31e0Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
The other 12 Session id: cron:our-pr-ci-monitor:20260907-083133 |
| : chunk_size(queue_size_) | ||
| , decode_concurrency(decode_concurrency_) | ||
| , data_snapshot(std::move(data_snapshot_)) | ||
| , prepare(std::move(prepare_)) |
There was a problem hiding this comment.
It was the prewarm hook from #116723 (361823ae9e47e52, "Prewarm the filter's subquery sets before entering the decode pool"): IcebergIterator passed a lambda calling VirtualColumnUtils::buildOrderedSetsForDAG(*manifest_filter_dag, local_context), and DataFileEntriesStream::run() called it once before scheduling any decode task.
Its purpose was ordering. The filter DAG is consumed on the manifest decode pool (createManifestIterator -> ManifestFileIterator), so a decode task that built an IN (SELECT ...) set itself could deadlock: if the subquery read another Iceberg table, the nested read scheduled its own tasks on that same pool and the outer task waited behind itself once the pool saturated. Every set had to be built before the first decode task existed.
That invariant still holds, just enforced earlier: the same call now runs in IcebergIterator's constructor before data_files_stream is created, and the producer thread is started inside DataFileEntriesStream's constructor, so no producer and no decode task exist yet at that point. run() returned early on !data_snapshot, so the new site keeps that as if (data_snapshot && manifest_filter_dag). DataFileEntriesStream has exactly one construction site in the tree, so no caller is left needing a hook there.
What was wrong was the thread, not the work. In StorageObjectStorageSource::createFileIterator the same filter_actions_dag is used twice in a row: configuration->iterate(...), which started the producer that ran the callback, and then ObjectIteratorWithPathAndFileFilter, whose constructor calls buildSetsForDAG on the calling thread. Both reach the same FutureSetFromSubquery, which is the race in #118784.
…r-thread Master gave the `DataFileEntriesStream` prepare callback a second job in dff00ce and 5dd260b: besides building the manifest filter DAG's ordered sets it now also constructs the `ManifestListPruner`. This branch removes that callback, so both jobs move to the `IcebergIterator` constructor, in the same order, keeping master's manifest-list partition pruning and its pruned-files counter intact. Moving the pruner construction is required, not incidental. It builds a `KeyCondition` over the filter DAG, and `KeyCondition` materializes an `IN (subquery)` right side through `FutureSetFromSubquery::buildOrderedSetInplace`. Left on the producer thread it would keep reading the shared set while the query thread writes it in `FutureSetFromSubquery::build`, which is the unguarded `std::move(source)` this branch exists to serialize. The pruner is now built before `DataFileEntriesStream` exists, so the producer thread that reads it is created afterwards and observes it through the thread creation itself.
|
Merged master to clear the conflict. It was not purely textual, so the resolution is worth a note. Master gave the Master's manifest-list pruning and its pruned-files counter are unchanged: |
CI finish ledger - 96d5f29Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Attribution, measured rather than assumed:
Session id: cron:our-pr-ci-monitor:20260911-183208 |
|
Follow-up asked for on #118959: this change should be paired with removing That mutex ( Proposed additional fix, two call sites and no plumbing: pass Behaviour cost: none once the sets are prepared in the constructor. Only the break/timeout state differs, where manifest-file pruning is skipped for that set instead of the build being retried on a decode thread. I can push both parts here (the two flags, plus deleting the mutex and its lock site), or send them as a separate PR against master once this merges. |
b390c78
|
The follow-up proposed above is now #124804 (removes |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Description
ThreadSanitizer reports a data race on a
FutureSetFromSubquery'ssource(
unique_ptr<QueryPlan>) in one Iceberg query. Four unrelated PRs hit it in 22 hours onStress test (*_tsan); one names the deleted lambda (frames below).IcebergIterator's constructor gaveDataFileEntriesStreamapreparecallback that built themanifest filter sets, and that stream's constructor immediately spawns the producer thread running
it. The constructing thread meanwhile prepares the same sets via
buildSetInplace->build(),whose
std::move(source)writessourceunlocked while the producer dereferences it under aninplace_build_mutexthe writer never takes. A move in between null-dereferences on the producerthread.
The fix deletes the callback and builds the sets in the constructor body, before
data_files_streamexists, so no set is built on its producer thread.ReadFromObjectStorageStep::applyFiltersalready does this for the ordinary read path. Thecallback came from #116723, which is in no release, hence
Not for changelog.The master merge here had to move one more thing. Master gave that same callback a second job,
constructing the
ManifestListPruner, whoseKeyConditionmaterialises anIN (subquery)rightside through
buildOrderedSetInplace. Leaving it on the producer thread would have kept the accessthis PR serialises, so it runs in the constructor too, after the set build it depends on.
05045_iceberg_manifest_partition_aritystill passes, its pruning counters included.A thread-attribution probe on the two unprepared-set shapes (cluster,
GLOBAL IN) shows one settouched by two threads before the change and one after, with the producer still delayed 300 ms. No
lock is added. The new test asserts results only, so CI's sanitizer arms are its race oracle
(no local TSAN report: self-connecting queries hang on my TSAN build).
A set-build failure now propagates from the constructor with its original text, not
next()'s"Iceberg iterator is failed with exception" wrapper, which no test asserts.
Residual: a partition-key set is consumed by a pruning
KeyConditionon the decode pool, a routethis PR leaves untouched, so the test has no partition-column arm. A 20-run probe found none of
those pool entries holding a live
source, so no race is demonstrated there.CI provenance: 4 unrelated carriers, 0 master rows, 90 days
9f16968a6bb14ac9d78d1e19debb128c12bab92a5ca71f4fAnchored on the changed file: an unanchored
FutureSetFromSubquery::buildmatch also catchesbuildOrderedSetInplace, pulling in an unrelated bloom-filter-index report. The last row is clearest,attributing the access to
IcebergIterator::IcebergIterator(...)::$_0::operator()() IcebergIterator.cpp:357:17, the deletedpreparelambda. No carrier touchesPreparedSets.cpp,VirtualColumnUtils.cpp,IObjectIterator.cpp,StorageObjectStorageSource.cppor any Iceberg file.Workflow [PR]
Sync PR [sync-upstream/pr/118486]
Version info
26.10.1.387-master(included in26.10and later)