Repository navigation
Conversation
…ronousMetrics The `iowait` field of `/proc/stat` is not monotonic (proc(5): "This value is not reliable ... may decrease"). `AsynchronousMetrics` computed every delta of a kernel counter with a plain unsigned subtraction, so a counter that stepped back wrapped to about 2^64: `system.asynchronous_metrics` reported `OSIOWaitTime` of about 2.4e16 and `OSContextSwitches` of 1.8e19 for that sample (measured on 26.10.5.57 and 26.3.63.123), and since ClickHouse#120906 enabled `-fsanitize=unsigned-integer-overflow` the same subtraction aborts `*_asan_ubsan` servers and keepers: AsynchronousMetrics.cpp:854:25: runtime error: unsigned integer overflow: 9363 - 9364 cannot be represented in type 'uint64_t' Use the existing `safeDiff` (ThreadProfileEvents.h) in all four kernel counter `operator-`: `/proc/stat` CPU and other lines, `/sys/block/*/stat` (32-bit tick fields wrap, a re-created device restarts its counters) and `/proc/net/dev` (a re-created interface restarts its counters). A counter that went backwards contributes 0 for that interval; the true delta is unknown, and 0 never produces an impossible value. `in_flight_ios` is a gauge and stays as is. The other deltas in the file (`/proc/pressure/*` totals, in-process profile events) are monotonic. The test bind-mounts a fake `/proc/stat` while the server starts (the file is opened once and sampled synchronously in `start()`), detaches the mount, lowers `iowait` and `ctxt`, and runs `SYSTEM RELOAD ASYNCHRONOUS METRICS` (the module's update period is 60000 s). `OSProcessesBlocked` (a gauge read from the fake file) proves the server reads it; `OSProcessesCreated` and `OSUserTime` prove an advancing counter keeps its delta. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 1 finding; bounded: 1 full pass + 1 fix round + 1 delta recheck).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20261124-110201 |
|
cc @pamarcos, could you review this? The four kernel-counter operator- in AsynchronousMetrics.cpp (/proc/stat CPU and other lines, block devices, network interfaces) now use the existing safeDiff, so a counter that steps backwards (iowait in /proc/stat) gives a 0 delta instead of wrapping to about 2^64; since #120906 that wrap aborts asan_ubsan servers and keepers in integration jobs. |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-7:20261124-094400 |
|
Workflow [PR], commit [78c21ab] Summary: ✅
AI ReviewSummaryReviewed #134097 at Missing context / blind spots
Final VerdictStatus: ✅ Approve |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 9 s compile time in total, 7 of them have a recent master baseline. |
Algunenano
left a comment
There was a problem hiding this comment.
Not sure if we need a test like this, but it's all good. Let's merge and go on
Related: #120906
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed asynchronous metrics such as
OSIOWaitTimereporting a value around 1e16 for one sample when the kernel counter they are computed from decreased between two updates (theiowaitfield of/proc/statcan go backwards). Such a delta is now 0. This covers every/proc/stat, block device and network interface counter.Description
On 26.10 and 26.3, when the
iowaitcounter in/proc/statsteps backwards between two samples (proc(5): it may decrease),system.asynchronous_metricsreportsOSIOWaitTimeof about 2.4e16 for that sample (measured on 26.10.5.57 and 26.3.63.123 with a faked/proc/stat). Since #120906 enabled the UBSan check for unsigned overflow, the same subtraction aborts sanitizer builds:It kills servers and keepers at random in
*_asan_ubsanintegration jobs, e.g. master Integration tests (amd_asan_ubsan, db disk, 3/8) (test_convert_ordinary_to_atomic: all 3 keepers died).The four
operator-that compute kernel counter deltas (/proc/statCPU and other lines, also used for cgroupcpu.stat;/sys/block/*/stat;/proc/net/dev) now use the existingsafeDiff(ThreadProfileEvents.h), so a counter that went backwards contributes 0. The other deltas in the file (/proc/pressure/*totals, in-process profile events) are monotonic and unchanged.Test:
test_system_reload_async_metricsgets a case that bind-mounts a fake/proc/statwhile the server starts, lowersiowaitandctxt, and runsSYSTEM RELOAD ASYNCHRONOUS METRICS. It fails on master (debug:OSIOWaitTime2.6e16; asan_ubsan: the abort above) and passes with the fix (10/10 debug, 5/5 asan_ubsan). The block device and network operators get the same change but are not exercised by the test.Workflow [PR]
Sync PR [sync-upstream/pr/134097]