Skip to content

Sync changes - #115630

Merged
kssenii merged 9 commits into
masterfrom
sync-private-cache-changes
Aug 27, 2026
Merged

kssenii merged 9 commits into
masterfrom
sync-private-cache-changes

Conversation

@kssenii

@kssenii kssenii commented Aug 20, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

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

...


Workflow [PR]
Sync PR [sync-upstream/pr/115630]

Version info

  • Merged into: 26.9.1.217 (included in 26.9 and later)

Sync cache-related changes from clickhouse-private master into the
shared src/ files:

- CachedOnDiskWriteBufferFromFile: recover write-through caching when a
  covering file segment stayed behind the written offset (mid-segment
  failover): shrink it and start a new file segment instead of throwing
  a logical error. New profile events
  CachedWriteBufferCoveringSegmentShrunk and
  CachedWriteBufferCoveringSegmentShrinkFailed, plus a chart on the
  Filesystem cache dashboard and the
  distributed_cache_write_simulate_mid_segment_failover failpoint.
- CachedOnDiskReadBufferFromFile: count
  CachedReadBufferCacheWriteStopped when switching to
  REMOTE_FS_READ_BYPASS_CACHE.
- CacheUsage: use the wall clock for the idle-client TTL, track
  created_at, expose getLastAccess (empty for clients loaded from
  the filesystem on startup), and count the TTL from creation while the
  last access is unknown. The startup load no longer counts as a client
  access in Metadata::getKeyMetadata. IFileCachePriority::UsageStat
  gains last_access_time.
- Metadata: assert that user_id has no NUL or '/' in the per-user
  cache path.
- ProfileEvents: add the DistrCache* seek events of the distributed
  cache read buffer.
- FailPoint: drop the unused
  distributed_cache_cancel_query_in_response_wait.

Co-Authored-By: Claude Fable 5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [1181618]

Summary: ❌

job_name test_name status info comment
BuzzHouse (amd_debug) FAIL
Logical error: Parsed partition value: A doesn't match partition value for an existing part with the same partition ID: B (STID: 3993-3f59) FAIL cidb, issue ISSUE CREATED

AI Review

Summary

This sync PR moves the distributed-cache read/write switches from profile settings to server settings and refactors filesystem-cache eviction/resize logic, including idle-client cleanup. The PR is not ready to merge: the distributed-cache migration breaks backward-compatibility in two separate ways, and the new idle-client TTL logic now depends on wall-clock jumps.

Missing context / blind spots
  • ⚠️ The PR title/body are just Sync changes, so the intended contract for the distributed-cache setting migration is not stated explicitly. A short description of whether legacy profile/query names are supposed to keep working, fail loudly, or be auto-migrated would close that gap.
Findings

❌ Blockers

  • src/Core/Settings.cpp:9248-9249, src/Interpreters/Context.cpp:6642-6653 The old read_through_distributed_cache / write_through_distributed_cache names are still accepted, but the runtime now resolves only force_read_through_distributed_cache / force_write_through_distributed_cache. That turns existing query/profile overrides into silent no-ops instead of preserving behavior or failing loudly. This is already visible in tree through tests/config/users.d/enable_distributed_cache_for_reads.xml:4-5 and tests/queries/0_stateless/00170_s3_cache.sql:9, and tests/config/users.d/ci_logs_sender.yaml:15,39 still relies on the old write setting too. Suggested fix: keep the legacy names as real aliases to the new force_* settings, or reject them with an exception everywhere they can still be set; do not leave them as accepted-but-ignored settings.
  • src/Core/SettingsChangesHistory.cpp:50-53, src/Core/Settings.cpp:9537-9548, src/Interpreters/Context.cpp:6642-6653 compatibility no longer restores the pre-26.9 default when the server-level distributed-cache switch is enabled. applyCompatibilitySetting skips obsolete settings entirely, so the read_through_distributed_cache / write_through_distributed_cache history entries never apply, and the new force_* settings keep previous_value = auto. A query running with compatibility='26.8' therefore still inherits enable_read_through_distributed_cache=1 / enable_write_through_distributed_cache=1 from the server, which violates the advertised compatibility contract. Suggested fix: encode the compatibility flip on force_* itself (for example previous_value = false) or add explicit restore logic so older compatibility levels get the historical per-query default back.

⚠️ Majors

  • src/Interpreters/FileCache/CacheUsage.h:33-35, src/Interpreters/FileCache/FileCache.cpp:2024-2044 Idle-client eviction now measures inactivity with std::chrono::system_clock, so NTP steps, VM resume, or manual clock changes can instantly purge active clients or keep dead clients alive after a backward jump. The TTL contract here is elapsed inactivity, not wall-clock time. Suggested fix: keep TTL comparisons on a monotonic steady_clock timestamp and, if system-table observability needs wall-clock time, store that separately.
Tests
  • ⚠️ Add a focused regression test showing that setting read_through_distributed_cache / write_through_distributed_cache through a profile or SET still affects behavior, or that the server now throws immediately on those legacy names instead of silently ignoring them.
  • ⚠️ Add a compatibility='26.8' test with enable_read_through_distributed_cache=1 / enable_write_through_distributed_cache=1 in server config and verify that a non-global query still sees the historical default (false) unless it explicitly sets force_*.
Final Verdict

❌ Changes required before merge: the distributed-cache setting migration still breaks backward compatibility, and the filesystem-cache idle-client TTL should not depend on wall-clock jumps.

LLVM Coverage Report

Metric Baseline Current Δ
Lines 87.20% 87.20% +0.00%
Functions 91.90% 91.90% +0.00%
Branches 79.30% 79.30% +0.00%

Changed lines: Changed C/C++ lines covered: 842/1032 (81.59%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Aug 20, 2026
Sync the move of `read_through_distributed_cache` /
`write_through_distributed_cache` from query settings to server settings
(private commits 68119670a70, 060f7c2c4fc). Merges, mutations and
`Buffer` flushes run in contexts built once at startup, so the
profile-level switches stayed pinned to whatever the server started
with; as server settings they are shared by every context and refreshed
from the config reload handler, reported as `changeable_without_restart`.

Per-query control remains via the new `BoolAuto` settings
`force_read_through_distributed_cache` /
`force_write_through_distributed_cache` (`auto` follows the server
setting). The old query-level settings become
`MAKE_DEPRECATED_BY_SERVER_CONFIG` and stay in the profile allowlist of
`ServerSettingsImpl::loadSettingsFromConfig`. The overrides are resolved
in `Context::resolveReadThroughDistributedCache` /
`resolveWriteThroughDistributedCache` instead of resetting the global
context, which raced with concurrent readers of the global settings
(TSan report in private PR 67632).

Also add the `distributed_cache_client_id` query setting (CI tests
only).

Co-Authored-By: Claude Fable 5 <[email protected]>
Comment thread src/Core/ServerSettings.cpp Resolved
Comment thread src/Core/Settings.cpp
MAKE_DEPRECATED_BY_SERVER_CONFIG(M, UInt64, background_distributed_schedule_pool_size, 16) \
MAKE_DEPRECATED_BY_SERVER_CONFIG(M, UInt64, max_remote_read_network_bandwidth_for_server, 0) \
MAKE_DEPRECATED_BY_SERVER_CONFIG(M, UInt64, max_remote_write_network_bandwidth_for_server, 0) \
MAKE_DEPRECATED_BY_SERVER_CONFIG(M, Bool, read_through_distributed_cache, false) \

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.

Making the old names MAKE_DEPRECATED_BY_SERVER_CONFIG turns existing session/profile overrides into silent no-ops, because the actual read/write path now only consults force_read_through_distributed_cache / force_write_through_distributed_cache (Context::resolveReadThroughDistributedCache / resolveWriteThroughDistributedCache). We still have in-tree consumers that rely on the old behavior, for example tests/queries/0_stateless/00170_s3_cache.sql, tests/queries/0_stateless/02770_async_buffer_ignore.sh, and the ci_logs_sender profile in tests/config/users.d/ci_logs_sender.yaml. After this change those settings still parse, but they no longer enable or disable distributed cache. Please either alias the old query/profile settings to the new force_* ones, or migrate every existing consumer in the same PR.

using Clock = std::chrono::steady_clock;
/// The wall clock, so that the last access can be reported as is in system tables.
/// The value does not survive a restart anyway, so monotonicity buys nothing here.
using Clock = std::chrono::system_clock;

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.

Switching the idle-client TTL to system_clock makes eviction depend on wall-clock jumps. An NTP step, VM resume, or manual clock correction can suddenly make every client look idle (or keep dead clients alive after a backward step), and FileCache::evictIdleClients will purge or retain cache state based on clock adjustments instead of real inactivity. If we need wall-clock observability for last_access_time, we should keep TTL comparisons on steady_clock and store a separate wall-clock timestamp for reporting.

@clickhouse-gh

clickhouse-gh Bot commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 11816184d with master 573230bfe (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes
Binary Master PR Δ
programs/clickhouse-stripped 711.33 MiB 708.29 MiB -3.04 MiB (-0.43%)

Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction.

Object file sizes

18 object files changed (+82.44 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Interpreters/FileCache/EvictionCandidates.cpp.o 169.92 KiB 242.93 KiB +73.02 KiB (+42.97%)

737 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

402 translation units recompiled, 3642 s compile time in total, 402 of them have a recent master baseline.

Job report

@clickhouse-gh

clickhouse-gh Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 35 queries analysed

This is a distributed-cache and filesystem-cache refactor: it moves read_through/write_through_distributed_cache from per-query to server-level switches (defaults unchanged, effective values preserved) and adjusts covering-segment shrink handling plus idle-client TTL bookkeeping. None of that touches the join, scan, or aggregation execution paths that TPCH Q7 and Q17 exercise, so the two flagged regressions (Q7 +17.9%, Q17 +59.4%) cannot plausibly be caused by this change — Q17's measurements were also very noisy. Both have been downgraded to not_sure as run-to-run variance rather than real PR effects.

clickbench

🟢 No significant changes

tpch_adapted_1_official

⚠️ 2 inconclusive

Flagged queries (2 of 22)
Query Verdict Baseline median (ms) PR median (ms) Change q-value Hint
⚠️ 7 not_sure 67 79 +17.9% <0.0001 join_operator: This PR only reworks distributed-cache read/write switching and filesystem-cache TTL bookkeeping; Q7's join and scan execution path is untouched, so the +17.9% reads as run-to-run variance.
⚠️ 17 not_sure 64 102 +59.4% <0.0001 Same off-path story as Q7: the changed distributed/filesystem-cache plumbing does not touch Q17's compute path, and its measurements were very noisy, so the +59.4% is not attributable to this PR.

Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on.

Debug info
  • StressHouse run: 088ecc25-c88c-4b9d-baa0-37fbec59dd50
  • MIRAI run: 2516050e-eb43-495e-934c-13ab21ca7923
  • PR check IDs:
    • clickbench_429593_1787318482
    • clickbench_429599_1787318482
    • clickbench_429610_1787318483
    • tpch_adapted_1_official_429622_1787318482
    • tpch_adapted_1_official_429637_1787318482
    • tpch_adapted_1_official_429663_1787318483

kssenii and others added 3 commits August 24, 2026 15:54
The entries for `distributed_cache_client_id`,
`read_through_distributed_cache`, `write_through_distributed_cache`,
`force_read_through_distributed_cache` and
`force_write_through_distributed_cache` were added to the `26.8` block of
`SettingsChangesHistory.cpp`, but `master` is already at `26.9`, so the
`settings_changes_history` style check failed:

    Session setting 'distributed_cache_client_id' must be recorded in the '26.9' block
    ...

Move them into a new `26.9` block.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Comment thread src/Core/SettingsChangesHistory.cpp Outdated
Comment on lines +49 to +50
{"force_read_through_distributed_cache", "auto", "auto", "New setting overriding the server setting `read_through_distributed_cache` for a single query."},
{"force_write_through_distributed_cache", "auto", "auto", "New setting overriding the server setting `write_through_distributed_cache` for a single query."},

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.

compatibility will not restore the pre-26.9 query default here. SettingsImpl::applyCompatibilitySetting skips obsolete settings entirely (src/Core/Settings.cpp:9520), so the read_through_distributed_cache / write_through_distributed_cache history entries above never apply, and the new force_* settings keep previous_value = auto. With read_through_distributed_cache=1 in the server config, a query running with compatibility='26.8' still resolves resolveReadThroughDistributedCache / resolveWriteThroughDistributedCache to true, even though before 26.9 the per-query default was always false. These force_* entries need a pre-26.9 value that recreates the old default (false), otherwise the compatibility contract is broken.

kssenii and others added 4 commits August 25, 2026 12:47
…names

`master` already carries the same work, naming the server-level switches
`enable_read_through_distributed_cache` and
`enable_write_through_distributed_cache` (see f381272). Resolve every
conflict in favour of those names, and follow through on the parts that
merged cleanly but still referenced the old ones:

- `programs/server/Server.cpp`: the `extern` declarations and the
  `new_server_settings[...]` lookups in the config-reload handler now use the
  `enable_*` names.
- `src/Core/SettingsChangesHistory.cpp`: dropped our five entries, the `26.9`
  block on `master` already records all of them, with wording that refers to
  the `enable_*` server settings.
- `src/Core/ServerSettings.cpp`: dropped the `settings_from_profile_allowlist`
  addition. It listed the pre-rename names, which no server setting has any
  more, so it could never fire; and the history entry on `master` states that
  the old setting is ignored as a profile setting.

What remains on top of `master` is the part not covered there: the
`Buffer`/background context reset of the `force_*` overrides, the `BuzzHouse`
setting list, and the filesystem cache usage changes.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`force_read_through_distributed_cache` and
`force_write_through_distributed_cache` were inserted before
`force_distinct_partitions_independently`, breaking the alphabetical order of
`serverSettings`. Move them after it.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Brings over the FileCache reservation/eviction locking work: the split cache
guard, the reduced state-lock cost on the reservation path, the dynamic-resize
locking and its restore path, and the removal of the per-user usage
consistency check from the hot path.

`CacheUsage::update` is now defined inline, so `CacheUsage.h` no longer needs
an out-of-line definition - this is the only change to the set of members
declared but not defined in the header.

`OvercommitFileCachePriority` is untouched: every reference to it stays behind
the existing `ENABLE_DISTRIBUTED_CACHE` / `CLICKHOUSE_CLOUD` guards, and the
count of references drops from 10 to 7 because the new `CacheUsage.h` no
longer names it in comments.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@kssenii kssenii self-assigned this Aug 27, 2026
@kssenii
kssenii added this pull request to the merge queue Aug 27, 2026
Merged via the queue into master with commit 17dd8fe Aug 27, 2026
177 of 179 checks passed
@kssenii
kssenii deleted the sync-private-cache-changes branch August 27, 2026 17:17
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants