Repository navigation
Build all examples as a single multi-call binary - #100736
Conversation
Previously each example program was built as a separate executable, each statically linking the full ClickHouse codebase (~2 GB per binary). With 83 examples, `amd_compat` CI build produced ~77 GB of example binaries alone (vs ~22 GB for the rest of the build). This was caused by PR #86258 which added `-DENABLE_EXAMPLES=1` and `-k0 all` target to `amd_compat`, and PR #95826 which added `-DENABLE_EXAMPLES=1` to `ARM_BINARY`. This change: - Consolidates all 83 example programs into a single `clickhouse-examples` multi-call binary (like ClickHouse itself), dispatching by argv[0] or first argument - Each example's `main` is renamed to a unique entry point (e.g., `mainEntryExampleHashMap`) - Removes `-DENABLE_EXAMPLES=1` from `amd_compat` and `ARM_BINARY` CI configurations - Removes `AMD_COMPAT` from the "build all targets" group Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
|
Workflow [PR], commit [88dde57] Summary: ✅ AI ReviewSummaryThis PR consolidates example executables into a single Missing context
Findings❌ Blockers
ClickHouse Rules
Final Verdict
|
…clude list The examples dispatcher is not production code and uses `std::cerr` for help output, similar to `programs/main.cpp`. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
|
|
||
| #if defined(OS_LINUX) | ||
| int main(int argc, char ** argv) | ||
| int mainEntryExampleProcfsMetricsProviderPerf(int argc, char ** argv) |
There was a problem hiding this comment.
❌ clickhouse-examples now includes this source unconditionally (src/Examples/CMakeLists.txt), but this file still has an #else int main() fallback for non-Linux builds.
That creates multiple main definitions (src/Examples/main.cpp + this file) when OS_LINUX is false, which breaks linking.
Please rename the fallback entry point as well (for example to mainEntryExampleProcfsMetricsProviderPerf) and keep behavior via #if defined(OS_LINUX) inside that function.
The `parser_memory_profiler` is now part of the `clickhouse-examples` multi-call binary and is no longer built as a separate executable. Remove its artifact config, S3 upload hook, and references from CI workflow definitions. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
…paths Rename fallback `main` to `mainEntryExampleProcfsMetricsProviderPerf` in `procfs_metrics_provider_perf.cpp` (non-Linux path) and to `mainEntryExampleJitExample` in `jit_example.cpp` (non-`USE_EMBEDDED_COMPILER` path). These conflict with the `main` in `src/Examples/main.cpp` when building the consolidated `clickhouse-examples` binary. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Re-add the `-no-pie` and `-Wl,-no-pie` link options that were lost when `parser_memory_profiler` was consolidated into the multi-call binary. These flags ensure jemalloc heap profile addresses are stable across processes, enabling cross-process batch symbolization with `--symbolize-batch`. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
…les` multi-call binary The `run_profiler.sh` and `rebuild_reports.py` scripts still referenced the old standalone `parser_memory_profiler` binary path at `build/src/Parsers/examples/parser_memory_profiler`. Update them to use the new `clickhouse-examples` multi-call binary at `build/src/Examples/clickhouse-examples`. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
| list(APPEND EXAMPLES_SOURCES ../IO/examples/read_buffer_from_hdfs.cpp) | ||
| endif() | ||
|
|
||
| clickhouse_add_executable(clickhouse-examples ${EXAMPLES_SOURCES}) |
There was a problem hiding this comment.
❌ Consolidating all examples into one clickhouse-examples binary introduces One Definition Rule collisions from duplicated global symbols across different example translation units.
Concrete collisions now in one final executable include duplicate global type/function names like IColumn/ConcreteColumn (cow_columns.cpp vs cow_compositions.cpp) and helper functions like bench in multiple hash_map* examples. With separate binaries this was isolated; in one binary this is ODR-undefined behavior and can produce non-deterministic behavior at link/runtime.
Please isolate file-local declarations in each example (namespace { ... } or static for helpers/types that are not external API), especially in files listed by EXAMPLES_SOURCES.
Wrap file-local declarations (classes, helper functions, type aliases) in anonymous namespaces to prevent One Definition Rule violations when all examples are linked into a single multi-call binary. Key collisions fixed: - `IColumn`/`ConcreteColumn`/`print` in cow_columns.cpp vs cow_compositions.cpp - `SimpleHash`/`Grower` across hash_map3.cpp, hash_map_string.cpp, hash_map_string_3.cpp - `FastHash64`/`CrapWow` across hash_map_string.cpp and hash_map_string_3.cpp - `bench` template across hash_map_lookup.cpp, hash_map_string_2.cpp, hash_map_string_3.cpp - `AlternativeHash`/`CRC32HashTest` in hash_map.cpp - `HashMapWithDump` in hash_map3.cpp - `test_function` in jit_example.cpp For files with `ZeroTraits`/`DefaultHash` template specializations, the anonymous namespace is closed before the specializations (which must be in the namespace of the primary template) and reopened afterward. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
|
|
||
|
|
||
| int main(int argc, char ** argv) | ||
| int mainEntryExampleParserMemoryProfiler(int argc, char ** argv) |
There was a problem hiding this comment.
./parser_memory_profiler binary, but after this PR the tool is a subcommand of clickhouse-examples.
Please update the examples to avoid user confusion, e.g. ./clickhouse-examples parser_memory_profiler ....
Suppress `clang-diagnostic-unused-member-function` warnings with NOLINT in `hash_map3.cpp`, `hash_map_string.cpp`, and `hash_map_string_small.cpp`. Remove redundant `static` on `mix` inside anonymous namespace in `hash_map_string.cpp`. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Move global-scope type aliases and helper functions into anonymous namespaces in `string_hash_map.cpp`, `string_hash_set.cpp`, `two_level_hash_map.cpp`, and `hash_map_string_small.cpp` to avoid One Definition Rule violations when all examples are linked into the single `clickhouse-examples` binary. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Replace references to standalone `./parser_memory_profiler` with `./clickhouse-examples parser_memory_profiler` in the documentation comment block to reflect the multi-call binary consolidation. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Wrap file-local declarations (structs, classes, functions, variables) in anonymous namespaces across all example source files that are now compiled into the single `clickhouse-examples` binary. Key fixes: - `SimpleHash`, `FastHash64`, `CrapWow`, `Grower` were defined in multiple hash_map example files with different implementations - Generic names like `State`, `Key`, `Value`, `Source` in several examples could collide at link time - Template specializations (`ZeroTraits`, `DefaultHash`) kept at global scope where required for correct lookup Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
- Remove redundant `static` from functions in anonymous namespace in `compact_array.cpp` and `radix_sort.cpp` (readability-static-definition-in-anonymous-namespace) - Add NOLINT for false positive unused function/member warnings in `hash_map_string_3.cpp` (functions are used through template instantiation) Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
| * jeprof --text --show_bytes \ | ||
| * --base=/tmp/query_before.*.heap \ | ||
| * ./parser_memory_profiler \ | ||
| * ./clickhouse-examples parser_memory_profiler \ |
There was a problem hiding this comment.
The jeprof examples in this comment block are now incorrect for a multi-call binary.
jeprof expects positional arguments as <program> <profile...>. With the current form:
jeprof ... ./clickhouse-examples parser_memory_profiler /tmp/query_after.*.heapparser_memory_profiler is treated as a profile path (not a subcommand), so the command fails.
Please keep parser_memory_profiler only when running the profiler, but for jeprof analysis use ./clickhouse-examples as the program path:
jeprof ... ./clickhouse-examples /tmp/query_after.*.heap…p`, fix `jeprof` examples - Remove unused `DecomposedFloat32` struct and `sign` member from `DecomposedFloat64` in `dragonbox_test.cpp` (clang-tidy `clang-diagnostic-unused-member-function`) - Remove redundant `static` from functions in anonymous namespace in `int_hashes_perf.cpp` (clang-tidy `readability-static-definition-in-anonymous-namespace`) - Fix `jeprof` command examples in `parser_memory_profiler.cpp` to use `./clickhouse-examples` as the program path without the subcommand name, since `jeprof` expects `<program> <profile>` positional arguments Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
| targets = "fuzzers" | ||
| elif build_type == BuildTypes.ARM_BINARY: | ||
| targets = "clickhouse-bundle parser_memory_profiler" | ||
| targets = "clickhouse-bundle" |
There was a problem hiding this comment.
❌ This drops parser_memory_profiler from ARM_BINARY outputs.
Before this PR, ARM_BINARY explicitly built parser_memory_profiler and CI uploaded it as an artifact (ArtifactConfigs.parser_memory_profiler and build_master_head_hook.py), which was then documented in changelogs as a published tool. After this change, ARM_BINARY only builds clickhouse-bundle, and all corresponding artifact/upload wiring is removed.
That is a functional regression in packaging/distribution, not just a build-size optimization. Please keep publishing this tool (for example, by adding a dedicated lightweight target/job that builds clickhouse-examples and uploads it, or by retaining parser_memory_profiler publishing path) so existing workflows depending on the published profiler do not break.
The `parser_memory_profiler` is now a subcommand of `clickhouse-examples`. Update the `run_profiler.sh` help text for `--profiler` and the `README.md` description of `run_profiler.sh` to reflect the multi-call invocation.
|
|
||
| # The profiler binary is built from src/Parsers/examples/parser_memory_profiler.cpp | ||
| # The profiler binary is part of the clickhouse-examples multi-call binary (src/Examples/) | ||
| return { |
There was a problem hiding this comment.
This file switches profiler execution to the clickhouse-examples multi-call binary, but the --profiler CLI help still says Path to parser_memory_profiler binary.
That message now points users to a non-existent standalone binary and conflicts with the new path/messaging in this same file.
Please update the --profiler help text to Path to clickhouse-examples binary for consistency.
The `--profiler` CLI option still said "Path to parser_memory_profiler binary", but after consolidation the script now executes the `clickhouse-examples` multi-call binary. Update the help text to match. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Per PR review feedback: this example is no longer needed. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
@groeneai, fix "Logical error: Port is already connected" and send a separate PR. But maybe I've already asked about it recently - in that case, link the corresponding existing PR here. |
|
@alexey-milovidov yes — STID 0996 family ("Port is already connected" from Stress test CI on the fix branch: 143 success / 16 skipped / 1 unrelated. All 11 stress test variants pass with the fix. Includes regression test Once #103230 lands, STID 0996 will clear from this PR's CI as well. Tracking task: cc @CurtizJ @KochetovNicolai for re-review of #103230. |
|
@groeneai, fix Unit tests (asan_ubsan, function_prop_fuzzer) and send a separate PR. |
|
@alexey-milovidov re function_prop_fuzzer — same chronic UBSAN bug at You earlier LGTM'd this deferral on PR #101034 (2026-04-26). 30+ unrelated PRs hit this in 14 days; Avogar's fix adds a Once #102890 merges, function_prop_fuzzer will clear from this and all other affected PRs. |
A flaky check hands every worker the *same* changed test, so one heavy test contends with `--jobs N` copies of itself instead of with N unrelated tests. `clickhouse-test` already accounts for that: a test tagged `long` is exempt from the `TEST_MAX_RUN_TIME_IN_SECONDS` "too long" verdict of the check. The per-test budget was not exempt, though - `proc.wait(args.timeout)` killed such a test at the `--timeout` default of 600s regardless of the tag - so a pull request that merely edits one draws a red that says nothing about the change. Measured on `03927_autopr_input_bytes_estimation_prewhere_filter`, whose p50 under any `asan` lane on master is 33s and whose p90 is 55s: in the `amd_asan_ubsan` flaky check it runs in 307-383s and is killed at 600.3s. The inflation is the check's shape rather than a property of the test - in the same job the other five AutoPR estimation tests are 4.1x to 5.6x their own master p50 - and it has already produced the same 600.3s kill on pull requests that have nothing in common: ClickHouse#96844, ClickHouse#119350 and ClickHouse#100736. `TestCase.get_timeout` now gives a `long` test of a flaky check `FLAKY_CHECK_LONG_TEST_TIMEOUT_MULTIPLIER` times `--timeout`, and is the single place the per-test budget is read: the wait, the cleanup budget, the worker's upper-level alarm, and `CLICKHOUSE_TEST_TIMEOUT` for a `.sh` test that budgets itself against the harness. Every other test and every other job keeps `--timeout` unchanged. The external safety net in `run_tests` has to stay above the graceful alarm it exists to avoid pre-empting, so it is now derived from the same numbers instead of being a written-out 900s. For a job that is not a flaky check the derivation yields exactly the 900s it has always been; for a flaky check it yields 2220s, still far below the 2.5h job timeout. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The
amd_compatCI build was producing ~98 GB of binaries — almost 77 GB of which came from 167 individual example programs, each statically linking the full ClickHouse codebase (~2 GB per binary in release). Other builds produce 22-25 GB.This was caused by PR #86258 (Aug 2025) which added
-DENABLE_EXAMPLES=1and-k0 alltarget toamd_compat, and PR #95826 (Feb 2026) which added-DENABLE_EXAMPLES=1toARM_BINARYforparser_memory_profiler.This PR consolidates all 83 example programs into a single
clickhouse-examplesmulti-call binary (like ClickHouse itself usesclickhouse-client,clickhouse-local, etc. via argv[0] dispatch):Changes:
mainrenamed tomainEntryExampleXxxentry pointsrc/Examples/main.cppdispatcher andsrc/Examples/CMakeLists.txt-DENABLE_EXAMPLES=1fromamd_compatandARM_BINARYCI configsAMD_COMPATfrom "build all targets" group (back toclickhouse-bundle)Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Build all examples as a single multi-call binary.
Documentation entry for user-facing changes
Version info
26.5.1.166