Repository navigation
Make 01548_parallel_parsing_max_memory actually test the memory guard, and stop writing 1 GB - #113080
Conversation
…p writing 1 GB The test has been timing out at the 60 s Fast test per-test cap on Fast test (arm_darwin): 8 failures across 8 unrelated PRs in 30 days, 6 of them on 2026-08-01, 0 on master. Durations cluster within 0.8 s of 60.0 s, so it is the runner's --timeout 60 (ci/jobs/fast_test.py:375), not a resource error. The test wrote a 1 GB fixture per run and write+flush dominates its wall time (6.40 s for 1 GiB against 0.12 s for 128 MiB), so it stretches under macOS-runner disk contention until it crosses the cap. Every arm_darwin fast test with p50 > 3 s inflated in that window while p50 itself never moved, so the trigger is the runner rather than the test. While shrinking the fixture I found the test had not been asserting anything since 2023. Its SELECT count() references no column, which makes StorageFile.cpp set need_only_count, and FormatFactory.cpp:558 disables parallel parsing on that flag before the max_memory_usage guard at :560-562 is consulted. The trace reports "(from 0.00 B)", and running the query twice in one session collapses from 0.399 s to 0.003 s via the count-from-files cache. An instrumented build confirms it directly: the guard is never reached, and removing the guard entirely does not change the result. It was hollowed on 2023-10-16 by ce7eca0, a change unrelated to this test. So instead of only shrinking the fixture, the test now aggregates over column values with sum(length(URL)), which no trivial-count shortcut can serve; pins the four settings the guard reads, all of which CI randomizes today; and asserts at two caps so both branches of the guard are taken and must agree. The 50 MiB cap and max_threads=1 are unchanged because they are the oracle. max_parsing_threads=1 would also make the guard unreachable via the max_parsing_threads > 1 conjunct, so pinning it is load-bearing rather than hygiene. The fixture drops to 128 MiB, which cuts 87.5 % of the bytes written per run, and is now removed at the end. The parallel-parsing decision is not observable from SQL, since ParallelParsingInputFormat emits no log line and no ProfileEvent and EXPLAIN PIPELINE is byte-identical for both branches, and the guard is conservative so whenever it permits parallel parsing the memory is genuinely fine. The oracle can therefore only be validated by mutating the guard away: with it present the low arm reaches and fires it and prints the correct value, and with lines 560-565 bypassed the same query fails MEMORY_LIMIT_EXCEEDED while executing ParallelParsingBlockInputFormat. The old query shape does not redden under that same mutation, including with all four settings pinned. max_memory_usage_for_user, the symmetric branch at :563-565, is deliberately still not covered: clickhouse-local cannot set a user-level setting per query, and widening the oracle to a path with no reported defect would add a redden burden the instrumentation-only limitation cannot discharge.
The two sums the test prints agree whichever input format was built, because the memory guard at FormatFactory.cpp:560-562 changes only the parsing strategy, never the result. So on their own they would stay green if any of the five preconditions ANDed at :556-559 started declining parallel parsing before the guard is consulted, which is exactly how ce7eca0 silently hollowed this test for two years. Add a third arm that pins the constructed format down. ParallelParsingInput- Format allocates max_threads + 2 processing units while the guard budgets min_chunk * max_threads * 2, so with max_parsing_threads=2 the guard under- estimates and there is a window where it permits parallel parsing yet that path cannot fit the cap. The resulting Code: 241 names the format, and the sequential path completes at the same cap, so the line breaks the moment parallel parsing stops being chosen. Feasible caps measured 16-24 MiB; the arm uses 20 MiB, mid-window. No in-test observable of the format exists to assert instead: clickhouse-local has no system log tables at all, EXPLAIN PIPELINE is byte-identical between the arms, normalized trace output is identical, and the ProfileEvents key sets differ only by scheduling counters. Verified by mutation on a local debug build. Forcing one upstream conjunct false flips the arm from PARALLEL to NOT PARALLEL and the test fails, while the pristine tree passes; neutering the memory guard itself still reddens, so no oracle was traded away. Co-Authored-By: Claude Fable 5 <[email protected]>
…lel parsing ran
The third arm proved which input format was constructed by requiring the parallel
path to exceed a 20 MiB memory cap. That peak is not a constant.
ParallelParsingInputFormat.h:106 allocates max_threads + 2 processing units, each
holding a min_chunk-sized segment, giving a structural floor of 16 MiB just 4 MiB
below the cap; everything above that floor comes from a scheduling-dependent
number of units whose segments and parsed chunks coexist
(ParallelParsingInputFormat.cpp:33, .cpp:225-235). So wherever the peak lands in
[16 MiB, 20 MiB) the arm printed NOT PARALLEL and the test went red on master.
Measured on one build, varying only max_block_size:
8000 / 16000 / 32000 -> NOT PARALLEL
65536 / 100000 -> PARALLEL
Smaller parsed chunks lower the peak below the cap. Both earlier validations ran
on a loaded 96-core box, the condition that inflates the peak, so the arm was
validated exactly where its failure mode is masked. This test runs on 21
check_names, so a flaky canary here is worse than the timeout it replaces.
Pinning max_block_size would not fix it: that removes one input to the peak and
leaves the concurrent-unit term, so the margin stays load-dependent.
Instead the arm now asserts an error that only a file segmentation engine raises.
file_segmentation_engine has exactly one runtime call site in the tree,
ParallelParsingInputFormat.cpp:37, so such an error is reachable only if that
format was built. That is a control-flow fact rather than a byte count: no margin
to tune, and no dependence on build flavor, allocator, core count, block size or
load. The error is the INCORRECT_DATA at JSONUtils.cpp:48-52, raised when one JSON
object exceeds 10 * min_chunk_bytes; 01701_parallel_parsing_infinite_segmentation
already greps for the same token, and the sequential path never emits it.
The fixture is a single 32 KB JSONEachRow object against
min_chunk_bytes_for_parallel_parsing=1024, so the threshold is cleared by exact
integer arithmetic on a byte count the test controls. It starts with { because
nonTrivialPrefixAndSuffixCheckerJSONEachRowImpl (JSONUtils.cpp:259-264) returns
true for [. The memory cap is deliberately high, 1024 * 2 * 2 = 4096 against
1000000000, so the guard permits and the arm cannot degenerate back into a memory
oracle; its error was verified to be INCORRECT_DATA and not MEMORY_LIMIT_EXCEEDED.
The new oracle prints PARALLEL at max_block_size 8000, 16000, 32000, 65536 and
100000 and at max_parsing_threads 2, 4 and 16. Hollowing an upstream conjunct
(&& !need_only_count -> && (need_only_count && false)) still flips it to
NOT PARALLEL and fails the test, and neutering the max_memory_usage guard still
fails arm 1 with Code 241 naming ParallelParsingBlockInputFormat, so no oracle was
traded away. Arms 1 and 2 and the reference are unchanged. 50 runs randomized and
50 in the Fast test shape pass, worst case 14.5 s against the 60 s cap.
Internal second-model review (3 rounds, 0 unresolved) - click to expandBefore opening this PR I reviewed the change myself and with an independent second model, three Round 1 (major, fixed)
Fixed by adding a third arm that pins down which format was constructed. Round 2 (major, fixed)
Fixed by replacing the numeric oracle with a control-flow one: Round 3 (this round): no blockers, no majorsThree nits, all recorded and accepted rather than fixed: 💡 The canary reads 💡 The 💡 The fixture uses Re-derived independently from source, all confirmedGuard arithmetic by hand (arms 1-2: |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-41:20260803-070200 |
|
cc @Avogar, could you review this? It is test-only. |
|
Workflow [PR], commit [c6beda1] Summary: ❌
AI ReviewSummaryThis PR rewrites Final VerdictStatus: ✅ Approve |
The observability arm read JSONEachRow, so it proved ParallelParsingInputFormat was constructed for that format, not for the TSV reads the two sum() checks perform. Two of the five preconditions at FormatFactory.cpp:556-558 are per-format registrations, so a TSV-only change could send both guarded queries back to sequential parsing while the arm still printed PARALLEL. The arm now reads the same TSV path with the same settings as the second guarded query. A malformed row raises a parse error, and ExecutionThreadContext.cpp:81 appends the raising node's getName(), which is ParallelParsingBlockInputFormat only when that format was constructed. The token occurs once in src/, where the previous one occurred nine times. Verified: PARALLEL at max_block_size 8000/16000/32000/65536/100000 and at max_parsing_threads 2/4/16; NOT PARALLEL when input_format_parallel_parsing=0, when count() sets need_only_count, and when the memory guard fires. Forcing !need_only_count false makes the test fail; neutering the guard makes it fail. 50/50 both shapes, no failures. The fixture drops from 32777 to 17 bytes.
|
The TSV blind spot is fixed in c6beda1: the observability arm now reads the same TSV path and settings as the second guarded query, and asserts the constructed processor's name ( |
CI finish ledger — c6beda1CI is fully finished on this head (175 check-runs, 0 incomplete,
The fixing PR names this exact test as one of four carriers of the same cause: since #109000 The The other 173 checks are green (the Bugfix validation nodes and the AST fuzzer are skipped: Session id: cron:our-pr-ci-monitor:20260803-220000 |
9804292
Related: #109408
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Description
01548_parallel_parsing_max_memoryhas been timing out at the 60 sFast testper-test cap onFast test (arm_darwin): 8 failures across 8 unrelated PRs in 30 days, 0 on master, durationsclustered within 0.8 s of 60.0 s, so it is the runner's
--timeout 60. Everyarm_darwinfast testwith p50 > 3 s inflated in that window while this test's own p50 never moved, so the trigger is runner
disk contention. Its contribution is IO volume: a 1 GB fixture per run, never removed. That drops to
128 MiB and is now deleted. Paired against master under the Fast test invocation, median falls to 7.7 s
from 10.2 s, worst round to 10.9 s from 33.3 s.
While shrinking the fixture I found the test had not asserted anything since
ce7eca06159(2023-10-16). Its
SELECT count()references no column, which setsneed_only_count, andFormatFactory.cpp:558declines parallel parsing on that flag before themax_memory_usageguard at:560-562. The trace confirms it:(from 0.00 B), no bytes read.The test now aggregates over values (
sum(length(URL))), which no trivial-count shortcut can serve,and asserts at two caps so both branches of the guard are taken and must agree. The 50 MiB cap and
max_threads=1are unchanged: they are the oracle. All four settings the guard reads are pinned, sincemax_parsing_threadsotherwise follows core count. Removing the guard now raisesCode: 241 ... While executing ParallelParsingBlockInputFormaton the low arm, where the old shapestayed green. Since two equal sums cannot say which format was built, a third arm asserts an error only
a file segmentation engine raises, and those run solely inside
ParallelParsingInputFormat: acontrol-flow fact with no numeric margin. It breaks if a precondition ahead of the guard again declines
parallel parsing.
max_memory_usage_for_userat:563-565stays uncovered:clickhouse-localcannotset it per query.
Version info
26.8.1.731(included in26.8and later)