Skip to content

Keep the default compression codec stable across the upgrade check's restart - #121249

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/pin-default-compression-codec-upgrade-check
Sep 27, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/pin-default-compression-codec-upgrade-check

Conversation

@groeneai

@groeneai groeneai commented Sep 20, 2026 •

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

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

The Upgrade check CI job now uses the same randomized default_compression_codec for both servers it boots, instead of drawing it again for the new one.

Description

Upgrade check (amd_release) has gone red on 5 unrelated PRs in 90 days (0 master rows) with Code: 40 ... Checksums of parts don't match ... (CHECKSUM_DOESNT_MATCH), then a refetch from the peer.

The product is not at fault: two servers resolving different default_compression_codec values is supported, and it is reason 2 of the error's own list ("Using another compression method"). The harness is unfaithful to what it models, because a real in-place upgrade does not re-roll the codec.

Root cause: tests/config/install.sh draws the codec from ("LZ4" "ZSTD(1)" "ZSTD(3)") with $RANDOM on every configure call, and tests/docker_scripts/upgrade_runner.sh calls configure twice over one data directory. The draws are independent, so with p=2/3 the two servers write parts under different codecs, and a part committed before the restart is no longer byte-identical when re-merged after it. The failing jobs' logs show LZ4 then ZSTD(3) in one job, and the reverse in the other.

install.sh gains --default-compression-codec <value>, validated against that same array and failing closed on an invalid, empty or missing value; the runner passes the codec its first configure drew to the second. Per-job randomization is preserved, so all three codecs are still covered across runs. No allow-list entry and no relaxed assertion, so every other cause of this message is still reported.

This PR's own Upgrade check job.log is the end-to-end check: its two Default compression codec: lines must now be equal.

Allow-listing the message would be cheaper, but would also hide a genuine non-deterministic-merge regression and the statistics-format sub-case; happy to switch if you prefer that. No automated test is added: both files are CI job scripts, exercised only by the jobs that run them.

CI provenance:

No related open issue found.

Per-file measurement: what a codec change actually moves in a part

Three tables, identical except SETTINGS default_compression_codec; six single-row inserts each, then OPTIMIZE FINAL. t_lz4b is the control.

table codec hash_of_uncompressed_files uncompressed_hash_of_compressed_files
t_lz4a LZ4 1a56241dde1c3b70... 99aa37af378aa297...
t_lz4b LZ4 1a56241dde1c3b70... 99aa37af378aa297...
t_zstd ZSTD(3) 9c16a6e6a7c7ada2... efa362b63cf5c3a3...

md5sum of every file in the t_lz4a and t_zstd Compact parts:

file LZ4 vs ZSTD(3) compared as
data.bin differs feeds the mark offsets
data.cmrk4 differs uncompressed_hash_of_compressed_files
statistics.packed differs hash_of_uncompressed_files
count.txt, serialization.json identical hash_of_uncompressed_files
primary.cidx identical own primary_key_compression_codec, not randomized
columns.txt, columns_substreams.txt, metadata_version.txt identical -

With auto_statistics_types = '' the uncompressed-files aggregate stops diverging while the other still does, so statistics.packed is its sole carrier. It is registered with only file_size/file_hash by serializeStatisticsPacked, where serializeStatisticsWide also sets is_compressed/uncompressed_hash; aligning them would not fix this failure, since the marks half survives.

For a Wide part both aggregates move once a column's data spans more than one compressed block; below that every mark offset is 0 and only the statistics aggregate moves.


Workflow [PR]
Sync PR [sync-upstream/pr/121249]

Version info

  • Merged into: 26.10.1.801-master (included in 26.10 and later)

…restart

Upgrade check (amd_release) has gone red on 5 unrelated PRs in 90 days (0
master rows) with

  Code: 40 ... Checksums of parts don't match: hash of uncompressed files
  doesn't match (X vs Y), uncompressed hash of compressed files doesn't
  match (A vs B). (CHECKSUM_DOESNT_MATCH)

followed by a refetch from the peer. The server self-heals, but the <Error>
line is logged and no allow-list entry covers it, so the job fails.

tests/config/install.sh draws the server-level default_compression_codec
from ("LZ4" "ZSTD(1)" "ZSTD(3)") with $RANDOM on every configure call, and
tests/docker_scripts/upgrade_runner.sh calls configure twice over one data
directory: once for the previous-release server and once for the new one.
The two draws are independent, so with probability 2/3 the two servers of a
single job write parts under different codecs. Because it is a server
default it is not persisted into a table's CREATE, so every write resolves
it from the running server. A part the previous-release server committed to
ZooKeeper is then no longer byte-identical when the new server re-merges or
re-mutates it, and checkPartChecksumsAndCommit rejects it. This is reason 2
of the error message's own list ("Using another compression method"), so the
product is behaving as designed; the harness is what is unfaithful, since a
real in-place upgrade does not re-roll the server's compression codec.

Both compared aggregates are codec-sensitive, which is why the message
carries both clauses. serializeStatisticsPacked compresses each per-column
statistics blob with the part's codec but registers the container with only
file_size/file_hash, leaving is_compressed false, so codec-dependent raw
bytes are compared as uncompressed content. Separately, a mark encodes
offset_in_compressed_file, so the marks' uncompressed content embeds the
compressed layout of the data. Measured by turning statistics off: the
uncompressed-files aggregate then stops diverging while the other still
does, which attributes one bucket to statistics.packed and the other to the
marks. For a Wide part both move once a column's data spans more than one
compressed block; below that every mark offset is 0.

install.sh gains a --default-compression-codec option, validated against
the same array that defines the legal values and failing closed on an
invalid, empty or missing value; upgrade_runner.sh reads back the codec its
previous-release configure drew and passes it to the second configure only
(not through configure_opts, which both calls share). If the read-back is
empty the runner writes a FAIL row and exits. The runner then re-reads the
generated config after the second configure and fails the job if the
upgraded server's codec differs, so a pin that stops being applied cannot
quietly restore the randomized condition.

An option rather than an environment variable because b41d0c5 moved
this runner off env vars onto install.sh options, and the option makes the
requirement legible at the site a future part-format randomization would be
added. Per-job randomization is preserved, all three codecs are still
covered across runs, and reads are unaffected because every part records
its own codec in default_compression_codec.txt.

Deliberately not an allow-list entry for this message: that would also hide
a genuine non-deterministic-merge regression and the separate
statistics-format divergence, which is the signal worth keeping. After this
change that sub-case presents with only the "hash of uncompressed files"
clause, so it becomes cleanly attributable.

Co-Authored-By: Claude Opus 5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding labels Sep 20, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Two rounds. Round 1: an independent model (engine: codex) raised 1 finding, plus my own cold pass over
the resulting code (4 further findings). Round 2, after the fix: the independent model re-reviewed the
changed hunks and found nothing, and my own second cold pass found no blocker and no major.

# Sev Finding Verdict Evidence / action
1 ⚠️ The runner pinned the codec but never asserted that the pin took effect, so dropping the argument, or reinstating the unconditional draw inside install.sh, would have left the job green while the flake came back (tests/docker_scripts/upgrade_runner.sh) AGREE, fixed before publication The runner now re-reads the generated config after the second configure and fails the job with a named row if it differs from the previous release's. Measured in both drift directions: argument dropped, and option accepted then ignored by a drifted install.sh. Detection is ~2 runs in 3, since an unpinned redraw coincides with the pinned value 1 time in 3; before the fix only removing the option was loud, and the failure it prevents shows up in roughly 1 run in 1600.
2 ⚠️ My own: the PR justified adding no test with "install.sh sudos", which is false AGREE, fixed before publication grep -c sudo tests/config/install.sh is 0, every chown/chgrp in it is commented out, and ci/jobs/fast_test.py already runs it unprivileged into a temp tree. The claim is withdrawn. Declining the test still stands, on the reasons that are true: both files are CI job scripts, nothing under tests/ exercises either, and the runner now asserts the invariant itself at job time.
3 💡 The new FAIL row's first cell is phrased as the satisfied invariant ("Default compression codec is stable across the upgrade"), while every other FAIL row in this file is phrased as the failure, so the report renders it as the good outcome having failed AGREE, not changed Mine to own: I prescribed that string to the implementation, and caught it only on the second cold read. Nothing mechanical depends on it (the status cell drives the result, and the info cell carries both codecs), so I left the diff alone rather than spend a round on wording. Happy to flip it to Default compression codec changed across the upgrade if you would rather it matched its neighbours.
4 💡 The case " ${array[*]} " in *" $value "* membership test also accepts a multi-token string that is a literal substring of the option list, such as LZ4 ZSTD(1) AGREE, not changed Unreachable: the sole caller passes one token read back from the five-line file the script itself wrote. Glob metacharacters are rejected, with or without extglob, because the expansion is quoted and therefore matched literally (measured on bash 5.2.21).
5 💡 Under set -e, a missing default_compression_codec.xml would die inside the command substitution, before the attributable FAIL row is written AGREE, not changed Unreachable: tests/config/install.sh writes that file unconditionally under its own set -e, so a failed write fails configure one line earlier. The empty read-back that the guard does claim to cover is covered, and the second read happens after config.d has been rewritten wholesale.
6 💡 This job's cache digest lists ./tests/docker_scripts/ but not ./tests/config, unlike the Stress test job's, so a later change to install.sh alone can be served from a cached success and would not re-run this assertion AGREE, not changed Left out of the diff on purpose: adding it makes a two hour job re-run on every tests/config change, which is your call rather than mine. It is one line in ci/defs/job_configs.py if you want it. This PR is unaffected, since it changes tests/docker_scripts/ and the digest moves.

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are terminal
per finding. Findings on hunks unchanged by the fix round are auto-dropped.

Session id: cron:clickhouse-review-slot-8:20260920-224900

@clickhouse-gh clickhouse-gh Bot added the manual approve Manual approve required to run CI label Sep 20, 2026
@clickhouse-gh clickhouse-gh Bot closed this Sep 20, 2026
@clickhouse-gh clickhouse-gh Bot reopened this Sep 20, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. Three tables differing only in SETTINGS default_compression_codec, six single-row inserts each, OPTIMIZE FINAL: the LZ4 and ZSTD(3) parts differ in both compared checksum aggregates, on demand, every run. The CI failure itself is ~6e-4/run, but the defect the fix acts on is 100% reproducible.
b Root cause explained? tests/config/install.sh draws default_compression_codec with $RANDOM on every configure call; tests/docker_scripts/upgrade_runner.sh calls configure twice over one data directory. Two independent draws means p=2/3 the two servers write parts under different codecs, so a part committed pre-restart is no longer byte-identical when re-merged post-restart and checkPartChecksumsAndCommit rejects it.
c Fix matches root cause? Yes: it removes the second draw. No allow-list entry, no widened bound, no relaxed assertion, no lowered log level.
d Test intent preserved / new tests added? Preserved and improved: the check still reports every other cause of this message, now cleanly attributable, and per-job randomization is kept so all three codecs are still covered. No test file added: the invariant spans tests/config/install.sh and tests/docker_scripts/upgrade_runner.sh, nothing under tests/ exercises either (both are CI job scripts, and the runner assumes a docker job's /etc, /test_output and installed packages), grepping their text is the shape removed in #115650, and the runner now asserts the invariant itself at job time.
e Both directions demonstrated? Yes, at three layers. Repro: differing codecs move the aggregates, a same-codec control stays byte-identical. Pin: unpinned install.sh calls are confirmed to still draw different codecs, pinned calls produce identical config. New assertion: silent when the pin holds, and one named FAIL row plus a non-zero exit when it does not, measured both for a dropped argument and for an option that is accepted and then ignored.
f Fix is general across code paths? Both reported shapes, MergeFromLogEntryTask and MutateFromLogEntryTask, reach the same StorageReplicatedMergeTree::checkPartChecksumsAndCommit, so one fix covers both. Both configure sites in the runner are enumerated; there is no third. stress_runner.sh also calls configure twice and is measured safe: every table it creates between those calls is non-replicated, so it never reaches the peer comparison.
g Fix generalizes across inputs? The option is validated against the same array that defines the legal values, so it cannot drift from the randomization it constrains. All three values round-trip, including the parenthesised ZSTD(1)/ZSTD(3); invalid, empty and missing values all fail closed. Part-format breadth measured on Compact and Wide at two fixture sizes.
h Backward compatible? N/A for product compatibility: no product setting, no format change, no SettingsChangesHistory.cpp entry. The option is inert unless passed, and only this runner's second configure passes it. A previous-release server that ignored the config key would simply be unpinned, which is no worse than today's independent draw.
i Invariants and contracts preserved? The invariant is that within one CI job every server writing into the same data directory resolves the same part-format-affecting MergeTree defaults. Error paths are fail-closed and visible: an unreadable codec file writes a FAIL row and exits non-zero, still reported because the job wrapper parses test_results.tsv unconditionally after the container exits. Two failure modes of the pin have two mechanisms: a bad value (invalid, empty, missing) aborts install.sh before any codec file is written, and an absent or ignored pin is caught by the runner's equality assertion after the second configure, so the pin cannot stop being applied without ~2 runs in 3 failing loudly with a named row.

Session id: cron:clickhouse-impl-slot-4:20260920-223300

@groeneai
groeneai requested a review from maxknv September 20, 2026 23:14
@clickhouse-gh

clickhouse-gh Bot commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [ba97606]

Summary: ✅


AI Review

Summary

This PR fixes the Upgrade check harness so the second configure call reuses the first server's default_compression_codec instead of re-randomizing it across the upgrade boundary. I did not find a correctness gap in the new option plumbing in tests/config/install.sh or in the pin-and-verify flow added to tests/docker_scripts/upgrade_runner.sh, and I did not find another equivalent double-configure path in the touched harness code that still carries the same replicated-part checksum risk.

Final Verdict
  • Status: ✅ Approve

LLVM Coverage Report

Measured on commit ba97606.

Metric Baseline Current Δ
Lines 88.50% 88.50% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 80.70% 80.70% +0.00%

Changed lines: Uncovered code analysis did not run: No coverable C/C++ source files changed (contrib/ is excluded from coverage).

Newly covered: +151 lines in 46 files (-194 lines lost coverage) · Details

Full report

@alexey-milovidov alexey-milovidov self-assigned this Sep 27, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 27, 2026
Merged via the queue into ClickHouse:master with commit a49c2b6 Sep 27, 2026
176 of 349 checks passed
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 27, 2026
serprex pushed a commit to serprex/ClickHouse that referenced this pull request Nov 2, 2026
upgrade_runner.sh calls configure() twice over one embedded Keeper and data
directory, and with RANDOMIZE_KEEPER_FEATURE_FLAGS=1 each call draws
check_not_exists, create_if_not_exists and remove_recursive again,
independently. When create_if_not_exists goes from 1 to 0, a coordinated
refreshable view created during the stress phase (04811's APPEND view in a
database recreated as Replicated) is attached against a Keeper that lost the
flag, and RefreshTask stops it by design, logging an <Error> that the upgrade
log scan reports. This failed the check on 3 unrelated PRs in 30 days
(ClickHouse#118372, ClickHouse#117784, ClickHouse#114812); all 3 job logs show the 1 -> 0 flip.

A real in-place upgrade does not downgrade its Keeper, so carry the flags the
previous-release configure() drew into the upgraded server's keeper_port.xml
and fail the job if they still differ, the same shape as the codec carry-over
of ClickHouse#121249. Every job still draws random flags.

Validated locally: the real code extracted from both scripts, run 2000 times
in the CI image, restores the first draw 2000/2000 with no FAIL row; with the
restore removed the new check fails 1765/2000. On a master build, restarting
with create_if_not_exists turned off logs exactly the CI line, and restarting
with the flags unchanged logs nothing.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-testing Test content only (no production code). groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding manual approve Manual approve required to run CI pr-ci 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.

3 participants