Skip to content

Add more OS sanity checks on server startup - #115725

Open
valerypetrov wants to merge 55 commits into
ClickHouse:masterfrom
valerypetrov:feature/issue-18794
Open

valerypetrov wants to merge 55 commits into
ClickHouse:masterfrom
valerypetrov:feature/issue-18794

Conversation

@valerypetrov

@valerypetrov valerypetrov commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Part of #18794 (the issue tracks a long list; this implements the remaining feasible items rather than closing it).

Changelog category (leave one):

  • Improvement

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

More OS sanity checks at server startup, reported in system.warnings: CPU scaling governor not set to performance, Linux kernel versions with known bugs, low system-wide fs.file-max, insufficient mdraid RAID 4/5/6 stripe cache, high corrected ECC error count, CPU thermal throttling events, disabled CPU turbo boost, NUMA zone reclaim, uncorrected ECC errors, THP defragmentation set to always, data directory on an overlay filesystem, data directory not on the largest mounted filesystem, missing renameat2 support, and enabled swap.

Documentation entry for user-facing changes

All checks are advisory warnings in system.warnings, each read from /proc / /sys inside its own try block so an unreadable file never affects startup. Added on top of the checks that already existed in sanityChecks():

  • CPU scaling governor ≠ performance (from /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor; hosts without cpufreq are skipped).
  • Kernel versions with known bugs: < 3.2 (random IPv6 packet drops), [4.16.0, 4.16.4) (ext4 corruption; warned only when the server's data path, a disk's local path, a filesystem cache or the temporary storage path is on ext4 or on a filesystem that cannot be identified), [5.5.0, 5.6.13) (broken nested epoll_wait — warned even though SettingsQuirks works around it, as requested in the issue). The blanket "< 5.4 THP" range is deliberately omitted: it would fire for every older-LTS user and overlaps the existing THP check.
  • System-wide fs.file-max below 500000.
  • mdraid RAID 4/5/6 stripe_cache_size below 1024, inside the existing mdraid scan.
  • Corrected ECC errors ≥ 100 total across /sys/devices/system/edac/mc/mc*/ce_count (a failing DIMM signal).
  • CPU thermal throttling events since boot (thermal_throttle/core_throttle_count; the counter is absent on some platforms and then skipped).
  • Turbo boost disabled via intel_pstate/no_turbo or cpufreq/boost.
  • Data directory on an overlay filesystem — typically the ephemeral layer of a container; data is lost when the container is removed.
  • Data directory not on the largest mounted filesystem — only durable local filesystem types are considered, devices are deduplicated, and the warning requires a 2x size difference so comparable volumes don't trigger it.
  • renameat2 unavailable — atomic EXCHANGE TABLES will not work.
  • NUMA zone reclaim enabled (vm.zone_reclaim_mode != 0) — causes severe latency spikes on multi-socket machines; the default and recommended value is 0.
  • Uncorrected ECC errors (any in edac/mc*/ue_count) — memory contents were corrupted; strictly more serious than the corrected-errors warning.
  • THP defragmentation set to always — causes allocation stalls even when THP itself is only enabled for madvise; skipped when THP is fully disabled.
  • Swap enabled (any active area in /proc/swaps) — new check not on the original list: swap causes severe latency degradation under memory pressure and disabling it is long-standing ClickHouse production guidance.

Remaining list items and why they are not here: the ELF code-segment checksum was implemented long ago (#18811); ulimits for files/threads, free memory, overcommit, clock source, THP, readahead, low disk space, pid_max/threads-max and mdraid resync/degraded checks already existed; the write-then-read disk self-test proposed in the comments is a refuse-to-start behavior change and does not fit this advisory-warnings PR.

test_reload_config_new_disks adds a local, a local_blob_storage and a cache disk through SYSTEM RELOAD CONFIG and through the background config reloader, and checks that the reload does not deadlock and runs the step that publishes the new disks' ext4 warnings; the warnings themselves depend on the host's /proc//sys state, so no test asserts their content.


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

valerypetrov and others added 3 commits August 20, 2026 21:46
New startup warnings, continuing ClickHouse#18794: CPU scaling governor not set
to performance; Linux kernel versions with known bugs (pre-3.2 IPv6
drops, 4.16.0-4.16.3 ext4 corruption, 5.5.0-5.6.12 broken nested
epoll_wait); system-wide fs.file-max too low; mdraid RAID 4/5/6
arrays with insufficient stripe cache size.

Co-Authored-By: Claude Fable 5 <[email protected]>
Covers corrected ECC errors, CPU thermal throttling, disabled turbo
boost, data directory on an overlay filesystem, data directory not on
the largest mounted filesystem, missing renameat2 support, and a new
check that warns when swap is enabled on the host.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01PcH1uX3QLcLes3XfidQqsC
@rienath rienath added the can be tested Allows running workflows for external contributors label Aug 24, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [ee94028]

Summary: ✅


AI Review

Summary

The PR adds advisory OS checks reported through system.warnings, including filesystem-aware warnings for the Linux 4.16.0–4.16.3 corruption bug. Reviewed head ee9402812f72885daab25298b51b2087015a7443, its diff and surrounding callers, and all prior review threads and replies. Earlier findings are addressed in the current code; no new actionable findings remain.

Missing context / blind spots
  • ⚠️ Unit and integration jobs are still pending in the current CI run. Fast tests passed. The new recorder and mount-parser unit tests and reload integration tests were inspected but were not run locally because this checkout has no configured build. Their CI results will provide runtime verification.
Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Aug 24, 2026
Comment thread programs/server/Server.cpp Resolved
supportsAtomicRename() reads the kernel version only; RENAME_EXCHANGE can still fail
with EINVAL/ENOSYS on filesystems this check never looks at.
Comment thread programs/server/Server.cpp Resolved
Comment thread programs/server/Server.cpp Resolved
One unreadable cpufreq/EDAC/thermal leaf suppressed the whole warning class; each read is
now caught on its own. Overlay is not always a container's writable layer, so the data-loss
sentence is conditional.
Comment thread programs/server/Server.cpp Resolved
One unreadable /sys/block/md*/md/ leaf still aborted the whole block, hiding the
resync, degraded and stripe-cache warnings for every later array.
Comment thread programs/server/Server.cpp Resolved
clang-tidy readability-container-contains rejects find() != npos as a membership test.
@clickhouse-gh

clickhouse-gh Bot commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing ee9402812 with master 903285ff6 (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

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Object file sizes

100 object files changed (+153.16 KiB total), 1 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Server/StartupWarnings.cpp.o 115.68 KiB 186.27 KiB +70.59 KiB (+61.02%)
src/CMakeFiles/dbms.dir/Disks/warnIfExt4CorruptionKernelBug.cpp.o new 62.84 KiB +62.84 KiB

716 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

1409 translation units recompiled, 6848 s compile time in total, 1408 of them have a recent master baseline.

Job report

valerypetrov and others added 3 commits August 24, 2026 18:20
The overlay and largest-filesystem checks probe the server's <path> setting,
which is not where table data lives when storage_configuration puts disks
elsewhere. Name that directory in both warnings instead of calling it "the data
directory", and say that other configured disks are not checked.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01PcH1uX3QLcLes3XfidQqsC
*slow_governors.begin() on an unordered_set picks a hash-order element,
so the warning could name an arbitrary slow governor; a plain
first_slow_governor string is deterministic and simpler for a
single-example value.

Also narrow the new per-array try/catch to just the new stripe-cache
read: the pre-existing sync_action/array_state reads were unguarded
before this PR, and wrapping them too silently changed their behavior
(a throw there no longer aborts the whole mdraid scan).

Co-Authored-By: Claude Opus 5 <[email protected]>
A throw from the sync_action or array_state read escapes to the outer
catch, so one unreadable /sys leaf on md0 suppresses the resync,
degraded and stripe-cache warnings for every later array. Widen the
per-array try/catch to cover the whole loop body, matching the CPU
governor, EDAC and thermal throttle scans.

Co-Authored-By: Claude Opus 5 <[email protected]>
Comment thread programs/server/Server.cpp Resolved
The 4.16.0-4.16.3 kernel check raised a global system.warnings alarm
from the kernel version alone, so a host running 4.16.2 with ClickHouse
on xfs or zfs was told its filesystem might be corrupting data even
though ext4 was not in use. Tell the filesystem type of the <path>
directory from /proc/self/mounts - picking the longest matching mount
point, like the overlay and largest-filesystem scans below do - and keep
the warning only when that filesystem actually is ext4. When the type
cannot be determined, warn as before rather than going quiet.
Comment thread programs/server/Server.cpp Resolved
@valerypetrov

Copy link
Copy Markdown
Contributor Author

Update: the 4.16.0–4.16.3 ext4 warning is now gated on a ClickHouse path actually residing on ext4, determined per-path from /proc/self/mounts. When the filesystem type cannot be determined, it warns as before (bd898f8).

Comment thread programs/server/Server.cpp Resolved
Comment thread programs/server/Server.cpp Resolved
Comment thread programs/server/Server.cpp Resolved
valerypetrov and others added 2 commits August 28, 2026 11:59
… disk objects

getDisksMap() is lazy and getPath() is ambiguous, but the configured
strings are not: every path/metadata_path declared under
storage_configuration.disks that exists as a local directory joins <path>
in the probe. Defaulted metadata paths live under <path> and share its
filesystem, so config-declared paths plus <path> cover the local roots.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01PcH1uX3QLcLes3XfidQqsC
Comment thread src/Interpreters/Context.cpp Resolved
The bit was set when a hit was committed, before `warning_supress_regexp`
was evaluated at publish time, so a suppressed ext4 message kept blocking
the "filesystem could not be determined" warning although no ext4 warning
existed. Tag each recorded message with whether it is an ext4 hit, let
`Context::addOrUpdateWarningMessage` report whether it published, and set
the bit from a hit that survived suppression - clearing it when a flush
suppressed every ext4 hit it carried.

Also publish right after the disk selector swap in
`Context::updateStorageConfiguration`: those disks are active from there
on, so a throw in a later step of the same reload (S3/Azure settings,
storage policies) must not delay their warnings. A throw inside
`updateFromConfig` itself still discards the staged batch.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01ScfL2iRpXjAYmAMoDLCmqY
valerypetrov and others added 4 commits September 24, 2026 19:36
Master now makes `DiskObjectStorage::isRemote` depend on the backend, so a
disk over local blob storage with local metadata reports false. The
encrypted-disk probe then took the local-disk branch and never checked the
blob key prefix, where the encrypted data actually lands. Branch on
`DataSourceType::Local` instead, so every object storage delegate reaches
the metadata-root and key-prefix probes again.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The old pattern matched both the swap-time and the end-of-reload log
lines, so the test still passed if the end-of-reload publish went away.
Match the end-of-reload line by its own prefix.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The "ext4 hit beats undetermined" rule was kept in a `published_ext4`
flag that could drift from what `system.warnings` actually holds. A flush
whose ext4 hits were all suppressed cleared it while an earlier ext4
warning was still stored, and `TRUNCATE system.warnings` never cleared
it. A flush also emptied the queue before the flag reflected its ext4
hit, so a concurrent undetermined probe could queue a message that the
next flush used to overwrite the real warning.

Flushes now run one at a time and read the stored warning first: an
undetermined message is skipped while the stored warning, or one
published earlier in the same flush, is an ext4 hit. The record-time
flag and its bookkeeping are gone.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@valerypetrov

Copy link
Copy Markdown
Contributor Author

@groeneai , can you please check the CI logs & prepare fix if necessary?

@groeneai

groeneai commented Oct 5, 2026

Copy link
Copy Markdown
Collaborator

I checked the CI on c933f2e. The only red is Performance Comparison (arm_release, master_head, 4/6); Mergeable Check and PR only roll it up. It is not caused by this PR, and nothing needs fixing here.

  • The failing row is set_index #0 (a IN (SELECT rand(1) FROM numbers(200000)) with read_overflow_mode = 'break'), 24.7 ms -> 41.3 ms, scored confirmed_regression by the performance dashboard. The in-tree comparison marked the same query only unstable, not slower.
  • The diff does not reach that query. What it adds at runtime is startup warnings, a disk/cache root probe that returns right after a static kernel-version check unless the kernel is 4.16.0-4.16.3, and flushes in Context::getWarnings (read only by system.warnings) and in the storage config reload.
  • The noise itself is fixed by Stabilize four noisy performance test queries #122458 (merged 2026-09-26): the rand set made every run look up a different set and read a different number of rows before the break. On arm master, set_index #0 was flagged in 79 of 559 commits in the two weeks before it and in 0 of 406 since; on PRs, 340 of 1779 before and 1 of 1434 since. This run is from 2026-09-25, and its job log still shows the rand(1) query.

Merging master into the branch picks up the fix. A plain re-run does not, since it reuses the original merge commit. CH Inc sync is pending on the private sync, which I cannot act on.

valerypetrov and others added 4 commits October 5, 2026 14:12
Master moved FileCache.cpp from base/hex.h to Common/Hex.h; keep that and
the branch's warnIfExt4CorruptionKernelBug.h include.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Comment thread src/Common/filesystemHelpers.cpp Resolved
Comment thread src/Interpreters/Context.cpp Resolved
…the ext4 probe of a reused filesystem cache

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Comment thread src/Interpreters/Context.cpp Resolved
@maxknv maxknv added the external Author is not a member of the ClickHouse organization label Nov 2, 2026
valerypetrov and others added 2 commits November 6, 2026 09:44
…ueues

The default cache policy is SLRU, and master now rejects a cache whose
max_file_segment_size (32 MiB by default) is larger than an SLRU queue.
With max_size 1Mi the cache disk failed to load, so both reload tests
failed. Use a 100 KiB segment and a 4 KiB boundary alignment.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Context::getOrCreateDisk ran the disk creator without a probe batch, so a
disk that recorded the ext4 warning and then failed (for example on an
unknown key) left that warning to be published for a disk that never
existed. Stage the probe and commit it only after the disk is registered.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
valerypetrov and others added 5 commits November 6, 2026 22:13
The reload integration test only sees probes on a 4.16.0-4.16.3 kernel, so
on CI it never recorded anything and could not catch a broken batch, commit,
suppression or precedence. The recording part of the probe now takes the
filesystem type as input, and a unit test drives it: a committed batch is
published, an uncommitted one is dropped, and a later undetermined or
suppressed probe keeps an earlier ext4 warning.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Bring the branch up to date with master.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
….cpp

Master added the same include a few lines below, so after the last merge the file included it twice and clang-tidy (readability-duplicate-include) failed the arm_tidy build.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
clang-tidy's modernize-use-nodiscard is an error on master now, and it
flags the const getter `stored` of the test fixture.

Co-Authored-By: Claude Fable 5.2 <[email protected]>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-logging Logging/monitoring/observability (logs, metrics, tracing, instrumentation). external Author is not a member of the ClickHouse organization pr-improvement Pull request with some product improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants