Repository navigation
Fix filesystem cache race in incrementSize after eviction - #99662
Algunenano wants to merge 2 commits into
Conversation
Between `collectEvictionInfo` and `incrementSize`, the state lock is dropped for eviction I/O. During that gap other threads may complete reserve cycles that change the sub-queue state, so `incrementSize` can legitimately find that a sub-queue no longer has room. This manifests as a LOGICAL_ERROR exception "Cannot increment size". Add `tryIncrementSize` (returns false instead of throwing) to the `Iterator` interface and use it in `doTryReserve` to treat the condition as a transient reservation failure. Also fix argument order in `LRUFileCachePriority::getStateInfoForLog` which swapped `max_elements` with `hold size` / `hold elements` in the diagnostic message. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
|
Workflow [PR], commit [13ad746] Summary: ✅ AI ReviewSummaryThis PR addresses a real race in file cache reservation accounting: when the state lock is released for eviction I/O, concurrent reservations can consume freed space before Missing context
ClickHouse Rules
Final Verdict
|
The same post-eviction race window affects the query priority path. Roll back the main iterator increment on failure. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
| /// Between `collectEvictionInfo` (which computed how much to evict under the | ||
| /// state lock) and here, the state lock was dropped for eviction I/O. During | ||
| /// that gap other threads may have acquired hold spaces or completed reserve | ||
| /// cycles that consumed the freed space in a sub-queue, so `incrementSize` |
There was a problem hiding this comment.
the state lock was dropped for eviction I/O. During
/// that gap other threads may have acquired hold spaces or completed reserve
/// cycles that consumed the freed space in a sub-queue,
This is not true, see IFileCachePriority::HoldSpace (and how it is used) which is created for this purpose to avoid the described issue. Likely the failure itself is related to private-only feature (a different cache policy which is enabled in private by default). Let me investigate myself, I haven't seen this failure.
There was a problem hiding this comment.
Yes, the issue affects only the private feature, but I needed to change the API here
LLVM Coverage Report
PR changed lines: PR changed-lines coverage: 55.38% (36/65, 1 noise lines excluded) |
|
This fix is much better than the one I merged a minute ago... let's un-draft? |
|
@kssenii, what to do with this change? |
|
The root cause should be fixed by #101991 |
Between
collectEvictionInfoandincrementSize, the state lock is dropped for eviction I/O. During that gap other threads may complete reserve cycles that change the sub-queue state, soincrementSizecan legitimately find that a sub-queue no longer has room. This manifests as aLOGICAL_ERRORexception "Cannot increment size".Example failure: https://d1k2gkhrlfqv31.cloudfront.net/clickhouse-test-reports-private/json.html?PR=52290&sha=c7313ec1fda3fdda8147d312f770824667ffe879&name_0=PR&name_1=Stateless%20tests%20%28amd_release%2C%20meta%20storage%20in%20keeper%2C%20s3%20storage%2C%20sequential%29
Add
tryIncrementSize(returns false instead of throwing) to theIteratorinterface and use it indoTryReserveto treat the condition as a transient reservation failure. Also fix argument order inLRUFileCachePriority::getStateInfoForLogwhich swappedmax_elementswithhold size/hold elements.cc @kssenii
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix a race condition in the filesystem cache that could cause a
LOGICAL_ERROR"Cannot increment size" when multiple threads compete for cache space.Documentation entry for user-facing changes