Skip to content

Fix LocalObjectStorage with cache - #106239

Merged
alexey-milovidov merged 3 commits into
masterfrom
fix-filecache-bypass-local-objstorage-overread
Jun 3, 2026
Merged

alexey-milovidov merged 3 commits into
masterfrom
fix-filecache-bypass-local-objstorage-overread

Conversation

@kssenii

@kssenii kssenii commented Jun 1, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

Not for changelog because LocalObjectStorage is used only for test, not a real feature.

Version info

  • Merged into: 26.6.1.347 (included in 26.6 and later)
  • Backported to: 26.3.33.42

@clickhouse-gh

clickhouse-gh Bot commented Jun 1, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [bef66a6]

Summary: ✅


AI Review

Summary

This PR fixes cached disk bypass reads by applying the same BoundedReadBuffer wrapping to non-right-bounded remote readers that the write-through cache path already uses, and adds an integration regression test for the PARTIALLY_DOWNLOADED_NO_CONTINUATION bypass path. I found no correctness blockers in the changed read-buffer flow.

Findings

💡 Nits

  • [tests/integration/test_filesystem_cache/test.py:255] The new comment describes a LOGICAL_ERROR path with server-abort wording. In release builds this is an exception, so rephrase the comment around a LOGICAL_ERROR exception/connection error.
Final Verdict

Status: ✅ Approve

The only finding is a non-blocking wording nit.

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Jun 1, 2026
finally:
node.query("SYSTEM DISABLE FAILPOINT cache_filesystem_failure")

# If the over-read aborted the server, the queries above raise a

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This describes a LOGICAL_ERROR path as aborting the server. In release builds this is an exception, so please phrase the comment in terms of a LOGICAL_ERROR exception/connection error instead of server-abort wording.

@clickhouse-gh

clickhouse-gh Bot commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.40% 84.40% +0.00%
Functions 92.40% 92.40% +0.00%
Branches 77.00% 77.00% +0.00%

Changed lines: Changed C/C++ lines covered by tests: 15/16 (93.75%) | Lost baseline coverage (was covered on master, now uncovered in this PR): 1 line(s) · Uncovered code

Full report · Diff report

@alexey-milovidov alexey-milovidov self-assigned this Jun 3, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jun 3, 2026
Merged via the queue into master with commit 77634f7 Jun 3, 2026
326 of 328 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-filecache-bypass-local-objstorage-overread branch June 3, 2026 08:18
@clickgapai

Copy link
Copy Markdown
Contributor

Hi @kssenii @alexey-milovidov — a couple of suggestions to make this PR easier for reviewers and the changelog reader.

Description (currently missing):

  • Why: The PR body is empty (no description of the bug, root cause, or fix). The added test's docstring contains a good explanation that belongs in the PR body.

  • Suggested addition:

    On the REMOTE_FS_READ_BYPASS_CACHE path, a non-last file segment read relies on the buffer being right-bounded. For readers without right-bounded support (local object storage), the bypass buffer was assigned the raw implementation reader without wrapping it in BoundedReadBuffer, so it could read past the held segment and trip a LOGICAL_ERROR. This PR wraps the bypass buffer in BoundedReadBuffer (via a shared create_remote_read_buffer helper) when the underlying reader does not support right-bounded reads, matching the REMOTE_FS_READ_AND_PUT_IN_CACHE path.

Ignore this if the current title/body is intentional.

@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 3, 2026
@groeneai

groeneai commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator

Release branch 26.3 is aborting its server in Integration tests (amd_tsan, 6/6) because this fix never reached it. I would like to ask for v26.3-must-backport here.

From the 26.3 branch run of 2026-09-05 16:50:07Z (01c76922, version 26.3.32.7):

<Fatal> : Logical error: 'Expected 401725 <= 131614 (size: 303421, read range: [98304, 131071],
          hold file segments: 2 ([98304, 131071](DOWNLOADED), [131072, 163839](DOWNLOADED)))'

https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=26.3&sha=01c7692242d8eaf71b46282653a5d9253cf0891c&name_0=ReleaseBranchCI&name_1=Integration%20tests%20%28amd_tsan%2C%206%2F6%29

The mechanism is what this PR changed. The test's cache sits on a local_blob_storage disk, whose object read buffer reports supportsRightBoundedReads() == false (SeekableReadBuffer.h:59) and inherits the empty-bodied ReadBuffer::setReadUntilPosition (ReadBuffer.h:234). On 26.3 the REMOTE_FS_READ_BYPASS_CACHE arm of getRemoteReadBuffer takes implementation_buffer_creator() raw, without the BoundedReadBuffer wrap that the REMOTE_FS_READ_AND_PUT_IN_CACHE arm applies ten lines above, so the per-segment bound set in prepareReadFromFileSegmentState is silently dropped and the read runs to the end of the object. The server log 5 ms before the abort names the arm: read_type: REMOTE_FS_READ_BYPASS_CACHE. The corrective resize is gated on holding a single file segment, and every failure holds two or three, so the assertion at the end of readFromFileSegment fires.

Selecting CIDB on the assertion text over 90 days gives 10 events, with offset + size equal to 401725, the object size, in all 10 while the requested bound varies over 65795, 131614, 197433, 263252 and 329069. All 10 are on the 26.3 or 26.5 line and none on master, 26.6, 26.7 or 26.8. That matches the commit: over 30 days with pull_request_number = 0, master has 0 failures against 8542 ok, 26.8 0/620, 26.7 0/840 and 26.6 0/938, all four containing 77634f7, while 26.3 has 2 failure rows against 656 ok and 26.5 has 2 against 472, both diverged. 26.5 is retired, so 26.3 is the only branch that needs anything. Besides that branch run, this killed Integration tests (amd_tsan, 6/6) on six separate 26.3 backport PRs since 2026-09-01 (#118543, #118338, #118062, #118033, #118030, #117502).

Not overstating it. Every one of those events ran with the default remote_filesystem_read_method = 'threadpool' (the stack contains AsynchronousBoundedReadBuffer::readSync), and on that path an official build compiles the assertion out and then trims the over-read in AsynchronousBoundedReadBuffer::nextImpl, which shrinks the working buffer by the excess and rewinds to read_until_position. I read that from the source rather than running it, so for that configuration I claim no incorrect results on 26.3, only the abort in sanitizer and debug builds plus wasted reads on the bypass path. With remote_filesystem_read_method = 'read' that trimming layer is not in the stack at all, since AsynchronousBoundedReadBuffer is only constructed when the method is threadpool (DiskObjectStorage.cpp:789, :864); I have not verified what an official build does there, so I make no claim about it either way.

No cherry-pick was ever opened or declined here: cherrypick/26.3/106239 and backport/26.3/106239 are both 404, and this thread has no human comments. v26.3-must-backport expands to 26.3 plus the newer active branches, and pre_check skips 26.6, 26.7 and 26.8 since they already contain the merge commit, so it would land on 26.3 alone.

One thing worth deciding up front, since the cherry-pick replays the merge commit and that is two files. I simulated the three-way merge onto 26.3 (git merge-file --diff3, base 3fca01d3): both files merge with zero conflict hunks, and the source half lands complete, including the explicit lambda return type from the third commit that it needs in order to compile. test_bypass_cache_does_not_overread_non_last_segment merges too but cannot pass on 26.3, because it uses the cache-disk setting skip_cache_on_disk_failure and the failpoint cache_filesystem_failure, and 26.3 has neither; its FailPoint.cpp does carry nine other cache* failpoints, so that is a real absence rather than a bad grep. The fix half is self-contained; the test half needs adapting or dropping there.

@alexey-milovidov could you apply the label? I am not hand-authoring a release-branch PR.

@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Sep 10, 2026
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Sep 10, 2026
@PedroTadim

Copy link
Copy Markdown
Member

Backporting to fix the flaky test on 26.3 and 26.4 CIs

PedroTadim added a commit that referenced this pull request Sep 10, 2026
Backport #106239 to 26.3: Fix LocalObjectStorage with cache
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-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-not-for-changelog This PR should not be mentioned in the changelog pr-synced-to-cloud The PR is synced to the cloud repo v26.3-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants