Repository navigation
Fix flaky test_trace_log_memory_context: attribute the forced global peak to its own query - #116855
Conversation
…peak to its own query test_memory_context_in_trace_log required `Global`/`Memory` and `Global`/`MemoryPeak` trace events with `empty(query_id)`, that is, emitted by a thread with no query attached. It failed on 8 unrelated PRs in 120 days, 0 on master, on both `amd_binary_excluded_from_llvm` and `arm_binary distributed plan`. `MemoryTracker::commitAllocation` emits a `Global` `MemoryPeak` event only when one and the same allocation both crosses `total_memory_profiler_step` on `total_memory_tracker` and sets a new global peak, and `TraceSender::send` stamps the event with the emitting thread's query id. Both watermarks only ever grow for the life of the server, so the assertion depended on a race that a query-less background thread had to win. ClickHouse#113688 forces the peak with a query: its own events carry that query's id and were therefore excluded, and each escalation raised both watermarks further, so retrying made the next attempt less likely to help rather than more. Count the events of the query that forces the peak instead, in the loop's break condition and in the assertion together so the two cannot diverge. That is stricter than before rather than weaker: a `Global`-context `Memory` and `MemoryPeak` row with `memory_blocked_context = 'Max'` are both still required, and they are now tied to a known query id. `01092_memory_profiler.sql` already scopes `MemoryPeak` to the allocating query. Rebuilding the failing run's own `system.trace_log` from its artifacts shows the old predicate reading 0 and the new one reading 6 over 5 query ids, every one of them an escalation query. 30 runs of the same CI job config pass, converging on the first forcing query in 29 of 30; the bounded retry loop absorbs the rest. Shrinking the forcing query to `numbers(1)` makes the new assertion fail, so it still catches a regression.
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 0 findings), plus a separate cold
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-10:20260828-083300 |
Pre-PR validation gate (click to expand)
Validation runs, real job config ( Session id: cron:clickhouse-impl-slot-4:20260828-071800 |
|
Workflow [PR], commit [df42abc] Summary: ✅ AI ReviewSummaryThis PR rewires Missing context / blind spots
Final Verdict✅ No review findings at current head. |
|
cc @antonio2368, could you review this? The test counted |
f7a09dd
…ueue fills The test's configs/overrides.xml lowers trace_log/max_size_rows to 100000 but leaves buffer_size_rows_flush_threshold at the 524288 it inherits from programs/server/config.xml; SystemLog.cpp derives max_size_rows / 2 only when the key is absent from every config, and it is not absent here. SystemLogQueue::push wakes the flush thread on queue.size() == threshold and caps the queue at max_size_rows, so a threshold above the cap makes the size-based flush unreachable: the queue drains only on the 7500 ms interval timer and on an explicit SYSTEM FLUSH LOGS, and discards everything in between. In the failing job (https://github.com/ClickHouse/ClickHouse/actions/runs/35678160277/job/106631465373) the server logged 0 "Queue is half full", 10 "Queue had been full" every one of them at accepted 100000, and 1081202 ignored rows, 546830 of those in the window holding the query the assertion read. Recovering that run's own system.trace_log from the job artifacts shows the query whose thread the log proves raised the global peak to 2.20 GiB has 0 Global/Max/Memory rows, while six earlier escalation ids kept theirs: the events were produced and then discarded. Setting the companion key to max_size_rows / 2 keeps the ratio that every one of the 18 log blocks in programs/server/config.xml uses. Measured on the failing job's own binary, 30 runs per arm: without the line "Queue is half full" is 0/30 and a single flush reaches exactly the 100000 cap (6466 rows dropped); with it every flush is 50438 rows or below, 0 rows are dropped, and 30/30 pass. That removes the row loss, not the probabilistic MemoryPeak emission which the existing 15-attempt retry loop already covers. Related: ClickHouse#116855 Co-Authored-By: Claude Opus 5 <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Description
Requested in #56335 (comment)
Related: #113688, #87995
Failing run: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=56335&sha=a3c5c38948ecdf544994b54043184abfa82c5e60&name_0=PR&name_1=Integration%20tests%20%28amd_binary_excluded_from_llvm%29
The test required
Global/MemoryPeakevents withempty(query_id), that is, emitted by a threadwith no query attached. 8 PRs in 120 days, 0 on master.
Root cause:
MemoryPeakis emitted only when a singlecommitAllocationontotal_memory_trackerboth crosses
total_memory_profiler_stepand sets a new global peak, andTraceSenderstamps theevent with the emitting thread's query id. Both watermarks only ever rise, so once a query has
raised them a query-less thread must out-allocate that query to emit again. #113688 forces the peak
with a query, so its own events carry that query's id and were excluded, and each escalation raised
the watermarks further, making the next attempt less likely to help.
The change counts the
GlobalMemory/MemoryPeakevents of the query that forces the peak, inthe break condition and the assertion together so they cannot diverge. Nothing is relaxed: both rows
are still required in the
Globalcontext withmemory_blocked_context = 'Max'. What changes iswhich thread emits them, from any query-less thread to the one the test issues for that purpose,
which also pins
query_idwhereempty(query_id)could not.01092_memory_profiler.sqlalready scopesMemoryPeakthis way.Validation: I rebuilt the failing run's own
system.trace_logfrom its artifacts. The old predicatereads 0 there; the new one reads 6 over 5 query ids, every one an escalation query, so the events
existed and only the
query_idfilter hid them. 30 runs of the real job config pass, converging onthe first forcing query in 29 of 30; the retry loop absorbs the rest. Shrinking that query to
numbers(1)makes the new assertion fail, so it still catches regressions. I used the job's ownamd_binaryartifact because theMALLOC_CONFthis test sets hangs a debug binary at startup.Workflow [PR]
Sync PR [sync-upstream/pr/116855]
Version info
26.9.1.266(included in26.9and later)