Repository navigation
Fix LLVM profile file contention in coverage builds by adding %p to patterns - #97020
alexey-milovidov wants to merge 5 commits into
Conversation
In coverage builds, LLVM instrumentation outputs warnings and errors to stderr like `LLVM Profile Error: Failed to write file ... File exists`. These are not real ClickHouse errors but cause the test client to raise `QueryRuntimeException` even when the return code is 0. This was causing `test_server_reload/test.py::test_change_listen_host` to fail in `amd_llvm_coverage` CI runs. https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=d9b2a1b80f514d66c594b524439026ff87193ada&name_0=MasterCI&name_1=Integration%20tests%20%28amd_llvm_coverage%2C%203%2F5%29 Co-Authored-By: Claude Opus 4.6 <[email protected]>
|
The question is - why "file exists"? Is it due to |
…terns The `LLVM Profile Error: Failed to write file ... File exists` occurs because many short-lived `clickhouse-client` processes inherit the same `LLVM_PROFILE_FILE` env var and contend over a small merge pool. With only `%Nm` in the pattern, all processes share N files and fight over file locks. Adding `%p` (PID) gives each process its own set of profile files, eliminating contention. `llvm-profdata merge` handles the additional files transparently. This replaces the previous stderr filtering workaround with a proper fix. Co-Authored-By: Claude Opus 4.6 <[email protected]>
|
The "File exists" error is not a PID collision per se — it's a file contention issue. All short-lived Fixed by adding |
|
Adding %p to LLVM_PROFILE_FILE creates thousands of profile files that the pool cannot merge. |
|
This might happen only if the clickhouse binary was overwritten by a different version during other tests. I'm looking into how to make it immutable here |
|
@fm4v, our compatibility tests run old binaries. |
On the per-test coverage lanes every process of the coverage binary merged its counters at exit into a merge-pool file shared by the whole job (`%2m` for stateless clients and the job env, `%4m` for integration containers and host clients), without continuous mode. The exit-time merge maps the pool file, merges it, truncates it and rewrites it from offset 0. A process SIGKILLed during that rewrite (02435's `thread_cancel`, the runner's process-group kill on a timeout) can leave the value-profile records cut inside a record. Every later process whose pool slot (`getpid() % N`) is that file then reads past the mapping in `lprofMergeValueProfData` and dies with SIGSEGV after its output, and the file stays poisoned. NightlyCoverage `Stateless tests (amd_llvm_coverage_per_test, per_test_coverage, 2/8)` on 358b830 lost 251 results this way: all 392 crashing client PIDs were even (pool slot 0), and the 163 sequential tests, which use another pool file, all passed. Those lanes never merge a `.profraw`: per-test coverage is read inside the server from the static counter section and exported from `system.coverage_log`. So point `LLVM_PROFILE_FILE` at `/dev/null` there: no process opens, reads or merges a pool file any more. The other lanes keep their `%c` values, which never merge. Not `%p` (thousands of files, ClickHouse#97020), not `%c` again (the shared-mapping slowdown ClickHouse#118370 removed). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
clickhouse-clientprocesses inherit the sameLLVM_PROFILE_FILEenv var with only%Nm(merge pool) in the patternLLVM Profile Error: Failed to write file ... File exists%p(PID) to allLLVM_PROFILE_FILEpatterns (it-%p-%4m.profraw,ft-{batch}-%p-%2m.profraw,ft-server-%p-%m.profraw), so each process writes to its own set of filesllvm-profdata mergehandles the additional files transparentlyCI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=d9b2a1b80f514d66c594b524439026ff87193ada&name_0=MasterCI&name_1=Integration%20tests%20%28amd_llvm_coverage%2C%203%2F5%29
Test plan
InstrProfilingFile.c,InstrProfilingUtil.c)test_server_reload/test.py::test_change_listen_hosttest should pass in coverage builds without profile errors on stderrChangelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...