Repository navigation
Conversation
…mFile `readFromFileSegment` emitted a TEST-level log message on entry and on exit, unconditionally, so a cached read produced two of them per buffer refill. A third fired inside the tail-batch resize branch whenever the segment batch held a single segment, and a fourth once per refill on the `readBigAt` path. `LOG_IMPL` evaluates its format arguments, builds the message and constructs a `Poco::Message` before handing anything to the channel, so the cost is message construction on the reading thread and no log limiter or sink-side throttle can remove it. Each of these messages additionally evaluated `getInfoForLog`, which takes the `FileSegment` mutex and formats eleven fields. On a `Stress test (amd_asan_ubsan)` run that hung-checked on a 978.06 s query, 663.14 s of that query (67.8% of elapsed) was inside `LOG_IMPL`: 272,839 `LogTest` messages against 136,381 cached reads, 2.000565 per read. The two unconditional lines account for 272,762 of them, 99.972%, leaving 77 messages from every other site in the file. The other two lines are removed because otherwise the storm stays reachable on a different randomization draw rather than because they cost measured time in that artifact: the resize message is per refill whenever `filesystem_cache_segments_batch_size` is small (that run happened to draw 100, and at 1 the pre-fix ratio measures 3.026 rather than 2.172), and the `readBigAt` message is the same defect on the parallel read path. This removes per-refill TEST logging from the cache-hit read path only. The download path still emits per-refill messages from `prepareReadFromFileSegmentState` and the `FileSegment` downloader lifecycle; those are deliberately left alone. Measured on the post-fix binary, a cold run logs 29,293 messages over 4,854 misses while the warm run logs 115 over 5,005 hits. The hung query was a warm read (136,380 hits against 1 miss), so the cache-hit path is the one that mattered. The per-open, per-seek and per-segment-transition logs are kept, as are all the diagnostics on exception paths, which still report the full read state. Follows 111546, which removed the equivalent per-block logging from `CompressedReadBufferFromFile` (486 s to about 0 on the same class).
Internal second-model review (click to expand)An independent cold review of the resulting code, plus a separate second-model review pass, both
What the cold review confirmed rather than challenged. I enumerated the log sites independently Test liveness was traced rather than assumed. The oracle is a two-column row and the Every countable in the PR body was re-derived from the recorded measurements and reproduces The one disclosed gap is real and is stated in the body: the Session id: cron:clickhouse-review-slot-11:20260807-193001 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-5:20260807-175212 |
|
cc @kssenii @antonio2368, could you review this? It deletes four |
|
Workflow [PR], commit [fc1dade] Summary: ❌
AI ReviewSummaryThis PR adds Final Verdict✅ No new review findings. LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 43/44 (97.73%) · Uncovered code |
Build profile diff (arm_release)No arm_release build profile data for commit fc1dade - the build was skipped, reused from cache, or predates profile upload. |
CI finish ledger - e57c3e9CI is fully finished on this head: 175 check runs, 0 queued or in progress,
Correction to this ledger, 2026-08-08: the Session id: cron:our-pr-ci-monitor:20260808-230000 |
…rm-cached-read-buffer
CI finish ledger - 2e36676Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task CI is fully finished on this commit with no failed checks - every dispatched job Session id: cron:our-pr-ci-monitor:20260809-170000 |
| skip_cache_on_disk_failure, | ||
| log); | ||
|
|
||
| LOG_TEST( |
There was a problem hiding this comment.
What is the problem having such logging on Test log level?
There was a problem hiding this comment.
On the Stress test (amd_asan_ubsan) run that hung-checked in #113742,
It the problem only with certain sanitizer builds? If so -- let's leave the logging as is with only debug build for example
There was a problem hiding this comment.
What is the problem having such logging on Test log level?
You are right that the level check comes first: logger_useful.h:80-81 breaks out before any work is done, so an ordinary build running at trace pays nothing for these lines. The problem is confined to the runs that do enable test, and stress runs do: tests/docker_scripts/stress_runner.sh:271 rewrites <level>trace</level> into <level>test</level>. Past that gate the whole body runs per buffer refill, not per segment: getInfoForLog builds a string, a Poco::Message is constructed, and the channel is called. readFromFileSegment emitted 2 to 3 of these per refill, so the volume tracks the number of cached reads.
It the problem only with certain sanitizer builds? If so -- let's leave the logging as is with only debug build for example
No, and this is the part where I would push back on the debug-only gate specifically: the worst carrier measured so far is a plain debug build, so that gate would keep the logging exactly where it costs the most. amd_debug has no sanitizer (-DSANITIZE= empty, ci/jobs/build_clickhouse.py:19). Both rows below are from the failing runs' own ProfileEvents:
| carrier | build | LogTest |
LoggerElapsedNanoseconds |
|---|---|---|---|
| #112788 (triaged yesterday) | amd_debug, no sanitizer |
1847525 | 6686 s |
| #113742 (this PR's origin) | amd_asan_ubsan |
272839 | 663 s |
The non-sanitizer run spends 10x more time in the logger than the sanitizer one.
That run also settles why I removed the calls instead of rate limiting them: async logging was already dropping messages there (AsyncLoggingFileLogDroppedMessages: 645616) and it still burned 6686 s, because the cost is message construction on the reading thread, before any limiter or sink is reached. This is the same conclusion as #111546, which removed the per-block log in CompressedReadBufferFromFile at the source.
Segment-level tracing is kept: 15 of the 20 LOG_TEST in this file remain, including buffer open, seek, new-segment, cache write and one per readBigAt call. Only the per-refill lines are gone.
If you would rather keep the lines under some condition, I am happy to do that instead of removing them.
There was a problem hiding this comment.
Those logs help to debug some stress test failures, let's at least add a setting filesystem_cache_verbose_logging and put them under it.
There was a problem hiding this comment.
@groeneai, add a setting explained above, disable by default
There was a problem hiding this comment.
Done, filesystem_cache_verbose_logging, default false. All four per-refill lines are back and guarded by it. The guard is a statement if rather than something inside the log arguments, since the arguments are what cost the time.
Measured on the new test, same 5052 cached reads: 58 TEST messages with the setting off, 15214 with it on (3.01 per read, which is what the pre-change binary did). Note this is a session setting, so a stress run can enable it globally through a users.d profile.
|
The stress tests hanged on this, my apologies |
@kssenii asked to keep the per-buffer-refill TEST-level messages of CachedOnDiskReadBufferFromFile available for debugging stress test failures rather than remove them, gated behind a new setting, disabled by default. The four messages are restored and each call site is guarded by `filesystem_cache_verbose_logging`. The check is a statement guard rather than something inside LOG_TEST, because the message arguments (getInfoForLog, which takes the FileSegment mutex and formats 11 fields) are evaluated before the macro sees them; that evaluation, once per buffer refill, is the cost measured on the failing stress runs (663 s of a 978 s query on amd_asan_ubsan, 6686 s on amd_debug). Measured on the regression test with the setting off vs on, over the same 5052 cached reads: 58 vs 15214 TEST messages, so the ratio goes from 0.01 to 3.01 per read. The 3.01 figure matches the pre-change binary, i.e. the setting restores the previous behaviour exactly. Co-Authored-By: Claude Fable 5 <[email protected]>
Review follow-up on the test. Three problems, all in the arm that turns the setting on: The setting value was written as `0 + 1`, which is not a literal, so the query failed to parse and that arm never ran at all. The arm scanned the whole table, which is unnecessary once the messages are known to be emitted: it only needs enough reads to measure their rate. It now reads one granule (about 410 cached reads, 1300 messages instead of 5000 and 15000), and `index_granularity` is pinned so the count does not depend on the runner's randomization. The assertion was `messages > reads`, which the surviving segment-level messages can satisfy on their own, so it would still pass if two of the three per-refill sites stopped firing. It now requires the rate to exceed 2.5 messages per read, and each arm asserts its own read count. Verified by mutation: gating only one of the three sites fails the rate assertion, and making the guards unconditional fails the default-off assertion. Also pin `enable_parallel_replicas = 0` - the runner randomizes it, and with it on the read happens on the replica cluster, so this server's ProfileEvents are not the ones being measured (2 of 5 repeat runs failed on this). Co-Authored-By: Claude Fable 5 <[email protected]>
Two of the listed settings, max_read_buffer_size_local_fs and filesystem_cache_prefer_bigger_buffer_size, are not randomized by clickhouse-test; they are pinned because their defaults widen the read buffer and so reduce the refill count the test measures. Co-Authored-By: Claude Fable 5 <[email protected]>
| { | ||
| LOG_TEST(log, "Reading file segment: {}", getInfoForLog(&state, info, offset)); | ||
| /// The check must stay outside LOG_TEST: once TEST logging is enabled the arguments are | ||
| /// evaluated and the message formatted, and this function runs once per buffer refill. |
There was a problem hiding this comment.
Remove this comment, the code is clear
There was a problem hiding this comment.
Removed in 16c9ca9. The rationale is in the commit message instead.
| bool enable_log = false; | ||
| /// Emit a TEST-level message per buffer refill. Off by default: the message is formatted once | ||
| /// per read rather than once per file segment, so it costs the reading thread proportionally. | ||
| bool verbose_logging = false; |
There was a problem hiding this comment.
Removed as well, same commit.
Requested by @kssenii on the PR. The removed text explained why the setting check is a statement guard rather than something inside the LOG_TEST arguments: once TEST logging is enabled, LOG_IMPL evaluates the arguments and formats the message, and readFromFileSegment runs once per buffer refill, so a guard placed inside the arguments would not remove the cost. Measured on the carrier that motivated this PR: 272839 messages, 663.14 s of a 978.06 s query spent inside LOG_IMPL. That rationale belongs here rather than at the call sites. No code change: the preprocessed form of both files is byte-identical before and after.
The history row said `false, false`, so `SET compatibility = '26.7'` left the
setting off and could not reproduce the pre-26.8 logging. Before this PR the four
per-buffer-refill LOG_TEST statements in CachedOnDiskReadBufferFromFile were
unconditional once the log level admitted them, so the value the setting
effectively had is `true`. That is also what SettingsChangesHistory.cpp asks for
in its own header comment ("For newly added setting choose the most appropriate
previous_value") and what the two other new gate settings in the 26.8 block do
(ai_function_allow_insecure_endpoint, input_format_read_datetime_number_as_raw_value).
04825 now also asserts that the setting is off by default and comes back under
compatibility = '26.7'. Reverting the row to `false, false` fails only that new
line (1 0), leaving the log-storm assertions green, so the arm is not vacuous.
Enabling it via compatibility restores logging only where TEST-level logging is
also on; no CI job combines an old compatibility value with test-level logging
(the stress runner rewrites the level but sets no compatibility, the upgrade
runner sets compatibility but not the level).
| {"filesystem_cache_wait_for_concurrent_download_timeout_milliseconds", 60000, 1000, "New setting to bound how long a read waits for a file segment being downloaded to the filesystem cache by a concurrent query; on timeout the read bypasses the cache instead of waiting indefinitely. The previous value 60000 corresponds to the old behavior (one full 60 s wait cycle on the downloader)."}, | ||
| {"text_index_posting_list_apply_mode", "materialize", "lazy", "Text index queries now decode posting lists on demand with a cursor instead of materializing them into Roaring Bitmaps, which reduces memory usage and CPU time for selective queries."}, | ||
| {"filesystem_cache_verbose_logging", false, false, "New setting gating the per-buffer-refill TEST-level log messages of the filesystem cache read buffer, which were previously emitted unconditionally once the log level allowed them."}, | ||
| {"filesystem_cache_verbose_logging", true, false, "New setting gating the per-buffer-refill TEST-level log messages of the filesystem cache read buffer. Before 26.8 they were emitted unconditionally once the log level admitted them, so the previous value is `true` and `SET compatibility = '26.7'` restores that logging."}, |
There was a problem hiding this comment.
Revert this change, we do not care about compatibility here
There was a problem hiding this comment.
Reverted in 4f6e59c. The 26.8 row is back to false, false and 04825 no longer asserts anything about compatibility. The row itself stays because 03999_stateless_settings_history requires every new setting to appear here.
Reverts 121d0ee. The 26.8 row goes back to `false, false` and 04825 drops the compatibility assertion, as requested in review: compatibility is not meant to govern this setting. The row itself stays, because 03999_stateless_settings_history requires every new setting to appear in SettingsChangesHistory.cpp.
Both measured arms set the setting explicitly, so neither of them covers the compiled default. Flipping that default to true kept all four assertions green while restoring the log storm for queries that do not touch the setting; the new line fails in that case and in no other. The setting is not randomized by tests/clickhouse-test, so reading system.settings is stable.
CI finish ledger - fc1dadeEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task Not caused by this PR: the diff gates existing cache log lines behind a new setting, and the
Earlier failures on the previous head ( Session id: cron:our-pr-ci-monitor:20260811-013000 |
c8ef760
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Description
readFromFileSegmentemitted a TEST-level message on entry and on exit, so a cached read logged twoper buffer refill; a third fired in the tail-batch resize branch when the batch held one segment, and
a fourth once per refill in
readBigAt.LOG_IMPLevaluates its arguments and formats the messagebefore reaching the channel, so once TEST logging is on the cost is message construction on the
reading thread and no log limiter helps. Each also called
getInfoForLog, which takes theFileSegmentmutex and formats 11 fields.On the
Stress test (amd_asan_ubsan)run that hung-checked in #113742, 663.14 s of a 978.06 squery (67.8% of elapsed) was inside
LOG_IMPL: 272,839LogTestmessages against 136,381 cachedreads. The
amd_debugrun triaged in #112788 is worse in absolute terms (1,847,525 messages,6686 s), and it has no sanitizer.
The four call sites are now behind a new setting
filesystem_cache_verbose_logging, defaultfalse, as @ kssenii asked, so the messages stay available for debugging stress test failures. The
check is a statement guard rather than part of the log arguments, which is what actually avoids the
formatting. Per-open, per-seek, per-segment and exception logs are untouched, as is the download
path.
Validation.
04825_cached_read_buffer_no_per_read_log_stormmeasures both directions over onesystem.query_logrow per arm: with the setting off, 5052 cached reads produce 58 TEST messages(0.011 per read); with it on, the rate is 3.01 per read, matching the pre-change binary. 30/30
randomized runs pass. Mutation-checked: unconditional guards fail the default-off assertion, and
gating only one of the three per-refill sites fails the rate assertion.
Version info
26.8.1.1158(included in26.8and later)