Repository navigation
Conversation
`ActionsDAG::clone` shares one `FutureSetFromSubquery` between the Iceberg manifest filter DAG and the path/file filter DAG, so the Iceberg manifest producer thread and the query thread can build that set at the same time: the producer runs `buildOrderedSetInplace` from the `prepare` callback of `DataFileEntriesStream`, while the query thread runs `buildSetInplace` from the `ObjectIteratorWithPathAndFileFilter` constructor. 323aee4 added `inplace_build_mutex` for exactly this situation, but only `buildOrderedSetInplace` takes it. `buildSetInplace` reaches `build`, whose `std::move(source)` destroys the pointer the locked builder tests and then dereferences, which ThreadSanitizer reports as a data race on `FutureSetFromSubquery::source`. Holding the mutex across the whole in-place build, rather than around the pointer alone, is what makes the second arrival wait for the first build's outcome instead of finding `source` already taken and silently skipping. The re-test it then performs is `build`'s existing `isCreated()` gate, so no new readiness state is introduced and a build that stops without creating the set stays retryable, which is why `callOnce` is still not usable here. The lock serializes the two in-place builders and nothing more: the deferred build hands a plan to the pipeline by design, so a waiter's set is not necessarily ready afterwards. The new test is a cluster read of a local Iceberg table filtered by `_path IN (subquery)`, which is the only shape in the tree that reaches both builders concurrently. Its assertions are deterministic; the concurrency oracle is the sanitizer and stress arms. Related: ClickHouse#118784 Co-Authored-By: Claude Opus 5 <[email protected]>
… in 05105 The test's only oracle is CI's sanitizer and stress arms observing the two in-place set builders overlap, so it has to reach both builders. The manifest-pruning builder has two gates. makeManifestFilterDag returns nullptr when use_iceberg_partition_pruning is false, so the Iceberg iterator's constructor never calls buildOrderedSetsForDAG and there is no second builder; and buildOrderedSetInplace returns before its lock when use_index_for_in_with_subqueries is false. The first of those is reachable in CI without touching the test: SettingsChangesHistory records the default flip in 25.6, and the stress runner passes compatibility='<20..26>.<1..12>' on 20% of runs, which reverts it. The test then still prints its expected output while exercising nothing. Pin both in the query, where the value beats the runner's client option. The helper table was created with a fixed name and never dropped, while clickhouse-test skips the per-test database drop whenever --database is passed and the stress runner passes --database=test_<i> for every odd worker. A second execution in such a worker failed with TABLE_ALREADY_EXISTS, a false failure in the arm that carries the oracle. Give it the per-database suffix and the DROP-before-CREATE the other table already had, and drop it at the end. No change to the expected output, and no source change. Co-Authored-By: Claude Opus 5 <[email protected]>
…s claim
The previous round made the helper table re-runnable but not the Iceberg
directory, and the directory is the harder half: DROP TABLE does not delete
Iceberg data, because iceberg_delete_data_on_drop defaults to false, and the
trap that removes it is skipped when clickhouse-test kills a timed-out test's
process group. Measured directly: six data files before the DROP, the same six
after it. With a fixed directory name the next execution in the same database
then creates the table over the leftover snapshot, so the deterministic
assertion no longer holds. Measured: the previous file fails with
"Iceberg table with path ... already exists" and prints 0 0 instead of 20 5090.
The stress runner also passes ignore_drop_queries_probability=0.2, and an
ignored DROP of a table that stores data on disk returns without dropping, so
the helper table can survive its own DROP IF EXISTS as well.
Give both names a per-run suffix, which makes the directory per-run too, and
remove the directory before the CREATE, as the other IcebergLocal tests do.
Both are conventional here: 224 stateless shell tests use a ${RANDOM} suffix.
The header claimed no other test reaches the racing pair, which was never
measured. It is now: 05043_object_storage_path_virtual_column_empty_namespace
filters _path with a subquery on an IcebergLocal table, and an instrumented run
of it reaches only the ordered builder, on one thread. A plain local read
finishes the set during analysis, so the manifest producer and the iterator
constructor both find it already created and skip; disabling
use_index_for_in_with_subqueries there brings the second builder back, one
thread, no overlap. The cluster read is what leaves the set unbuilt for two
threads at once. Say that instead of the unmeasured claim.
The oracle survives the rename: the two builders still meet on one set object
with an 802 ms arrival overlap, including on a second run in the same database.
No change to the expected output, and no source change.
Co-Authored-By: Claude Opus 5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex) over three rounds, alongside my own cold
Severity: ❌ blocker / On the deadlock question a lock now held across a pipeline run raises: no cycle is reachable, because One randomized knob the earlier rounds had not named was checked in the last pass and needs no pin: Noted, not blocking: the co-located publication of Session id: cron:clickhouse-review-slot-48:20260908-172000, cron:clickhouse-review-slot-49:20260908-214900, cron:clickhouse-review-slot-9:20260909-041200 |
|
Workflow [PR], commit [dc5452e] Summary: ❌
AI ReviewSummaryThis PR takes Findings❌ Blockers
Final Verdict❌ Changes requested. The LLVM Coverage ReportMeasured on commit dc5452e.
Changed lines: Changed C/C++ lines covered: 3/3 (100.00%) · Uncovered code |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-5:20260908-134300, cron:clickhouse-impl-slot-4:20260908-210300, cron:clickhouse-impl-slot-4:20260909-030300 |
|
cc @nickitat @yariks5s, could you review this? |
| { | ||
| /// `build` below moves `source` out, and `buildOrderedSetInplace` tests and dereferences it under | ||
| /// this mutex, so both in-place builders must hold it. Rationale at the other lock site. | ||
| std::lock_guard lock(inplace_build_mutex); |
There was a problem hiding this comment.
This lock fixes the source move/dereference race, but it still leaves a second unsynchronized shared state in the same two-thread Iceberg path: buildOrderedSetInplace can replace set_and_key->set, while plain readers like FutureSetFromSubquery::get() and VirtualColumnUtils::buildSetsForDAG still read that member without inplace_build_mutex. Because ActionsDAG::clone / ColumnSet::cloneDummy keep the same FutureSet shared between the manifest and path/file DAGs, one thread can be publishing the new SetPtr while the other is inside the unlocked get() probe. I think set_and_key->set needs the same synchronization discipline (or an atomic publication) before this race is actually closed.
There was a problem hiding this comment.
The mechanism is right, and it is a different race from the one this PR closes.
get() (PreparedSets.cpp:329) reads set_and_key->set with no lock, and buildOrderedSetInplace republishes that pointer at :543 and :758. Neither site changes here: the whole src/ diff is one std::lock_guard in buildSetInplace, and the ordered publication has been inside inplace_build_mutex since 323aee4fbfe7fa0 (2026-08-27), before this PR. So the pointer race is pre-existing, and this change neither creates nor widens it. The description already names it as a separate defect the new test can surface next.
Giving every read of set_and_key->set the same lock would not be a synchronization-only change. get() has 20 call sites in src/; the other writer, CreatingSetsTransform.cpp:143, holds a SetAndKeyPtr and no FutureSetFromSubquery, so it cannot take that mutex at all; and two of the readers are deliberately non-blocking readiness probes, KeyCondition.cpp:2906 under require_ready_sets and LazyFinalKeyAnalysisTransform.cpp:67. A blocking get() would make index analysis wait for exactly the subquery build those two guards exist to skip.
Whether to fold that publication in or keep it separate is already asked in the issue, #118784 (comment). I would rather follow the answer there than widen this PR now.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 11 s compile time in total, 7 of them have a recent master baseline. |
CI finish ledger - dc5452eEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task whose
Session id: cron:our-pr-ci-monitor:20260909-100059 |
| { | ||
| /// `build` below moves `source` out, and `buildOrderedSetInplace` tests and dereferences it under | ||
| /// this mutex, so both in-place builders must hold it. Rationale at the other lock site. | ||
| std::lock_guard lock(inplace_build_mutex); |
There was a problem hiding this comment.
At what point the second thread will understand that the set was already built and will bail out? In other words, how do we guarantee that there will be no attempt to build the same set for the second time.
There was a problem hiding this comment.
The second entrant does not bail at the top of buildSetInplace; it bails one frame down, in build(), on either of two predicates:
PreparedSets.cpp:420if (set_and_key->set->isCreated()) return nullptr;(the set is already built), or:430auto plan = std::move(source);with:432 if (!plan) return nullptr;(an earlier in-place build already consumed the plan).
buildSetInplace then returns at :487 on the null plan. If that earlier build consumed source and threw, :427 rethrows the recorded failure instead of silently returning. Nothing ahead of the build() call rebuilds this set either: the statements in between are read-only or isCreated()-guarded (prepareForDistributedPlan, :447), and the external_table_set recursion at :466-467 bails on those same two predicates in its own build().
On the ordered path the same re-check is explicit and first after the lock: :530 if (auto set = get()), get() at :329 testing isCreated(), then :548 if (!source).
Both predicates predate this PR. What the lock adds is that they are now evaluated under the same mutex as the build that invalidates them. Before it, :420 and :430 ran unsynchronized against buildOrderedSetInplace, so two threads could both read "not created, source non-null" and both proceed, which is the reported race on the source handoff. Serialized, the second entrant reads state the first one finished publishing at :757-759.
One re-attempt is intentional: a speculative ordered build can stop without creating the set (subquery timeout with overflow_mode = 'break') while preserving source through a clone, and the next entrant retries it. That is why this is a mutex and not callOnce (:525-527).
The comment I added at the lock states only the source-handoff half, which is narrower than what the lock guarantees. Happy to push this wording instead if you prefer it:
/// Serializes with `buildOrderedSetInplace`: both in-place builders must test "already built"
/// (`isCreated()` in `build`) and consume `source` under the same mutex, or two threads can
/// both decide to build and then race on the `source` handoff.
|
For the race in #118784, yes. #118486 removes the second builder: it deletes the This PR is not a second fix for that stack. It closes an asymmetry: What #118486 leaves, measured: its constructor build runs over the same No behaviour change, and the mutex has two lock sites ( |
|
Yes, once one more path is closed, and closing it is two lines. #118486 removes the state, not the sharing. On its head The two lines are So I would drop this PR rather than have it add a lock to a mutex that is going away; close it whenever suits you, or keep it as an interim if you would rather not wait for #118486. Once #118486 lands I will send those two lines plus the removal of |
|
Done: #118486 (comment) (removal of |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Serialize the two in-place builds of one
FutureSetFromSubqueryagainst each other.Description
Stress test (*_tsan)reports a data race onFutureSetFromSubquery::source, filed as #118784 andrequested in #115798 (comment). 14 stress
jobs on 13 pull requests over 14 days, none on master.
ActionsDAG::cloneshares oneFutureSetFromSubquerybetween the Iceberg manifest filter DAG and thepath/file filter DAG, so the manifest producer and query threads build it at once.
323aee4fbfe7fa0addedinplace_build_mutexfor this, but onlybuildOrderedSetInplacetakes it:buildSetInplacereachesbuild'sstd::move(source)unlocked and destroys the pointer the lockedbuilder is dereferencing.
The change is one
std::lock_guard, held across the whole in-place build. The issue's objection that aplain mutex is not sufficient holds for a pointer-scoped lock, where the second caller finds
source == nullptrand skips; held across the build, the second arrival waits and re-tests throughbuild's existingisCreated()gate. In a reproducer the second builder moves from inside the first's802 ms build to waiting for it and seeing
isCreated() = 1; removing the line restores the overlap.Measured: a plain local read does not reach this pair, because its set is built during analysis.
#118486 removes the Iceberg callback behind today's second builder; this closes the missing half of the
lock, as the issue asks.
Scope: the lock serializes the two in-place builders; it does not make a waiter's set ready, because the
deferred
build()is a plan handoff by design.SetAndKey::set's publication in this vehicle isunsynchronized, a separate defect the new test can surface next.
buildSetInplacealso records nofailure reason when a build throws; that code is released, so it needs a different changelog category.
Regression corpus and 50 randomized runs of the new test are green, no hangs. A 16-way
IN-subquerybenchmark stays inside its own noise (median 3144 vs 3352 QPS, base spread 9.2%, p99 unchanged).
CIDB census: 14 rows / 13 pull requests / 0 master, last 14 days
Workflow [PR]
Sync PR [sync-upstream/pr/118959]