mirror of
https://github.com/hanzoai/datastore.git
synced 2026-09-26 13:55:07 +00:00
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]>
51 lines
2.2 KiB
Python
51 lines
2.2 KiB
Python
import pytest
|
|
|
|
from helpers.cluster import ClickHouseCluster
|
|
|
|
# Regression test for https://github.com/ClickHouse/ClickHouse/issues/101759
|
|
#
|
|
# In `AsynchronousMetrics::update`, after `values.swap(new_values)` the warning helpers
|
|
# (`processWarningForMutationStats`, `processWarningForMemoryOverload`,
|
|
# `processWarningForCPUOverload`) were still passed `new_values`, which after the swap holds
|
|
# the *previous* cycle's metrics. As a result the overload warnings in `system.warnings`
|
|
# lagged one asynchronous-metrics cycle behind, and on the very first cycle `new_values` is
|
|
# empty, so no warning was emitted at all even when a threshold was exceeded. The fix passes
|
|
# the freshly computed `values` instead.
|
|
#
|
|
# The config below makes the memory-overload warning fire unconditionally on the first cycle
|
|
# (warn ratio 0, zero minimum duration) and disables the periodic refresh (very large update
|
|
# period), so exactly one asynchronous-metrics update -- the synchronous one done at server
|
|
# startup -- has run by the time the test queries `system.warnings`.
|
|
#
|
|
# With the bug, that first cycle reads the empty post-swap `new_values` and emits nothing;
|
|
# with the fix, the warning is present immediately after start.
|
|
|
|
cluster = ClickHouseCluster(__file__)
|
|
node = cluster.add_instance(
|
|
"node",
|
|
main_configs=["configs/overload_warnings.xml"],
|
|
stay_alive=True,
|
|
)
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
def start_cluster():
|
|
try:
|
|
cluster.start()
|
|
yield cluster
|
|
finally:
|
|
cluster.shutdown()
|
|
|
|
|
|
def test_memory_overload_warning_present_on_first_cycle(start_cluster):
|
|
# Only the synchronous startup update has run so far (the periodic refresh is effectively
|
|
# disabled), so this directly exercises the first-cycle behaviour.
|
|
warnings = node.query(
|
|
"SELECT message FROM system.warnings WHERE message LIKE 'High ClickHouse memory usage:%'"
|
|
)
|
|
assert "High ClickHouse memory usage" in warnings, (
|
|
"The memory-overload warning was not emitted on the first asynchronous-metrics cycle. "
|
|
"This is the regression fixed in this change: the warning helpers must read the freshly "
|
|
"computed `values`, not the stale post-swap `new_values`."
|
|
)
|