Skip to content

Fix data race on FileCacheQueryLimit::query_map causing LOGICAL_ERROR - #107028

Merged
alexey-milovidov merged 6 commits into
ClickHouse:masterfrom
groeneai:fix-filecache-query-limit-race
Jul 12, 2026
Merged

alexey-milovidov merged 6 commits into
ClickHouse:masterfrom
groeneai:fix-filecache-query-limit-race

Conversation

@groeneai

@groeneai groeneai commented Jun 10, 2026 •

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

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

Fix a rare LOGICAL_ERROR "Attempt to release query context that does not exist" and the accompanying server crash when reading MergeTree tables through a filesystem cache disk created with enable_filesystem_query_cache_limit = 1.

Description

FileCacheQueryLimit::query_map (a std::unordered_map) was reachable from two different cache locks with no single lock serializing it:

  • the read tryGetQueryContext (query_map.find) runs under CacheStateGuard::Lock (called from FileCache::doTryReserve, once per reservation);
  • the writes getOrSetQueryContext (query_map.emplace) and removeQueryContext (query_map.erase) run under CachePriorityGuard::WriteLock (called from FileCache::getQueryContextHolder and ~QueryContextHolder).

Since the read takes a different mutex than the writes, a find() can run concurrently with an emplace()/erase() that rehashes the table and invalidates buckets and iterators. That is undefined behaviour on std::unordered_map and surfaces as either Attempt to release query context that does not exist (the map is corrupted so a present key looks absent in removeQueryContext) or a server crash while reading a half-rehashed bucket. Both were seen together in the same CI run on Stateless tests (amd_debug, sequential).

The split appeared when tryGetQueryContext was moved from the priority write lock to the cheaper cache state lock, leaving the map reachable from two locks at once.

Fix: guard all three query_map accessors with a dedicated leaf mutex, so the map has a single owning lock regardless of which cache lock the caller holds. The mutex is taken last and never nests another cache lock under it, so it does not change the existing lock order, and the optimization of keeping the read off the priority write lock is preserved.

Reproduced with a concurrent reader/writer witness over an S3-backed cache disk with enable_filesystem_query_cache_limit = 1: 2073 overlapping accesses to query_map without the fix, 0 with it.

Follow-up: last-holder release leak (#109508)

@ Algunenano found a related issue by code analysis (#109508): the last-holder decision in ~QueryContextHolder still dropped this holder's own reference to the context outside the cache lock, and removeQueryContext gated the erase on use_count() > 2 before that drop. use_count() is not a synchronization primitive, so this is a TOCTOU. A query with parallel read streams has several holders for the same query_id (each CachedOnDiskReadBufferFromFile creates its own), so use_count > 2. When two holders release at the same time both observe the shared count, both skip the erase, and after both drop their reference only the map entry remains and is never removed. That orphans query_map[query_id] for the lifetime of the cache, so a later query reusing the same query_id picks up stale per-query limit state.

Fix: drop this holder's reference inside removeQueryContext under query_map_mutex and erase only once the map entry is the sole owner (use_count() == 1). Every reference change to the context is then serialized by the lock that also guards getOrSetQueryContext, so the check-and-erase is atomic with respect to concurrent holders. Added FileCacheTest.QueryLimitConcurrentReleaseNoLeak, which drives the concurrent-release interleaving deterministically (fails on the previous use_count() > 2 logic, passes now).

Related: #109508

Version info

  • Merged into: 26.7.1.840 (included in 26.7 and later)
  • Backported to: 26.6.3.44, 26.5.7.53, 26.3.18.29, 25.8.30.20

FileCacheQueryLimit::query_map (a std::unordered_map) was accessed under two
different cache locks with no single lock serializing it:

  - read  (tryGetQueryContext, query_map.find) runs under CacheStateGuard::Lock,
    called from FileCache::doTryReserve once per reservation;
  - writes (getOrSetQueryContext, query_map.emplace; removeQueryContext,
    query_map.erase) run under CachePriorityGuard::WriteLock, called from
    FileCache::getQueryContextHolder and ~QueryContextHolder.

Because the read uses a different mutex than the writes, a find() can run
concurrently with an emplace()/erase() that rehashes and invalidates buckets
and iterators. This is undefined behaviour on std::unordered_map and shows up
as either "Attempt to release query context that does not exist" (the map was
corrupted so a present key looks absent in removeQueryContext) or a server
crash while reading a half-rehashed bucket. Both were observed together in the
same CI run on Stateless tests (amd_debug, sequential).

The split was introduced when tryGetQueryContext was moved from the priority
write lock to the cheaper cache state lock, which left the map reachable from
two locks at once.

Guard all three query_map accessors with a dedicated leaf mutex so the map has
a single owning lock regardless of which cache lock the caller holds. The mutex
is taken last and never nests another cache lock under it, so it cannot change
the existing lock order. The earlier optimization of keeping the read off the
priority write lock is preserved.

Reproduced with a concurrent reader/writer witness: 2073 overlapping accesses
to query_map without the fix, 0 with it.
@groeneai

Copy link
Copy Markdown
Collaborator Author

Pre-PR validation gate

# Question Answer
a Deterministic repro? Yes. Built an env-gated reader/writer witness into FileCacheQueryLimit and drove 50 concurrent distinct-query_id reads over an S3-backed cache disk with enable_filesystem_query_cache_limit = 1. The witness fired 2073 times (a writer modifying query_map while a reader was inside it). Deterministic on demand.
b Root cause explained? Yes. query_map (std::unordered_map) is read in tryGetQueryContext under CacheStateGuard::Lock but written (emplace/erase, which rehash and invalidate iterators) in getOrSetQueryContext/removeQueryContext under CachePriorityGuard::WriteLock. Two different mutexes guard one container, so a find() races a rehashing emplace()/erase(). That UB corrupts the map (a present key looks absent in removeQueryContext, raising the LOGICAL_ERROR) or crashes the server reading a half-rehashed bucket. Both appeared together in the CI run.
c Fix matches root cause? Yes. A dedicated leaf mutex query_map_mutex now serializes all three query_map accessors, so the map has a single owning lock regardless of which cache lock the caller holds. This directly closes the two-lock split, not a symptom.
d Test intent preserved / new tests added? The change adds no test-weakening. Existing query-limit tests (02240_filesystem_query_cache, 02503_cache_on_write_with_small_segment_size) still pass. A deterministic data-race regression test is hard to make non-flaky in the stateless suite; the race is validated by the witness (see e). Happy to add a targeted concurrency test if reviewers prefer.
e Both directions demonstrated? Yes. Same concurrent blast: 2073 overlapping query_map accesses without the fix, 0 with the fix. Server stayed healthy and 200 query-limit reads completed with 0 errors after the fix.
f Fix is general, not a narrow patch? Yes. All three (and the only three) query_map accessors are guarded. The sibling per-query priority-queue data in QueryContext is correctly partitioned across CacheStateGuard (counters) and CachePriorityGuard (queue structure) by the existing IFileCachePriority lock contract, so it is not affected; only query_map was left without a single owning lock. The mutex is a leaf (taken last, no nested cache lock under it), so it does not alter the documented lock order.

Session id: cron:clickhouse-worker-slot-1:20260610-143600

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @kssenii could you review this? It fixes a data race on FileCacheQueryLimit::query_map: the map is read under CacheStateGuard but written (emplace/erase, which rehash) under CachePriorityGuard, so a concurrent find vs rehashing write corrupts it, producing the Attempt to release query context that does not exist LOGICAL_ERROR or a server crash. Fix serializes all three accessors with a dedicated leaf mutex.

@PedroTadim PedroTadim added the can be tested Allows running workflows for external contributors label Jun 10, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 10, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [5ff6ffc]

Summary: ✅


AI Review

Summary

This PR fixes the FileCacheQueryLimit locking/lifetime bugs in three places: query_map now has a single owning mutex, the last-holder decision is made inside the serialized release path, and the final QueryContext destruction is deferred until after the cache write lock is released. I rechecked the current head against the prior review threads and did not find any remaining correctness or lifecycle issues in the changed code.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Jun 10, 2026
The previous commit serialized query_map access with query_map_mutex, which
fixed the data race that corrupted the map (LOGICAL_ERROR / Server died). But
the last-holder decision (use_count() == 2) in ~QueryContextHolder was still
made before any lock was taken. A real interleaving remained:

1. the only holder sees use_count() == 2 and decides to release;
2. before it reaches removeQueryContext, another buffer for the same query_id
   calls getOrSetQueryContext and revives the same context;
3. this holder then erases the map entry anyway.

The new holder stays alive but its query_map entry is gone, so subsequent
tryGetQueryContext calls cannot find it and enable_filesystem_query_cache_limit
stops being enforced for the rest of the query. A later release of the revived
context then fails to find its entry (the "Attempt to release query context
that does not exist" LOGICAL_ERROR).

Move the decision into removeQueryContext, made under the cache write lock that
also serializes getOrSetQueryContext, and only erase when the map still points
at this exact context and use_count() == 2 (compare-and-erase). A revived or
already-removed entry is left untouched instead of throwing.

Adds a unit test (FileCacheTest.QueryLimitContextRevivedDuringRelease) that
reproduces the revive-during-release interleaving: it fails on the previous
code (the revived context becomes undiscoverable) and passes with this change.

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

Copy link
Copy Markdown
Collaborator Author

Pre-PR validation gate (updated for HEAD eff66eb, follow-up commit)

This covers the second commit, which addresses the review comment that the last-holder decision was still made before any lock.

# Question Answer
a Deterministic repro? Yes. New unit test FileCacheTest.QueryLimitContextRevivedDuringRelease reproduces the revive-during-release interleaving deterministically (no threads, no failpoints): holder1 takes the context, holder2 revives it via getOrSetQueryContext, holder1 releases. Run: build/src/unit_tests_dbms --gtest_filter="FileCacheTest.QueryLimitContextRevivedDuringRelease".
b Root cause explained? The first commit serialized query_map with query_map_mutex (fixed the map-corruption crash). But ~QueryContextHolder still made the last-holder decision (use_count() == 2) before taking any lock. Between that check and the erase, another buffer for the same query_id can call getOrSetQueryContext (under the cache write lock) and revive the same context. The dying holder then erases the entry of a still-live holder, so tryGetQueryContext returns null and enable_filesystem_query_cache_limit stops being enforced; the later release of the revived context then throws "Attempt to release query context that does not exist".
c Fix matches root cause? Yes. The decision is moved into removeQueryContext, made under the cache write lock that also serializes getOrSetQueryContext, with compare-and-erase: only erase when the map still maps query_id to this exact context AND use_count() == 2. A revived or already-removed entry is left in place instead of throwing. This is exactly the change requested in review.
d Test intent preserved / new tests added? New regression test added (white-box on FileCacheQueryLimit). It asserts both post-conditions the old code violated: the revived context stays discoverable after holder1 releases, and the final release removes it exactly once without throwing. No existing test weakened; all 22 FileCacheTest.* pass.
e Both directions demonstrated? Yes. Against the previous (first-commit) code the test FAILS: after holder1 releases, tryGetQueryContext returns NULL while holder2's context is still live (enforcement gap). With this commit the test PASSES. Full FileCacheTest.* suite: 22/22 pass.
f Fix is general, not a narrow patch? Yes. removeQueryContext is the single erase path for query_map, and getOrSetQueryContext is the single revival path; both now run under the same cache write lock and the compare-and-erase covers every revive/erase ordering, not just the one interleaving in the test. No sibling code path performs an unguarded last-holder decision. The fix is at the source (the decision point), not a symptom guard.

Session id: cron:clickhouse-worker-slot-1:20260610-184028

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI fully finished (Finish Workflow passed). Failures, both pre-existing chronic classes, none PR-caused (this PR fixes the FileCacheQueryLimit data race):

  • Stateless tests (arm_asan_ubsan, azure, sequential) -- azure-infra-outage / db-disk "Server died" chronic class.
  • Stress test (arm_ubsan) -- generic stress instability (deadlock/hung/fault harness markers).
    No Fast/Bugfix/Style failure.

@kssenii kssenii self-assigned this Jun 15, 2026
Comment on lines +36 to +42
if (query_iter == query_map.end() || query_iter->second != context)
{
throw Exception(
ErrorCodes::LOGICAL_ERROR,
"Attempt to release query context that does not exist (query_id: {})",
query_id);
/// The entry was already removed, or was re-created for a newer holder via
/// getOrSetQueryContext after this holder decided to release. Both writers run
/// under the same cache write lock, so observing a different (or missing) context
/// here means another live holder now owns it. Leave it in place.
return;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Was a test added for this case? Why can we try to remove query context twice?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes. FileCacheTest.QueryLimitContextRevivedDuringRelease in src/Interpreters/tests/gtest_filecache.cpp covers this case. It drives the revive-during-release interleaving deterministically: holder1 takes the context (use_count() == 2); holder2 revives it via getOrSetQueryContext before holder1 releases (use_count() == 3); holder1 releases, which must be a no-op so the revived context survives and stays discoverable via tryGetQueryContext; then holder2 releases and the entry is removed exactly once with no throw. It fails against the pre-fix logic (the revived context becomes undiscoverable, so per-query enforcement is lost) and passes with this change. The full FileCacheTest.* suite is green.

On why a query context can be released more than once: a single query opens one CachedOnDiskReadBufferFromFile per cached file it reads, and each buffer constructs its own QueryContextHolder for the same query_id (getQueryContextHolder hands back the shared context via getOrSetQueryContext). On teardown each ~QueryContextHolder calls removeQueryContext, so the same query_id is released once per buffer. Before this PR the last-holder check (use_count() == 2) was made in ~QueryContextHolder before any lock, so a late release could erase an entry that a still-live or just-revived holder owned, and that stale release threw Attempt to release query context that does not exist. The check now lives in removeQueryContext under the cache write lock (which also serializes the getOrSetQueryContext revival path), with compare-and-erase: it erases only when the map still maps query_id to this exact context and no other holder is alive (use_count() is just the map entry plus this release). Otherwise it is a no-op. A duplicate or late release is then a legitimate concurrent outcome, not an invariant violation.

groeneai and others added 2 commits July 6, 2026 16:40
… context leak

The last-holder decision in ~QueryContextHolder still dropped this holder's
own reference to the query context outside the cache lock, and removeQueryContext
gated the erase on use_count() > 2 before that drop. A query with parallel read
streams has several holders for the same query_id, so when two of them release at
the same time both observe the shared count, both skip the erase, and after both
drop their reference only the map entry remains and is never removed. That orphans
query_map[query_id] for the lifetime of the cache; a later query reusing the same
query_id then picks up stale per-query limit state.

Move the reference drop into removeQueryContext under query_map_mutex and erase
only once the map entry is the sole owner, so every reference change to the context
is serialized by the lock that also guards getOrSetQueryContext.

Add FileCacheTest.QueryLimitConcurrentReleaseNoLeak, which reproduces the
concurrent-release leak deterministically (fails on the previous logic, passes now).

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

groeneai commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator Author

Follow-up commit 4808dae addresses #109508 (last-holder release leak), which @ Algunenano filed after reviewing this PR. The query_map_mutex change and the crash fix from the earlier commits are unchanged.

Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. FileCacheTest.QueryLimitConcurrentReleaseNoLeak drives the concurrent-release interleaving deterministically: two holders take the same context (use_count == 3), both call removeQueryContext while both are alive, then assert the map entry is gone.
b Root cause explained? ~QueryContextHolder dropped this holder's own context reference outside the cache lock, and removeQueryContext gated the erase on use_count() > 2 before that drop. use_count() is not a synchronization primitive, so this is a TOCTOU: two holders releasing at once both observe the shared count (3), both skip the erase, then both drop their reference, leaving only the map entry, which is never removed. query_map[query_id] is orphaned for the lifetime of the cache and a later query reusing the id inherits stale per-query limit state.
c Fix matches root cause? Yes. The holder's reference is dropped inside removeQueryContext under query_map_mutex, and the erase fires only when the map entry is the sole owner (use_count() == 1). Every reference change is now serialized by the lock that also guards getOrSetQueryContext, so the check-and-erase is atomic w.r.t. concurrent holders.
d Test intent preserved / new tests added? Yes. The existing QueryLimitContextRevivedDuringRelease test still passes (revive-during-release path). Added QueryLimitConcurrentReleaseNoLeak covering the new leak scenario.
e Both directions demonstrated? Yes. The new test FAILS on the previous use_count() > 2 logic (entry leaks, context1 not reset) and PASSES with the fix. Full FileCacheTest.* suite (27 tests) green.
f Fix is general across code paths? Yes. removeQueryContext and ~QueryContextHolder are the only places the last-holder decision and reference drop happen; both are covered. A codebase sweep (noted in #109508) found this the only remaining unlocked-use_count()-gates-mutation site.
g Fix generalizes across inputs? N/A. Not an input-shaped code bug; the fix is a lock-ordering/ownership correction independent of column types or query inputs.
h Backward compatible? Yes. No setting, format, or on-disk change. Pure internal serialization of an in-memory map; only the private removeQueryContext signature changed (const QueryContextPtr& → QueryContextPtr&).
i Invariants and contracts preserved? Yes. Lock order unchanged (query_map_mutex is still the innermost leaf lock, taken under the cache write lock, nesting nothing). Ownership invariant strengthened: after the last holder releases, query_map holds no dangling entry, and a still-alive holder always keeps its entry discoverable.

Session id: cron:clickhouse-worker-slot-7:20260706-162800

The last-holder path in removeQueryContext erased the query_map entry while
~QueryContextHolder still held the global cache WriteLock. Being the sole owner
at that point, the erase destroyed the whole QueryContext (its per-query records
map and LRUFileCachePriority queue) under cache->lockCache(), so a query that
touched many segments freed all of that state while holding the lock and could
block unrelated reserve/eviction work for the duration of teardown.

Extract the doomed QueryContextPtr from the map under query_map_mutex and return
it, so the caller destroys it after the cache write lock scope has ended. This
restores the pre-ClickHouse#109508 teardown timing (the context used to destruct when the
holder member fell out of scope, after the lock released) while keeping the
under-lock compare-and-erase that fixes the leak and the revival race. The
QueryContext and LRU iterator destructors take no cache locks, so destroying it
outside the lock is safe.

Extend FileCacheTest.QueryLimitConcurrentReleaseNoLeak and
QueryLimitContextRevivedDuringRelease to assert that only the last release hands
the context back (use_count 1) for out-of-lock destruction and earlier releases
return nullptr.

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

groeneai commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. FileCacheTest.QueryLimitConcurrentReleaseNoLeak and QueryLimitContextRevivedDuringRelease reproduce the last-holder / revival interleavings deterministically (no threads, no failpoints).
b Root cause explained? The last-holder erase ran inside ~QueryContextHolder while it still held the global cache WriteLock. Being the sole owner, the erase destroyed the whole QueryContext (per-query records map + LRUFileCachePriority queue) under cache->lockCache(), so a query that touched many segments freed all of it while holding the lock, blocking unrelated reserve/eviction work.
c Fix matches root cause? Yes. removeQueryContext extracts the doomed QueryContextPtr from query_map under query_map_mutex, erases the entry, and returns it; ~QueryContextHolder destroys it after the cache write lock scope ends. Destruction moves out from under the lock; the compare-and-erase decision stays under it.
d Test intent preserved? / New tests added? Both existing tests preserved and extended to assert only the last release returns the context (use_count == 1) for out-of-lock destruction and earlier releases return nullptr.
e Demonstrated in both directions? Yes. The extended assertions fail against the prior signature (which returned nothing / destructed under the lock) and pass with the fix; full FileCacheTest.* (27 tests) green.
f Fix is general, not a narrow patch? removeQueryContext is the single last-holder release path; ~QueryContextHolder is its only caller. No sibling paths destroy the query context under the lock.
g Fix generalizes across inputs? The extract-and-destroy-outside-lock path is independent of segment count / query size; it applies to every query context regardless of how many records it accumulated.
h Backward compatible? Yes. Internal FileCache locking change only; no setting, on-disk, wire, or metadata format change.
i Invariants and contracts preserved? Yes. query_map access stays serialized by query_map_mutex; erase still happens under the cache write lock that also guards getOrSetQueryContext (revival); the only change is deferring the context object's destruction to after the lock is released. Lock order unchanged.

Session id: cron:clickhouse-worker-slot-0:20260706-173400

@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.

@clickhouse-gh

clickhouse-gh Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.60% 85.60% +0.00%
Functions 92.70% 92.70% +0.00%
Branches 77.80% 77.80% +0.00%

Changed lines: Changed C/C++ lines covered: 85/87 (97.70%) · Uncovered code

Full report · Diff report

@groeneai

groeneai commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — 5ff6ffc

CI fully finished on head 5ff6ffc4e491 (Finish Workflow: SUCCESS; all 152 checks green, 0 red, 0 pending). Every check passed. The only CIDB-level noise was a first-attempt flake that retried to green:

Check / test Reason Owner / fixing PR
Stateless tests (amd_debug / arm_binary, parallel) / 04001_join_reorder_through_expression flaky (retried to pass; not PR-caused — this PR touches FileCache only) #109499 (external, merged)
Mergeable Check / PR rollup all green
Sync — CH Inc sync (private, not actionable)

No PR-caused failure. Ready for review.

Session id: cron:our-pr-ci-monitor:20260706-230000

@alexey-milovidov
alexey-milovidov requested a review from kssenii July 12, 2026 02:39

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ok. It was failing. Now it doesn't.

@alexey-milovidov alexey-milovidov self-assigned this Jul 12, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jul 12, 2026
Merged via the queue into ClickHouse:master with commit f75ecd4 Jul 12, 2026
175 checks passed
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 13, 2026
@alexey-milovidov alexey-milovidov added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Aug 13, 2026
@robot-clickhouse robot-clickhouse added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Aug 13, 2026
alexey-milovidov added a commit that referenced this pull request Aug 14, 2026
Fix data race on FileCacheQueryLimit::query_map causing LOGICAL_ERROR
robot-clickhouse added a commit that referenced this pull request Aug 14, 2026
Cherry pick #107028 to 25.8: Fix data race on FileCacheQueryLimit::query_map causing LOGICAL_ERROR
robot-clickhouse added a commit that referenced this pull request Aug 14, 2026
alexey-milovidov added a commit that referenced this pull request Aug 14, 2026
The two regression tests added by the backport were written against
`master`, where `9de468d826bc1c4` renamed the settings type passed to
`FileCacheQueryLimit::getOrSetQueryContext`. On 26.5 that method still
takes `const ReadSettings &` and `FilesystemCacheSettings` does not
exist, so clang typo-corrected it to the unrelated `FileCacheSettings`
and the `amd_debug`, `amd_asan_ubsan` and `amd_tsan` builds failed on
`src/Interpreters/tests/gtest_filecache.cpp`. The cherry-pick produced
no textual conflict because both tests are appended at the end of the
file.

Use `ReadSettings` with `filesystem_cache_max_download_size`, which is
the pre-rename spelling of the same value read by
`getOrSetQueryContext` on this branch, so the assertions are unchanged.
`ReadSettings` is only forward-declared in `QueryLimit.h`, so include
`IO/ReadSettings.h` explicitly.

Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=114585&sha=46540245a0d34a4f50e96e6dabb0aa5b58a83b35&name_0=BackportPR
Related: #114585
Related: #107028

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
alexey-milovidov added a commit that referenced this pull request Aug 14, 2026
Backport #107028 to 26.5: Fix data race on FileCacheQueryLimit::query_map causing LOGICAL_ERROR
robot-ch-test-poll4 added a commit that referenced this pull request Aug 14, 2026
Cherry pick #107028 to 26.3: Fix data race on FileCacheQueryLimit::query_map causing LOGICAL_ERROR
robot-clickhouse added a commit that referenced this pull request Aug 14, 2026
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Aug 14, 2026
alexey-milovidov added a commit that referenced this pull request Aug 15, 2026
Backport #107028 to 26.3: Fix data race on FileCacheQueryLimit::query_map causing LOGICAL_ERROR
alexey-milovidov added a commit that referenced this pull request Aug 15, 2026
Backport #107028 to 25.8: Fix data race on FileCacheQueryLimit::query_map causing LOGICAL_ERROR
alexey-milovidov added a commit that referenced this pull request Aug 16, 2026
Backport #107028 to 26.6: Fix data race on FileCacheQueryLimit::query_map causing LOGICAL_ERROR
kssenii added a commit that referenced this pull request Aug 17, 2026
Both sides appended new tests to the end of `src/Interpreters/tests/gtest_filecache.cpp`.
Resolved by keeping both: the two `readBigAt` tests from this backport and the two
`FileCacheQueryLimit` tests that `26.6` gained from the #107028 backport.

Co-Authored-By: Claude Opus 5 <[email protected]>
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Aug 24, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…y-limit-race

Fix data race on FileCacheQueryLimit::query_map causing LOGICAL_ERROR
VighneshPath pushed a commit to VighneshPath/ClickHouse that referenced this pull request Sep 16, 2026
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-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants