Skip to content

Randomize default compression codec in stateless tests - #108093

Merged
alexey-milovidov merged 9 commits into
masterfrom
randomize-default-compression-codec
Jun 28, 2026
Merged

alexey-milovidov merged 9 commits into
masterfrom
randomize-default-compression-codec

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Jun 22, 2026 •

Copy link
Copy Markdown
Member

Add randomization of the default column compression codec to the stateless test runner (clickhouse-test). For every randomized MergeTree table, columns without an explicit CODEC now get a default codec randomly chosen among LZ4, ZSTD(1) and ZSTD(3), via the per-table default_compression_codec MergeTree setting. This exercises more of the compression code paths across the existing test suite.

Codec values contain parentheses, which the two test execution paths treat oppositely: .sql tests embed the client options into a shell command line (so the value must be shell-quoted, otherwise the parentheses are a syntax error), while .sh tests expand CLICKHOUSE_CLIENT_OPT unquoted via $CLICKHOUSE_CLIENT (so the value must stay bare, otherwise the quotes are passed to the client literally). To support both, cli_format_settings gains a shell_quote option (using shlex.quote, which only quotes values that actually need it, so every existing setting is unchanged); add_effective_settings keeps bare values in the env var and shell-quotes the values it embeds into the .sql command line. The human-facing reproduction strings are shell-quoted too, so they can be copy-pasted.

Changelog category (leave one):

  • Build/Testing/Packaging Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Randomize the default compression codec (LZ4, ZSTD(1), ZSTD(3)) in stateless tests.

🤖 Generated with Claude Code

Version info

  • Merged into: 26.7.1.202 (included in 26.7 and later)

Add randomization of the default column compression codec to the
stateless test runner, cycling MergeTree tables (for columns without an
explicit CODEC) through LZ4, ZSTD(1) and ZSTD(3) via the per-table
`default_compression_codec` MergeTree setting.

Codec values contain parentheses, which the two test execution paths
treat oppositely: `.sql` tests embed the options into a shell command
line (so the value must be shell-quoted, otherwise the parentheses are a
syntax error), while `.sh` tests expand `CLICKHOUSE_CLIENT_OPT` unquoted
via `$CLICKHOUSE_CLIENT` (so the value must stay bare, otherwise the
quotes are passed through to the client literally). To support both,
`cli_format_settings` gains a `shell_quote` option (using `shlex.quote`,
which only quotes values that actually need it, leaving every existing
setting untouched). `add_effective_settings` now keeps bare values in
the env var and shell-quotes the values it embeds into the `.sql`
command line; the human-facing reproduction strings are shell-quoted too
so they can be copy-pasted.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Jun 22, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [1e3be0c]

Summary: ✅


AI Review

Summary

This PR moves stateless-test coverage of default_compression_codec to a randomized server-side MergeTree config and pins several codec-sensitive tests back to LZ4. The targeted pins address the earlier byte-exact failures, but the global no-randomization contract is still broken for untagged tests and diagnostics, so I would request changes before merge.

Findings

⚠️ Majors

  • [tests/config/install.sh:154, tests/clickhouse-test:2602] --no-random-settings and --no-random-merge-tree-settings still do not disable the new codec randomization. install.sh now chooses LZ4 / ZSTD(1) / ZSTD(3) unconditionally at server startup, while the runner only pins default_compression_codec = 'LZ4' when a test has a no-random tag. Global opt-out users such as Fast test and the randomized-settings diagnostic rerun path pass the no-random flags without adding those tags, so untagged MergeTree tables can still use random ZSTD in the supposedly non-random run. That can keep codec-sensitive failures or timeouts in the control run and breaks the reproduction contract.
    Suggested fix: make the generated server config use LZ4 for jobs that request no random settings, or otherwise include args.no_random_settings / args.no_random_merge_tree_settings in the runner-side pin and handle the test_observes_create_query_text cases that the current pin deliberately skips.
Tests
  • ⚠️ Please add or run a focused check that installs a non-LZ4 server default and then runs clickhouse-test --no-random-settings --no-random-merge-tree-settings against an untagged MergeTree test, proving that the table gets the stable LZ4 default in the no-random path.
Final Verdict

Status: ⚠️ Request changes

Minimum required action: restore the global no-random opt-out for the server-level default_compression_codec randomization and cover that path.

@clickhouse-gh clickhouse-gh Bot added the pr-build Pull request with build/testing/packaging improvement label Jun 22, 2026
Comment thread tests/clickhouse-test Resolved
The codec randomization added `--default_compression_codec ZSTD(1)`/`ZSTD(3)`
to the client options. For `.sh` tests these go through the
`CLICKHOUSE_CLIENT_OPT` env var, which is expanded unquoted via
`$CLICKHOUSE_CLIENT`; some `.sh` tests re-parse that string through a second
shell (e.g. perl `qx{}`, `eval`, `bash -c`), where the bare parentheses are a
shell syntax error (`sh: 1: Syntax error: "(" unexpected`). No single env-var
representation survives both the single-expansion case (needs bare) and the
re-parse case (needs quoting).

So `cli_format_settings` now drops shell-unsafe values from the bare env var
(`omit_unsafe`) while still shell-quoting them on the `.sql` command-line path.
`.sql` tests keep per-test codec randomization; a `.sh` test that needs a
specific codec sets it explicitly in SQL.

Also pin `default_compression_codec='LZ4'` in
`02028_system_data_skipping_indices_size`: skip index substreams are compressed
with the default codec, so their reported compressed size depends on it.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Comment thread tests/clickhouse-test Resolved
Replace the per-test CLI approach with a server-level <compression> config
override generated in tests/config/install.sh, randomized across LZ4, ZSTD(1)
and ZSTD(3). The per-test approach passed `--default_compression_codec ZSTD(3)`
through the client options; for .sh tests these go through CLICKHOUSE_CLIENT_OPT,
which is expanded unquoted and sometimes re-parsed through a second shell (perl
`qx{}`, `eval`, `bash -c`), where the bare parentheses are a shell syntax error.
No single env-var representation survives both uses.

The server <compression> override has no such problem: it is plain XML config,
applies to .sql and .sh tests alike, and matches how the default codec actually
works. A test that needs a specific codec pins it with
`SETTINGS default_compression_codec = '...'` (which overrides the server default,
since ClientBase only injects settings not already present).

This reverts the tests/clickhouse-test changes from the earlier commits on this
branch. The 02028 pin is kept (it is still needed under this approach).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Comment thread tests/config/install.sh Resolved
The server-level <compression> override (install.sh) randomizes the default codec
for ALL tests, bypassing the no-random-merge-tree-settings / no-random-settings
opt-outs. This broke the Fast test (a gate) on 16 codec-sensitive tests.

clickhouse-test now injects `default_compression_codec=LZ4` for any test tagged
no-random-merge-tree-settings or no-random-settings (skipping SHOW CREATE tests,
where it would change the printed definition). LZ4 has no shell metacharacters,
so it is safe in CLICKHOUSE_CLIENT_OPT for .sh tests. This pins all such tests
back to the historical default — what "no randomization" should mean — and
auto-fixes the ~255 opted-out tests, including 9 of the 16 Fast test failures.

The 7 remaining (untagged) failures assert codec-dependent output (index/column
sizes, mark offsets, statistics-based prewhere order). They run cleanly on master
under per-test MergeTree randomization, so only the codec affects them — pinned
inline with `SETTINGS default_compression_codec = 'LZ4'`:
01465 (+ SHOW CREATE reference), 02864, 03164, 03261, 04114, 04115;
03276 (a .sql.j2 that echoes its CREATE text, so an inline pin would break the
Jinja/SQL quoting) gets the no-random-merge-tree-settings tag instead.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Comment thread tests/clickhouse-test
# shell metacharacters, so it is safe in CLICKHOUSE_CLIENT_OPT for .sh tests.
# SHOW CREATE tests are skipped: the injected setting would change their output.
if (
(has_no_random_settings_tag or has_no_random_merge_tree_settings_tag)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--no-random-settings and --no-random-merge-tree-settings no longer disable this randomization. The new server <compression> value is chosen in install.sh, but this pin only covers tests that carry no-random tags; a global opt-out (the Fast test command passes both flags, and the diagnostics path reruns with {} as "without randomized settings") still leaves untagged tables using random ZSTD(1) / ZSTD(3) unless each test was manually pinned. That breaks the opt-out/repro contract and can keep codec-sensitive failures in the supposedly non-random run. Please include args.no_random_settings / args.no_random_merge_tree_settings in this condition, or gate the generated config so those modes restore LZ4 globally.

The codec injection for no-random-* tests uses --allow_merge_tree_settings, which
makes the client rewrite CREATE ... MergeTree queries (adding the SETTINGS). That
broke tagged tests that observe the query text — `01600_log_queries_with_extensive_info`
(reads system.query_log normalized_query_hash) — or whose CREATE reparse changes
semantics — `02293_compatibility_ignore_auto_increment_in_create_table` (the
client-side reparse no longer raises the expected SYNTAX_ERROR for AUTO_INCREMENT).

Such tests are not codec-sensitive (they pass under the randomized server default,
which is invisible to query text), so the injection now skips tests matching
`show create | create_table_query | normalized_query | auto_increment`. Tests that
read system.query_log only for metrics (e.g. 03277, 03634) are not excluded and keep
the pin.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…42/03278

The <compression> server override broke `clickhouse local`: ConnectionParameters
reads the top-level `<compression>` config key as a connection-level boolean, so a
codec selector there fails with "Cannot convert to boolean: zstd 3" — this broke the
"Scraping system tables" step (clickhouse-local --config-file=.../config.xml) in every
stateless flavor. Set the randomized default codec through the `default_compression_codec`
MergeTree setting in the <merge_tree> config section instead. Verified: clickhouse-local
no longer crashes, columns are compressed with the chosen codec, and an inline
`SETTINGS default_compression_codec = '...'` still overrides it.

Also pin the two genuine codec-sensitive stateless failures:
- 03278_json_subcolumns_in_skipping_indexes: JSON sibling of 03276, same .sql.j2 that
  echoes its CREATE text, so tagged no-random-merge-tree-settings (pinned via injection).
- 02842_move_pk_to_end_of_prewhere: cost-based prewhere reordering depends on column
  sizes, which depend on the codec; pinned to LZ4 (its diagnosis even confirmed it fails
  "without randomized settings", i.e. it is the server codec).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Comment thread tests/clickhouse-test
(has_no_random_settings_tag or has_no_random_merge_tree_settings_tag)
and not self.test_observes_create_query_text()
and "default_compression_codec" not in self.effective_merge_tree_settings
):

@Felixoid Felixoid Jun 22, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A long comment doesn't help understanding what is going on here.

Three variables with dedicated one-line comments would be much more valuable.

alexey-milovidov and others added 2 commits June 22, 2026 20:57
Full stateless suite (after the <merge_tree> fix) surfaced exactly three
codec-sensitive failures across all flavors; all pinned to LZ4:

- 02864_statistics_usage: prewhere condition order falls back to cost-based
  (column sizes) after statistics are dropped; sizes depend on the codec.
- 03783_autopr_dataflow_cache_reuse_qcc: the automatic-parallel-replicas
  decision compares estimated table bytes against a 1Mi threshold, so a
  smaller (ZSTD) codec flips pr_used. Diagnosis confirmed it fails "without
  randomized settings" (i.e. the server default codec).
- 03291_json_big_structure_deserialization: a `long` test using 128-byte
  compress blocks; ZSTD on tiny blocks is much slower and timed out under
  tsan (the rerun passed). Pin to LZ4 to keep it fast and deterministic.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Investigation of the "Server died" in the amd_debug flaky check: it is NOT an
OOM/crash. The server-wide memory limit (max_server_memory_usage, 53.8 GiB) was
never exceeded, dmesg shows no kernel OOM, there is no fatal signal/abort, and the
server shut down gracefully — the harness restarted it because `SELECT 1` (liveness)
timed out for ~60s. The 354 MEMORY_LIMIT_EXCEEDED entries are per-query graceful
rejections of background distributed log-export sends.

Root cause: this PR modifies 03291, which pulls it into the flaky check (each
modified test is rerun ~40x). 03291 stores a big JSON column in 128-byte compress
blocks, and a single `select json.a` took ~3000s (TOO_SLOW) under the debug build;
running it ~40x saturated the server and tripped the liveness timeout. Tag it
no-flaky-check (it is already `long`). The LZ4 pin added earlier keeps the regular
single run fast (a random ZSTD makes the tiny-block JSON read even slower).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

@groeneai, provide a fix for 04039_merge_tree_snapshot_teardown_race.

@groeneai

Copy link
Copy Markdown
Collaborator

@alexey-milovidov fix in #108338 (targets this branch).

04039 is long with index_granularity = 1 (8192 single-row granules ×2 tables) + 40 kill-mid-read iterations. On amd_msan, WasmEdge it already runs near the 600s cap (CIDB 30d: p50 ~228s, max OK 547s); the randomized ZSTD default tips it over — the FAIL was test_duration_ms = 600260 (timeout), not the teardown race. Codec is orthogonal to what the test checks, so both tables pin default_compression_codec = 'LZ4' (matching your 03291/02842/03278 pins). Verified locally against a ZSTD(3)-default server: passes, parts use LZ4.

…ompression-codec

# Conflicts:
#	tests/config/install.sh
@clickhouse-gh

clickhouse-gh Bot commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.30% 85.40% +0.10%
Functions 92.60% 92.60% +0.00%
Branches 77.60% 77.60% +0.00%

Changed lines: No C/C++ source files changed — skipping uncovered code analysis.

Newly covered by added/modified tests: 472 line(s), 24 function(s) across 134 file(s) · Details

Top files
  • src/Functions/FunctionShowCertificate.cpp: 37 line(s), 3 function(s)
  • src/Storages/StorageReplicatedMergeTree.cpp: 37 line(s)
  • src/Client/ClientBase.cpp: 24 line(s), 1 function(s)
  • src/Storages/MergeTree/MergeTreeSettings.cpp: 16 line(s), 3 function(s)
  • src/Disks/IO/CachedOnDiskWriteBufferFromFile.cpp: 15 line(s)

Full report

@alexey-milovidov alexey-milovidov self-assigned this Jun 28, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jun 28, 2026
Merged via the queue into master with commit 92910c2 Jun 28, 2026
169 checks passed
@alexey-milovidov
alexey-milovidov deleted the randomize-default-compression-codec branch June 28, 2026 17:37
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 28, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…t-compression-codec

Randomize default compression codec in stateless tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-build Pull request with build/testing/packaging improvement pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants