Repository navigation
Stop a full disk from killing a perf-comparison shard silently - #112145
alexey-milovidov merged 10 commits into
Conversation
A perf-comparison shard could fill the runner root filesystem and then die in a way that uploaded no artifacts at all, so the red check named no query and could not be acted on. From the harness's own df -h on run 30208735413 (arm_release release_base 2/6): 8.8G used / 185G avail / 5% at job start, 194G used / 4.0M avail / 100% at job end, i.e. 185 GB in 79 minutes. Chain: get_profiles runs two `select * from system.trace_log` dumps; both die on Code 159 TIMEOUT_EXCEEDED after streaming TSV for the full 300 s, and because they are `||: &` the failure is swallowed while the partial multi-GB files stay on disk. errno 28 then hits unstable-run-traces.*.rep, and finally the clickhouse-local that recreates ci-checks.tsv, leaving that file present but 0 bytes. performance_tests.py checks only Path(...).is_file(), which is true for a 0-byte file, and then calls a bare next(f), so StopIteration escapes main() before praktika uploads the artifacts. Project the trace_log dump to the four columns its only consumer (the `stacks` table) reads. The dropped columns include the per-frame `symbols` and `lines` arrays, the largest fields in the table and unused because symbols are resolved separately through *-addresses.tsv. This is the rule the same function already applies to query_log, and it finishes what 4f8806c started: that commit excluded *-trace-log.tsv from the archive while it was still written to disk in full. On a 3000-row fixture with the real trace_log schema the dump shrinks 23.5x and report/stacks.$version.tsv is byte-identical; dropping `size` as well makes the query fail with Code 47, so the column list is minimal. Delete unstable-run-traces.$version.rep: no code in the repository reads it, it appears in no report (flamegraphs use report/stacks.$version.tsv), and it is the first file to hit errno 28 above. Read the two ci-checks.tsv header lines defensively and reuse the warning branch that already exists for a missing file, so a future disk failure still fails the shard but with artifacts and the verdict compare.sh had already written into report.html. The first two changes reduce consumption; they do not by themselves guarantee headroom, since every shard of this check currently ends with single-digit-percent free space. The third makes a recurrence visible.
The previous commit guarded only the two header lines of ci-checks.tsv, which covers a 0-byte and a header-only file. Those are two points in the space of byte prefixes an ENOSPC failure can leave behind, and not the common one. compare.sh recreates ci-checks.tsv through a ClickHouse File-engine table, and WriteBufferFromFileDescriptor::nextImpl loops on ::write and throws only after a partial write has been flushed, so the leftover prefix has arbitrary length and usually ends mid-row. csv.DictReader fills a short row's missing fields with restval, which defaults to None, so float(row["test_duration_ms"]) then raises TypeError; a cut inside the duration field raises ValueError; and a truncated header line yields fewer field names than a data row has cells, so subscripting the row raises KeyError. Each of those escapes main() and kills the job before praktika uploads the artifacts, which is the exact failure the guard was added to remove. Sweeping every truncation offset of a realistic 1685-byte file, 150 of 3147 offsets died that way. Extract the parse into read_ci_checks_results and contain the row loop there, following read_test_results in stress_job.py: read each consumed field with .get, skip and count a row that was cut short, and guard the numeric conversion. Rows that did parse are still reported, since degrading beats dying. Passing restval="" instead would only turn the TypeError into a ValueError, so the guard belongs on the consuming code. The helper is also what makes this testable. ci/tests runs in every PR through ci_tests_job.py with include_paths=["./ci"], so ci/tests/test_perf_ci_checks_parse.py covers the absent, empty, header-only, headers-without-rows, well-formed, mid-row-truncated, truncated-header and summary-row shapes, plus a sweep of every truncation offset. Reverting either guard makes it fail. Finally, two skill docs described the trace-log dump positionally, by a symbols column that the previous commit's projection removes and that logs.tar.zst has not shipped since 4f8806c. Point both at report/stacks.$version.tsv, which is symbolized and is what the report's own flamegraphs use.
The parse guard added earlier only rejected a file with fewer than two lines. An ENOSPC prefix usually ends mid-row, and csv.DictReader fills the missing fields with restval, so a row cut inside test_duration_ms after its first digits was accepted with a corrupt value: 25 of the 3147 truncation offsets of a realistic file were reported clean while carrying a wrong duration, and an unterminated types line counted as a header, so a truncated file was reported clean with no warning at all. A byte prefix can also end inside a multi-byte character, which the strict decode rejected with UnicodeDecodeError, escaping main() before praktika uploads the artifacts. compare.sh writes ci-checks.tsv through a File(TSVWithNamesAndTypes) table, which terminates every row, so a non-empty trailing fragment is a line cut mid-write: drop it and report the file as not clean. A row is accepted only when every column is present, not only the three that are read. The decode is lenient, as in stress_job.read_test_results. The new tests also pin the call site in main(): the earlier tests all called the helper directly, so deleting either warning or the results[-2] assignment left the suite green. The perf-report skill's stacks.tsv recipe keyed on math.query2, which is the perf.py query-id spelling and never appears in that file, so the command silently produced an empty file. Key on the test, query_index and trace_type columns the file actually carries, and keep the trace types apart: CPU and Real count samples while MemorySample and JemallocSample sum bytes.
The import block lived inline in main(), so the only thing that could test it
was a set of substring assertions over inspect.getsource(main). Those cannot
see branch semantics: inverting `if not complete:` there leaves all five
assertions passing, while an incomplete file would be imported with no warning
and a complete one skipped.
Extract the block into import_ci_checks_results and drive it directly, so the
warnings and the assignment are asserted as behaviour. The inverted branch now
fails three tests. The warning strings and the assignment target stay pinned
textually as well, so a rewrite cannot quietly drop a log line operators grep
for.
Two parser tests documented a guard they did not reach. Both built their
fixture without a trailing newline, so the cut row was the unterminated final
line and was dropped by the trailing-fragment rule before reaching any row
guard; the malformed count they asserted came from that rule. Terminate both
fixtures so the cut row is a complete line and does reach the guards, and
correct the comments to name the branch actually taken.
That leaves one branch the suite could not reach, the float() conversion guard.
Sweeping the cross product of a truncated names line and a truncated data row
(29670 shapes) finds exactly one shape that reaches it: a names line cut so
that test_duration_ms is the last field, over a row whose duration cell is
empty. Every field the header declares is then present, so the all-columns
guard passes and float("") raises ValueError. Added as a test.
Also pin main()'s is_file() guard, which keeps the importer away from a shard
that died before compare.sh wrote the file at all.
No behaviour change to the parser or to compare.sh.
The parse guards added in this PR cover a prefix that ends mid-row, but not one that ends on a line boundary. Driving the parser over the newline-terminated prefixes of a realistic file, all of them are reported clean: headers only, headers plus the summary row, and headers plus summary plus one of two query rows. The third is the damaging one, a strict subset of the shard's queries assigned into CIDB with nothing in the log saying so. Fix it at the write. compare.sh created the File-engine table straight at the final path, and upload_results is invoked as `time upload_results ||:`, which suppresses errexit for the whole function body, so the failure of that write was swallowed and a torn file was left where the importer would find it. Write to a sibling ci-checks.tsv.tmp and publish with `&& mv`: a same-directory rename allocates no data blocks, so the final path is only ever absent or complete, and the absent case already prints a warning from main(). The rename is chained with `&&` rather than written as the next statement precisely because errexit is suppressed here; as a separate statement it would publish the torn file after a failed write, which is worse than the status quo. clickhouse-local exits non-zero on a failed flush in both dispositions, 75 with CANNOT_WRITE_TO_FILE_DESCRIPTOR when SIGXFSZ is ignored and 153 otherwise, so the guard holds. Same idiom as analyze-confirm's raw.tsv.tmp earlier in the file. The parser also documented a run that cannot happen. upload_results unions an unconditional single-row summary select into every ci-checks.tsv, with no WHERE on either side, so the shortest file a completed run can write is two header lines plus that row: a zero-query run writes three lines, verified against the File engine. A file with no data row is therefore a prefix, not an empty run. Tighten the completeness predicate from two lines to three and correct the docstring and the test that asserted the opposite. The parser's prefix tolerance stays as belt-and-braces for a legacy file or an interrupted rename.
Two behaviours this PR relies on had no assertion of their own. The parser drops an unterminated final line because a complete ci-checks.tsv is newline-terminated, so a final line without its newline was cut mid-write no matter how much of it arrived. Every existing test for that rule cut the row somewhere a row guard would also have rejected it, so the rule itself was unpinned: a prefix ending exactly at a row's last byte carries every declared column, each value parses, and the value it would import is the correct one - nothing but the framing can catch it. Appending the fragment back instead of counting it left the whole suite green. A test for that shape now fails under each of three ways of trusting the fragment. The publish protocol has no Python surface at all. compare.sh writes the file to a sibling .tmp path and renames it with `&&`, which is what keeps the final path either absent or complete when the write dies on a full disk - and for a prefix that ends on a line boundary at or after the summary row, that protocol is the only thing standing between a torn file and an import that looks clean, because two header lines plus the summary row is byte-for-byte what a zero-query run writes. Reverting the rename left all twenty tests green. The new test extracts the real block from compare.sh between anchor comments and runs it under bash with a stubbed clickhouse-local: on success the file is published and no .tmp is left, on a failed write the final path is absent and the partial .tmp remains, and the script still exits 0 as the call site's `||:` dictates. It fails against the form this commit's parent replaced and against a separate-`mv` variant, so it measures the chaining rather than describing it.
Both of these behaviours are introduced or made load-bearing by this PR and neither was covered by a test that could see it break. The publish block opens with `rm -f ci-checks.tsv ci-checks.tsv.tmp`. Deleting that line leaves a previous run's complete-looking ci-checks.tsv at the final path when a write fails, so the importer reports the wrong run's queries with nothing warning - worse than the truncation this change fixes. Dropping only the `.tmp` half lets a previous attempt's torn temporary file be prepended to the new content and then renamed into place: the File engine opens with O_APPEND and `engine_file_truncate_on_insert` defaults to false, so an insert adds to whatever is already there. Both modes are reachable because perf_wd is never wiped at job start and main supports --param re-entry. The test stub now appends rather than truncates, so it models the real writer, and two seeded-directory tests pin both halves of the line; the pre-existing fresh-directory tests cannot see either mutant, which is why the pair is needed. The presence check for ci-checks.tsv moves from main() into import_ci_checks_results, so all three outcomes - absent, truncated, complete - are behaviourally testable instead of split between the caller and the helper. This matters more here than before: the atomic publish deliberately leaves the final path absent on a failed write, so absent is now an expected outcome, and an unguarded open() on that path raises FileNotFoundError out of main() before praktika uploads the artifacts, which is the failure being fixed. The warning string is unchanged and was moved, not duplicated. Verified byte-for-byte behaviour-preserving on all three outcomes against the previous head.
Asserting only the terminal file states of the publish block cannot tell a rename from a copy. Replacing `&& mv ci-checks.tsv.tmp ci-checks.tsv` with `&& cp ci-checks.tsv.tmp ci-checks.tsv && rm -f ci-checks.tsv.tmp` satisfies every path, absence and content assertion in ci/tests/test_perf_upload_results_atomic.py, and it re-opens the failure this change exists to close: with `ulimit -f 0` standing in for a full filesystem, `mv src dst` still publishes the complete file whereas `cp src dst` leaves dst at size 0 with src intact - a torn file at the exact path the importer reads. A same-directory rename allocates no data blocks, which is the whole reason it survives the full disk. Inode identity is what separates the two mechanisms: `mv` preserves the inode the writer produced, `cp` plus `rm` allocates a new one. The stub now records `stat -c %i` of the target it wrote, derived from the SQL as before, and both success-direction tests assert that the published file carries that inode. The copy substitution now fails both of them on that assertion and nothing else, while the two failed-write tests still pass. The import_ci_checks_results docstring said a truncated or empty file is not imported. Only a file with no importable data row is skipped; one that lost individual rows imports the intact ones and reports the count, which is what the shipped test asserts. The prose is narrowed to match the behaviour; no behaviour, warning string or test changed. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=110844&sha=5103f6e068af287dd2d3cf67d86c8297234416dd&name_0=PR
Internal second-model review (click to expand)An independent reviewer read the resulting code cold, without the author's evidence, and a
Two remarks noted and deliberately not acted on: Rejected during design: a free-space pre-check, a shard retry, and reducing the query workload. Session id: cron:clickhouse-review-slot-48:20260727-150900 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-40:20260727-115200 |
|
cc @maxknv — could you review this? A perf-comparison shard that fills the runner disk currently dies before praktika uploads anything, so the red check has no artifacts and no query rows: |
|
Workflow [PR], commit [610a4b9] Summary: ✅
AI ReviewSummaryThis PR hardens the perf-comparison reporting path against disk-full failures by shrinking the Final Verdict✅ No new findings on the current PR head. |
The docstring on import_ci_checks_results justified the `if not complete` branch as data preservation: "assigning an empty row set would silently drop every query the shard ran". That is not what the branch does. Every subtask main() appends before the import site is constructed without a `results=` argument - Result.from_commands_run's own create_from call passes none, and the one plain Result(...) append does not either - so the assignment target's row list is empty regardless of what the parse returned. There is nothing an empty assignment could drop. The branch is worth keeping because it reports the real cause instead of leaving the shard red with no explanation, which is the whole point of the change, but it preserves nothing. Stating it the other way round invites the inverse "fix": treating a partial parse as non-importable in order to avoid overwriting the target, which trades a reported warning for a silent one and, on the offsets where a prefix cuts the first query row, gives up the only signal there is. Measured over the 298 truncation offsets inside that row, master's inline parse imports a query row carrying a wrong duration on 5 of them, raises TypeError on 29 and ValueError on 1; this parser reports every one of them as a skipped malformed row. The new test asserts the property the docstring now claims, over the append sites themselves rather than one simulated run, so it holds for every stage entry point --param can select and fails loudly if a subtask ever starts carrying sub-results of its own. No behaviour change: comments plus one added test.
The recipe's closing line offered `analyze-assembly.py --perf-map` as a consumer of the folded `.collapsed` file. That flag reads JSONL records keyed by instruction address (`load_perf_map` json-decodes every line and requires an `ip` field), so each folded `symbol;...;symbol count` line is rejected as a JSON parse error. Measured on a two-line collapsed file: 0 of 2 rows accepted, both counted under `json_parse_error`. The rejection tally is only printed under `verbose`, so the weighting silently comes out empty rather than failing. The claim predates this PR, but the line it sits on is one this PR rewrites, so it ships either way. `flamegraph.pl` is the compatible consumer and stays.
|
LGTM, cc @egor-click |
|
yes, looks great! |
CI finish ledger - 610a4b9CI has fully finished on this head: 174 check-runs, 0 queued, 0 in progress,
The large skipped count is expected for this head: the change is confined to the perf-comparison Session id: cron:our-pr-ci-monitor:20260728-140000 |
|
Correction to one premise I stated in this PR's review table, plus the disposal of the In row (e) of the a-i table above I justified the two seeded tests with " - name: Prepare env script
run: |
rm -rf ./ci/tmp
mkdir -p ./ci/tmpIt comes from Two arms on a seeded The premise does still hold for the case the tests were actually written around - a local Consequently the follow-up I said I had "filed separately" - a shard importing a previous The sibling follow-up about the positional |
Related: #111377
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Reduces the disk usage of the performance comparison check by dumping only the
system.trace_logcolumns the report reads and by dropping an unused intermediate file, and makes a truncatedci-checks.tsva reported warning instead of an uncaught exception that killed the shard before it uploaded any artifacts.Description
A
Performance Comparison (<arch>_release, <base>, N/6)shard sometimes reports a job-levelERRORwithinfo: '',links: [], and every S3 artifact (job.log,report.html,all-queries.html,logs.tar.zst) returning HTTP 403 because nothing was ever uploaded.CIDB then has no query rows at all, so the red check names no query and cannot be acted on.
The runner root filesystem fills up completely. From the harness's own
df -h(
ci/praktika/runner.py:323at job start,:513at job end) on run 30208735413,sha
6c5c34bf727ee7,arm_release release_base 2/6:185 GB in 79 minutes. The chain, in log order:
get_profileslaunches ten concurrent log dumps, two of which areselect * from system.trace_log.Code: 159 TIMEOUT_EXCEEDED: elapsed 300011 msafter streaming TSV to diskfor the full 300 s. They run as
||: &, so the failure is swallowed and the partialmulti-GB files stay on disk.
Code: 75 ... errno: 28, No space left on devicewritingunstable-run-traces.{left,right}.rep, thensort: write failed.errno 28hits theclickhouse-localthat recreatesci-checks.tsv, leavingthat file present but 0 bytes.
performance_tests.pychecks onlyPath(...).is_file()(true for a 0-byte file) and thendoes a bare
next(f), soStopIterationescapesmain()before praktika uploads theartifacts - which is the reported no-artifact signature.
So there are two separate problems: a dump that writes far more than anything reads, and a
parse that turns a disk failure into an invisible one.
Three changes:
Project the
trace_logdump. The only consumer is thestackstable, which readsexactly
query_id, trace, trace_type, size. The dropped columns include the per-framesymbolsandlinesarrays, by far the largest fields in the table, and unused because theharness resolves symbols separately through
*-addresses.tsv. This applies the rule thesame function already follows for
query_log("The other ~70 columns are dropped to keepthe artifact smaller"), and finishes what 4f8806c started - that commit excluded
*-trace-log.tsvfrom the archive while it was still written to disk in full.On a 3000-row fixture carrying the real
trace_logschema the dump shrinks 23.5x, and theresulting
report/stacks.$version.tsvis byte-identical (same md5) to the one built fromthe full dump, over seven of the nine
trace_typevalues and both arms of the byte-weightedmultiIf(the two not in the fixture,MemoryAllocatedWithoutCheckandInstrumentation,both fall in the
count()arm the other seven already exercise).Removing
sizefrom the projection as well makesstacksfail withCode: 47 UNKNOWN_IDENTIFIER, so the column list is minimal.Delete
unstable-run-traces.$version.rep. Nothing in the repository reads it: afterremoval,
grep -rn "unstable-run-traces\|unstable_run_traces" .returns no hits. It is notreferenced by any report - the flamegraphs use
report/stacks.$version.tsv- and it is thefirst file to hit
errno 28above. If it is wanted as a debugging artifact, restoring it isa one-line revert; I removed it because it costs a large write plus an extra full pass over
the trace data for no reader.
Publish
ci-checks.tsvby rename, and contain its parse.compare.shnow writes thefile to a sibling
ci-checks.tsv.tmpand publishes it with&& mv, so the final path isonly ever absent or complete. The chaining is load-bearing rather than stylistic: this write
is the last thing the job does and its failure is swallowed by the
||:on the call, whichsuppresses
errexitfor the whole function body, so a separate next-linemvwould runafter a failed write and publish the torn file. A same-directory rename allocates no data
blocks, so it still works on the full disk that caused the problem. With the final path
absent, the importer warns and imports nothing - the pre-existing warning, now raised
inside
import_ci_checks_resultsso that all three outcomes (absent, no importable row,importable) are behaviourally testable rather than split between the caller and the helper;
the shard's
verdict comes from
report.html, not from this file.The parse is contained as well, both for a legacy file and for a write interrupted before
the rename. An ENOSPC failure in the
clickhouse-localthat writes this file leaves anarbitrary byte prefix on disk, not only an empty file: a partial header line, or a row cut
mid-field. The parse moves into
read_ci_checks_results, whichreads the file as bytes and decodes leniently, because a prefix can end inside a multi-byte
character; treats an unterminated final line as cut and drops it, because the file is written
through a
File(TSVWithNamesAndTypes)table and every complete row is newline-terminated;accepts a row only when every column is present; reads every field with
.getso a truncatedheader line cannot raise; guards the duration conversion; and reports separately whether the
file was importable at all and how many rows it had to skip. Both warning branches that
already existed are reused. Dropping the unterminated line matters because a number cut after
its first digits still parses: sweeping every truncation offset of a realistic file, prefixes
previously either raised an uncaught exception or were reported clean while carrying a
duration that differed from the truth; now neither happens, the only prefixes reported clean
are the genuine row boundaries at or after the summary row (3 of the 1287 offsets of the
fixture the tests sweep), and a complete file parses
identically. A future disk failure
then still fails the shard, but with artifacts and the real verdict
compare.shhad alreadywritten into
report.html, instead of an opaque no-artifactERROR.ci/tests/test_perf_ci_checks_parse.pycovers those shapes and the offset sweep, andci/tests/test_perf_upload_results_atomic.pyruns the real publish block fromcompare.shunder bash to pin both directions of the rename, and that the publish is a rename rather than
a copy - a copy satisfies every terminal-state assertion while re-opening the torn-file
window on a full disk. Both run on every PR through the existing
CI Testsjob, whose digestincludes
./ci.Two documentation files described the trace dump by column index (
$7,$19) and told thereader to extract
*-trace-log.tsvfromlogs.tar.zst. Both claims were already wrong beforethis PR, since 4f8806c removed that file from the archive, and the projection also
invalidates the indices. They now point at
report/stacks.$version.tsv, which is what thereport's own flamegraphs are built from.
Scope, plainly: the first two changes reduce disk consumption, they do not prove the shard
stays green. All six
release_baseshards currently finish with single-digit-percentheadroom, and two
master_headshards do as well (end-of-job usage on one commit:release_base93/97/92/91/96/92 %,master_headarm 89/68/81/68/59/96 %, amd63/84/59/97/67/85 %), so the remaining capacity question is fleet-side, not a repo change. The third change is what guarantees a recurrence is visible.
Two things this deliberately does not touch: the 300 s trace-dump timeout swallowed by
||: &(pre-existing, and profile data is silently partial today because of it), and theseparate
release_basefailure where the baseline commit'sperf.pyrejects--binary/--http-port(Code: 125thenCode: 107), which fails all sixrelease_baseshardsuniformly and is a harness-design question for the perf owner.
Version info
26.8.1.324(included in26.8and later)