Skip to content

Revert "Revert "Make getServerSetting return live values for runtime-changeable settings"" - #107388

Merged
alexey-milovidov merged 3 commits into
masterfrom
revert-106930-revert-105172-fix-getServerSetting-live-values
Jun 13, 2026
Merged

alexey-milovidov merged 3 commits into
masterfrom
revert-106930-revert-105172-fix-getServerSetting-live-values

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Jun 13, 2026 •

Copy link
Copy Markdown
Member

Re-applies #105172 ("Make getServerSetting return live values for runtime-changeable settings"), which was reverted by #106930 because of a data race.

getServerSetting read the live value of runtime-changeable server settings by copy-constructing the whole ServerSettings struct from the reference returned by Context::getServerSettings, without any synchronization. Meanwhile the config reloader mutates a few fields of the shared server_settings at runtime (e.g. setS3QueueDisableStreaming, setMessageQueueDisableInsertion) while holding shared->mutex. The unsynchronized full-struct copy in the reader raced with those writers, which ThreadSanitizer reported as a data race in __tsan_memcpy. This was the root cause of the revert.

This PR fixes the root cause:

  • Add Context::getServerSettingsCopy, which takes a consistent snapshot of shared->server_settings under shared->mutex (the same lock the writers already take).
  • getServerSetting now operates on a locked snapshot instead of copying the live reference.
  • collectChangeableServerSettings reads the runtime-mutable s3queue_disable_streaming field through the locked copy instead of the bare reference.
  • Make the 04241_get_server_setting_live_values test robust: the max_server_memory_usage value is auto-adjusted at runtime, so it is now asserted to be non-zero instead of compared for exact equality (which raced with the runtime adjustment).

Closes: #106902
Related: #105172
Related: #106930

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 getServerSetting to return the live effective value for runtime-changeable server settings (such as max_server_memory_usage, mark_cache_size, max_concurrent_queries, thread pool sizes, etc.), matching what system.server_settings reports.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Version info

  • Merged into: 26.6.1.770

@clickhouse-gh

clickhouse-gh Bot commented Jun 13, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [02ce0c5]

Summary: ✅


AI Review

Summary

This PR re-applies the live-value behavior for getServerSetting while fixing the previously reported data race by snapshotting ServerSettings under Context's shared mutex and reusing the system.server_settings live-value path. I found no remaining correctness, safety, or test-coverage issues requiring inline comments.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Jun 13, 2026
Comment thread src/Functions/getServerSetting.cpp Resolved
alexey-milovidov and others added 2 commits June 13, 2026 16:17
`getServerSetting` (re-introduced here) read the live value of runtime-changeable
server settings by copy-constructing the whole `ServerSettings` struct from the
reference returned by `Context::getServerSettings`, without any synchronization.
Meanwhile the config reloader mutates a few fields of the shared `server_settings`
at runtime (e.g. `setS3QueueDisableStreaming`, `setMessageQueueDisableInsertion`),
holding `shared->mutex`. The unsynchronized full-struct copy in the reader raced
with those writers, which `ThreadSanitizer` reported as a data race in
`__tsan_memcpy`. This is why the original change was reverted.

Add `Context::getServerSettingsCopy`, which takes a consistent snapshot of
`shared->server_settings` under `shared->mutex` (matching the lock the writers
already take), and route the racy reads through it:
- `getServerSetting` now operates on a locked snapshot instead of copying the
  live reference.
- `collectChangeableServerSettings` reads `s3queue_disable_streaming` (a
  runtime-mutable field) through the locked copy instead of the bare reference.

Closes: #106902

Co-Authored-By: Claude Opus 4.8 <[email protected]>
…mit drift

The flaky check failed on the `max_server_memory_usage` assertion: the test
compared `getServerSetting('max_server_memory_usage')` against the value in
`system.server_settings` for exact equality, but both read
`total_memory_tracker.getHardLimit()`, which is auto-adjusted at runtime (based
on cgroup/RAM observations). The two reads happen at different moments, so the
limit can change between them and the equality flakes.

Assert instead that `getServerSetting('max_server_memory_usage')` is non-zero,
which is what the fix actually changed (it used to return the raw config value
`0`). The remaining settings compared for exact equality
(`max_concurrent_queries`, `mark_cache_size`, `mark_cache_policy`, `keeper_hosts`)
are config-driven and stable during the test.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=107388&sha=faddff6cd96c6274c16cc8c0ad75ab6a91a2c90e&name_0=PR

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@clickhouse-gh clickhouse-gh Bot added pr-bugfix Pull request with bugfix, not backported by default and removed pr-not-for-changelog This PR should not be mentioned in the changelog labels Jun 13, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.70% 84.70% +0.00%
Functions 92.30% 92.40% +0.10%
Branches 77.30% 77.30% +0.00%

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

Full report · Diff report

@alexey-milovidov alexey-milovidov self-assigned this Jun 13, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jun 13, 2026
Merged via the queue into master with commit bf20513 Jun 13, 2026
166 checks passed
@alexey-milovidov
alexey-milovidov deleted the revert-106930-revert-105172-fix-getServerSetting-live-values branch June 13, 2026 22:18
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-bugfix Pull request with bugfix, not backported by default 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.

Data race on ServerSettings during reload

2 participants