Skip to content

Fix redundant file segment contention introduced in 26.1+ - #109577

Merged
kssenii merged 2 commits into
masterfrom
fix-fs-cache-26.2-issue
Jul 7, 2026
Merged

Fix redundant file segment contention introduced in 26.1+#109577
kssenii merged 2 commits into
masterfrom
fix-fs-cache-26.2-issue

Conversation

@kssenii

@kssenii kssenii commented Jul 6, 2026

Copy link
Copy Markdown
Member

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 redundant file segment contention introduced in 26.1+.

Version info

  • Merged into: 26.7.1.597 (included in 26.7 and later)
  • Backported to: 26.6.2.48, 26.5.6.26, 26.4.5.113, 26.3.17.32

A CACHED-type reader is never the downloader of its file segment, but
nextImplStep checked FileSegment::isDownloader unconditionally - both in
the SCOPE_EXIT cleanup and at the end of the step. Each check takes the
per-segment mutex. On cache-hit-heavy workloads with many concurrent
readers of the same hot segments (e.g. compact parts, where all columns
share the segments), these acquisitions collapse into a lock convoy:
FileSegmentLockMicroseconds grew 21.7x per query after the read buffer
was rewritten into a stateless read-state machine (which dropped the
download_current_segment guard that 25.12 had).

Gate both checks on state->read_type != ReadType::CACHED. The SCOPE_EXIT
stays conservative when an exception is in flight, because
prepareReadFromFileSegmentState could have thrown after becoming a
downloader but before the new state was assigned. A download demoted to
REMOTE_FS_READ_BYPASS_CACHE still passes the read_type gate.

Analysis: https://pastila.clickhouse.com/?004d62dc/180549db80ba6c9a5781c3b74a02fc2f.html#dK09hbPCCbRg+qMl49WWeg==GCM

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@kssenii kssenii added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Jul 6, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [ed0e0c7]

Summary:

job_name test_name status info comment
Stress test (amd_tsan) FAIL
ThreadSanitizer: data race (STID: 1464-2f74) FAIL cidb, issue ISSUE EXISTS
Stress test (arm_msan) FAIL
Logical error: Unexpected return type from A. Expected B. Got C (STID: 3262-40aa) FAIL cidb, issue ISSUE CREATED
Finish Workflow FAIL
python3 ./ci/jobs/scripts/workflow_hooks/new_tests_check.py FAIL IGNORED

AI Review

Summary

This PR removes redundant FileSegment::isDownloader() checks from the cache-hit read path in CachedOnDiskReadBufferFromFile, while keeping downloader ownership validation in debug builds and preserving the fail-closed checks in the mutating FileSegment operations. After reviewing the current diff, the full modified file, the relevant FileSegment ownership code, and the prior review thread, I did not find any remaining issues that warrant new review comments.

Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Jul 6, 2026
Comment thread src/Disks/IO/CachedOnDiskReadBufferFromFile.cpp
The check took the file segment lock before every buffer refill, keeping
one contended acquisition per read on the cache-hit path. In release
builds FileSegment::write and FileSegment::reserve still throw if the
caller is not the downloader, and the reverse direction (a CACHED-type
reader being the downloader) is enforced by the chassert in
prepareReadFromFileSegmentState.

Addresses #109577 (comment)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@kssenii
kssenii requested a review from antonio2368 July 7, 2026 09:00
@clickhouse-gh

clickhouse-gh Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.70% 85.70% +0.00%
Functions 92.70% 92.70% +0.00%
Branches 77.90% 77.90% +0.00%

Changed lines: Changed C/C++ lines covered: 16/16 (100.00%) · Uncovered code

Full report · Diff report

@kssenii
kssenii added this pull request to the merge queue Jul 7, 2026
Merged via the queue into master with commit 5ea379b Jul 7, 2026
171 of 175 checks passed
@kssenii
kssenii deleted the fix-fs-cache-26.2-issue branch July 7, 2026 13:15
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 7, 2026
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Jul 7, 2026
@tavplubix tavplubix added v25.12-must-backport v26.2-must-backport and removed pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR labels Jul 7, 2026
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Jul 7, 2026
kssenii pushed a commit that referenced this pull request Jul 8, 2026
kssenii added a commit that referenced this pull request Jul 8, 2026
Backport #109577 to 26.5: Fix redundant file segment contention introduced in 26.1+
kssenii added a commit that referenced this pull request Jul 8, 2026
Backport #109577 to 26.4: Fix redundant file segment contention introduced in 26.1+
kssenii added a commit that referenced this pull request Jul 8, 2026
Backport #109577 to 26.3: Fix redundant file segment contention introduced in 26.1+
kssenii added a commit that referenced this pull request Jul 8, 2026
Backport #109577 to 26.6: Fix redundant file segment contention introduced in 26.1+
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Jul 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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 v25.12-must-backport v26.2-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants