Skip to content

Fix overload warnings reading stale async-metrics values (one-cycle lag) - #108035

Merged
alexey-milovidov merged 7 commits into
masterfrom
fix-asyncmetrics-stale-warnings
Jul 1, 2026
Merged

alexey-milovidov merged 7 commits into
masterfrom
fix-asyncmetrics-stale-warnings

Conversation

@alexey-milovidov

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

Copy link
Copy Markdown
Member

In AsynchronousMetrics::update, after values.swap(new_values) the warning helpers were still passed new_values, which after the swap holds the previous cycle's data. So processWarningForMutationStats, processWarningForMemoryOverload and processWarningForCPUOverload read stale metrics: system.warnings lagged one async-metrics cycle, and on the very first cycle new_values is empty, so no warning was emitted even when a threshold was exceeded. This passes values (the freshly computed metrics) instead.

Testing: added a deterministic regression test (tests/integration/test_async_metrics_overload_warning). It sets a very large asynchronous_metrics_update_period_s so that only the synchronous update performed once at server startup has run by the time the test queries system.warnings, and forces the memory-overload warning to fire unconditionally on that first cycle (memory_overload_warn_ratio 0, memory_overload_duration_seconds 0). Without the fix, the first cycle reads the empty post-swap new_values and emits no warning (the test fails); with the fix it reads the freshly computed values and the warning High ClickHouse memory usage: ... is present immediately after start (the test passes). Verified locally on both the fixed and the unfixed binary: with the unfixed binary the warning is absent after startup and only appears after one further SYSTEM RELOAD ASYNCHRONOUS METRICS, confirming the one-cycle lag.

This revives the change from the closed PR #102779 (closed for process reasons) and rebases it onto current master.

Closes: #101759
Related: #102779

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):

Fixed memory/CPU/mutation overload warnings in system.warnings lagging one asynchronous-metrics cycle behind (and being absent on the first cycle).

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Version info

  • Merged into: 26.7.1.328 (included in 26.7 and later)

In AsynchronousMetrics::update, after values.swap(new_values) the warning helpers
were still passed new_values, which then holds the previous cycle's data. This
lagged system.warnings by one cycle and emitted nothing on the first cycle.
Pass the freshly computed `values` instead.

Closes: #101759
Related: #102779

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Jun 20, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [31fcf9c]

Summary: ✅


AI Review

Summary

This PR fixes system.warnings overload and mutation warnings reading the previous asynchronous metrics snapshot after values.swap(new_values). The production change now passes the fresh values snapshot to all three warning helpers, and the added integration test deterministically covers the first-cycle memory-overload warning by forcing the threshold and disabling later periodic refreshes. I did not find any blocker or major correctness issue in the current diff.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Jun 20, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member Author

Status: ready to merge pending maintainer override.

  • CH Inc sync: ✅ green now (it was the prior round's sole substantive red; cleared on its own).
  • AI Review: ✅ no blockers or major findings; 0 unresolved review threads.
  • All builds + functional / integration / unit / stateless test lanes green; LLVM coverage unchanged (85.40%).

Remaining non-green checks are not caused by this change:

  • Stress test (amd_tsan) / Stress test (arm_tsan) → Hung check failed, possible deadlock found = chronic Hung check failed, possible deadlock found #107941 (OPEN). The hung-query stacks are generic Poco::Net TCP-handler threads with zero AsynchronousMetrics / processWarningForMutationStats / processWarningForMemoryOverload / processWarningForCPUOverload frames. This PR only changes a periodic background-thread metrics swap, which cannot deadlock a connection handler.
  • Finish Workflow / new_tests_check.py → No new tests have been added. As documented in the PR body, the one-cycle warning lag is non-deterministic black-box behavior (async-metrics cycle timing plus actually exceeding memory/CPU/mutation thresholds) and is not reproducible in the test harness; the change is verified by inspection. Reserved for maintainer override.

The fix is unchanged (+9/-5 in src/Common/AsynchronousMetrics.cpp): after values.swap(new_values), the warning helpers now read the fresh values rather than the post-swap stale new_values. Master has not touched the file since the merge-base (68024785a70, 2026-06-29 23:39 UTC, ~14h), so no re-merge is needed.

alexey-milovidov and others added 2 commits June 30, 2026 19:17
Adds a deterministic regression test for the one-cycle lag fixed in this
change. With `asynchronous_metrics_update_period_s` set very large, only the
synchronous update performed at server startup runs before the test queries
`system.warnings`. The config also forces the memory-overload warning to fire
unconditionally on that first cycle (`memory_overload_warn_ratio` 0,
`memory_overload_duration_seconds` 0).

With the bug, the first cycle reads the empty post-swap `new_values` and emits
no warning; with the fix it reads the freshly computed `values` and the warning
`High ClickHouse memory usage: ...` is present immediately after start.

Verified locally: on the fixed binary the warning is present after startup
(count 1); on the unfixed binary it is absent after startup (count 0) and only
appears after one further `SYSTEM RELOAD ASYNCHRONOUS METRICS`, confirming the
one-cycle lag.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

Added a deterministic regression test and refreshed the branch on current master (clean merge — master has not touched AsynchronousMetrics.cpp).

New test: tests/integration/test_async_metrics_overload_warning. It sets a very large asynchronous_metrics_update_period_s so that only the synchronous async-metrics update performed once at server startup has run when the test queries system.warnings, and forces the memory-overload warning to fire unconditionally on that first cycle (memory_overload_warn_ratio 0, memory_overload_duration_seconds 0).

Verified locally on both binaries:

  • Unfixed (master) binary: no High ClickHouse memory usage warning after startup; it appears only after a further SYSTEM RELOAD ASYNCHRONOUS METRICS — directly reproducing the one-cycle lag.
  • Fixed binary: the warning is present immediately after startup (values holds the freshly computed metrics, which system.asynchronous_metrics confirms are populated after the first cycle).

So the test fails on master and passes with the fix — the behaviour the bugfix-validation gate expects — and it gives the change the automated test that new_tests_check.py was flagging as missing. This corrects the earlier assessment that the bug was not deterministically reproducible in the harness.

Build sanity: -fsyntax-only on the merged AsynchronousMetrics.cpp is clean.

@clickhouse-gh

clickhouse-gh Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.40% 85.40% +0.00%
Functions 92.60% 92.60% +0.00%
Branches 77.70% 77.70% +0.00%

Changed lines: Changed C/C++ lines covered: 5/5 (100.00%) · Uncovered code

Full report · Diff report

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good.

@alexey-milovidov alexey-milovidov self-assigned this Jul 1, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jul 1, 2026
Merged via the queue into master with commit e9db786 Jul 1, 2026
174 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-asyncmetrics-stale-warnings branch July 1, 2026 06:10
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 1, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…-stale-warnings

Fix overload warnings reading stale async-metrics values (one-cycle lag)
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.

processWarning methods use stale metrics after values.swap(new_values)

2 participants