Skip to content

Fix race condition in file cache dynamic resize - #96980

Merged
alexey-milovidov merged 3 commits into
masterfrom
fix-cache-resize-race-condition
Feb 16, 2026
Merged

alexey-milovidov merged 3 commits into
masterfrom
fix-cache-resize-race-condition

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Feb 15, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Fixed a race condition in FileCache::doDynamicResizeImpl where the write lock was released between removeQueueEntries and modifySizeLimits, allowing concurrent tryIncreasePriority to promote entries into the protected queue
  • This caused a LOGICAL_ERROR exception: "Cannot modify size limits... not enough space freed" in the stress test (amd_debug)
  • Fix: hold the write lock across both operations, following the documented locking order in Guards.h

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=96930&sha=434475dfdaa26392f727dca644bb6cfb29aa4bb7&name_0=PR&name_1=Stress%20test%20%28amd_debug%29
#96930

Changelog category (leave one):

  • CI Fix or Improvement

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

  • Fix race condition in file cache dynamic resize that could cause a LOGICAL_ERROR exception during config reload.

🤖 Generated with Claude Code

Version info

  • Merged into: 26.2.1.776

The stress test (amd_debug) was failing with:

  Logical error: 'Cannot modify size limits to 62914560 in size and
  3000000 in elements: not enough space freed. Current size:
  64962887/188743680, elements: 138/3000000 (s3_cache, protected)'.

Root cause: in `FileCache::doDynamicResizeImpl`, `removeQueueEntries`
created a temporary write lock that was released immediately after the
call. Between that release and the subsequent `modifySizeLimits` call,
concurrent `tryIncreasePriority` could promote entries from the
probationary queue to the protected queue, increasing the protected
queue size above the new limit.

Fix: hold the write lock from `removeQueueEntries` through
`modifySizeLimits`, preventing concurrent queue modifications
(promotions, additions) between removal and limit application.
This follows the locking order documented in Guards.h
(`CachePriorityGuard` before `CacheStateGuard`).

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=96930&sha=434475dfdaa26392f727dca644bb6cfb29aa4bb7&name_0=PR&name_1=Stress%20test%20%28amd_debug%29

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Feb 15, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [725c453]

Summary: ✅

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Feb 15, 2026
@alexey-milovidov alexey-milovidov added pr-ci and removed pr-bugfix Pull request with bugfix, not backported by default labels Feb 15, 2026
@alexey-milovidov
alexey-milovidov merged commit 9c8a66b into master Feb 16, 2026
137 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-cache-resize-race-condition branch February 16, 2026 06:19
@alexey-milovidov alexey-milovidov self-assigned this Feb 16, 2026
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Feb 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-ci 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.

2 participants