Skip to content

Upgrade check: do not report a failed system.mutations query as an unfinished mutation - #121315

Merged
azat merged 1 commit into
ClickHouse:masterfrom
groeneai:upgrade-check-mutation-probe-attribution
Sep 23, 2026
Merged

azat merged 1 commit into
ClickHouse:masterfrom
groeneai:upgrade-check-mutation-probe-attribution

Conversation

@groeneai

@groeneai groeneai commented Sep 21, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #120908
Related: #120932
Related: #120978

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):

Report a failed system.mutations probe in the Upgrade check as a failed probe, instead of as a mutation that did not finish.

Description

Requested in #120908 (comment), accepting the offer in #120908 (comment). The server-side cause of that run's red was #120932, already merged and on this base; this PR is the diagnostics half only, and it does not relax the assertion.

Upgrade check reported The mutation submitted before the upgrade was not finished by the new server in runs where the mutation demonstrably did finish. 14 days of CIDB: 225 OK, 9 FAIL across 9 unrelated PRs since #120978 added the row, failure context empty in all 9. On #121247 the mutation was applied at 07:59:40.104 while all 60 probe executions ran 08:00:35..08:01:39, every one thrown.

system.mutations resolves every table it enumerates before the *MergeTree narrowing and the predicate (StorageSystemMutations.cpp:89-128), and rethrows each table's failed startup job, so one unrelated unloadable table makes the probe throw whatever the WHERE says. var=$(...) ||: then turned the throw into the empty string, which is not 1 and so was read as "not finished". The dump reads the same table, so the artifact the message named was 0 bytes.

The probe now has three outcomes instead of two, using the idiom already at :203 and :220: a thrown probe gets its own row, still FAIL, carrying the real error text. A genuinely unfinished mutation reds byte-identically to today, measured against a real server with SYSTEM STOP MERGES holding a real mutation, and against one whose async load job genuinely failed.

If you would rather one broken table produced one row and not two, making that third outcome non-failing is a one-line change, your call.


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

Version info

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

…finished mutation

The mutation-across-upgrade probe asks system.mutations whether the mutation
submitted to the old server was finished by the new one. That query cannot be
narrowed to the table it is about: StorageSystemMutations::fillData resolves
every table it enumerates (StorageSystemMutations.cpp:91) before the *MergeTree
narrowing at :95 and the predicate at :128, and getTablesIterator waits on each
table's startup job and rethrows its exception (DatabaseOrdinary.cpp:722-741).
One unrelated table that cannot load therefore makes the probe throw whatever
the WHERE says.

`var=$(clickhouse-client ...) ||:` then erased the throw: stderr went to the job
log, the exit status was discarded, and the variable was left as the empty
string. Only `= 1` was tested, so empty fell into the else branch and the job
reported that this mutation had not finished. The diagnostic dump reads
system.mutations too, so it threw for the same reason and the artifact the
message pointed at was 0 bytes.

Over 14 days of CIDB this produced 9 such rows on 9 unrelated pull requests
against 225 passes, with an empty failure context every time. On ClickHouse#121247 the
mutation was applied at 07:59:40.104 while all 60 probe executions ran between
08:00:35 and 08:01:39 and every one of them threw, so the report named the
wrong subsystem and carried no evidence for it. The underlying load failure in
those runs was the Keeper feature-flag error already fixed by ClickHouse#120932; this
change is the attribution half.

Give the probe three outcomes instead of two, which is the idiom this file
already uses for its two other system.mutations probes at :203 and :220: keep
the answer-1 and answer-0 rows exactly as they were, and report a thrown probe
as its own row carrying the real error text. That row stays a FAIL, because the
check could not be performed and passing silently would lose the same signal in
the other direction. The assertion is neither relaxed nor narrowed and a
genuinely unfinished mutation still reds byte-identically.

The `||` guard is load-bearing rather than decoration: `set -ex` is in effect,
and `A || B` with an assignment for B always succeeds. The existing
if/then/break/fi is kept for the same reason, since a false `&&` list as the
last command of the loop body would exit the job. The probe's stderr is
captured so the new row can carry its cause, and removed when empty per the
convention already at :239 and :439. The dump gains 2>&1 so it can no longer be
the empty artifact a message points at.

Requested at ClickHouse#120908 (comment)

Co-Authored-By: Claude Opus 5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-request PR origin: a maintainer pinged or directed groeneai labels Sep 21, 2026
@groeneai

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

Pre-publication review by an independent model (engine: codex; 0 findings), plus my own cold review
of the resulting code: no blocker, no major, 2 nits. Nothing is deferred.

# Sev Finding Verdict Evidence / action
1 💡 The new row names mutation_across_upgrade_error.txt, but the cleanup at the end of the block removes that file when it is empty, and it is empty if the probe exits non-zero without writing to stderr: timeout 1m firing (rc 124) because a load job hangs instead of failing. AGREE, noted Left as is. The row is still correctly attributed in that arm, set -x keeps + mutation_across_upgrade_finished=cannot_check in job.log, and this file already pairs (see X.txt) with [ -s ] || rm -f for application_errors.txt, unkilled_mutations.txt and unfinished_mutations.txt. In the arm that fires today the file measured 863 bytes. If you would rather close it, appending the exit code inside the || group is one line and would also separate a hang (124) from a throw (210).
2 💡 The cannot_check arm skips the system.mutations dump even in the case where only SELECT sum(v) FROM default.mutation_across_upgrade failed and the dump would still have worked. AGREE, noted Nearly unreachable: a table that cannot load also makes system.mutations throw, because its iterator waits for every startup job of the database before any narrowing (DatabaseOrdinary.cpp:722-741), so only a non-load execution error reaches the asymmetry.

Severity: ❌ blocker / ⚠️ major / 💡 nit. Also checked and clean: the assertion is not relaxed (every
arm that was red stays red, and the new arm is a FAIL too), the new row name and the new artifact
need no registration (ci/jobs/stress_job.py parses rows by cell count and uploads every file in
/test_output), and after this patch no var=$(...) ||:-then-compared site is left anywhere in
tests/docker_scripts/.

Session id: cron:clickhouse-review-slot-10:20260921-100600

@clickhouse-gh clickhouse-gh Bot closed this Sep 21, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes, 100%, two rigs. Stubbed client: the unpatched block writes the wrong row on every run. Real server: a table whose async load job genuinely fails makes the probe throw, clickhouse-client returns 210, and the real block writes the wrong row. Not sampled.
b Root cause explained? system.mutations resolves every table it enumerates (StorageSystemMutations.cpp:91) before the *MergeTree narrowing at :95 and the predicate at :128, and getTablesIterator rethrows each table's failed startup job (DatabaseOrdinary.cpp:722-741), so one unloadable table makes the probe throw whatever the WHERE says. `var=$(...)
c Fix matches root cause? Yes. The defect is that a failed probe was indistinguishable from a negative one; the fix gives the failure its own state and its own row. No bound widened, no tag added, no assertion removed or narrowed, no data reduced, wait loop unchanged.
d Test intent preserved / new tests added? Preserved and measured: with a genuinely unfinished mutation the patched block writes the byte-identical FAIL row and the same 720-byte dump. No test file is shippable and none was added: nothing in the tree exercises upgrade_runner.sh (its only reference is ci/jobs/stress_job.py:177) and it is not sourceable.
e Both directions demonstrated? Yes, in both rigs. Unpatched + thrown probe: the wrong row, empty failure context, 0-byte artifact. Patched + thrown probe: Cannot check whether the mutation ... was finished, 880-byte context carrying ASYNC_LOAD_WAIT_FAILED, no misleading dump. Plus two no-regression arms per rig, cmp byte-identical.
f Fix is general across code paths? Yes. Exhaustive census of `$(...clickhouse-client
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A for type wrappers (shell script). The relevant input space is the probe's outcome space, fully covered: stdout 1, 0, any other value including \N (unchanged else), and non-zero exit including timeout's 124 (the new row). Mid-loop transitions are consistent: the last iteration decides, and 2> truncation keeps the error file aligned with it.
h Backward compatible? Yes. No setting, no SettingsChangesHistory.cpp, no versioned format. One new test_name and one new artifact name; grep -rn "mutation submitted before the upgrade" matches only this file, and no allow-list, praktika pattern or dashboard keys on it. TEST_FAILURE_PATTERNS contains "Code:", so the new row's context buckets usefully where an empty context bucketed as nothing.
i Invariants and contracts preserved? Invariant added, none broken: a verdict row is written only from a probe that actually answered, and a probe that failed is reported as a failed probe. set -e safety measured on every path, all 12 arms exited 0: A || B with an assignment for B always succeeds; the existing if/then/break/fi was kept rather than a && list, whose false result as the loop body's last command would exit the job; [ -s f ] || rm -f f is rc 0 on a missing file.

Session id: cron:clickhouse-impl-slot-4:20260921-092300

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

clickhouse-gh Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [ba869a9]

Summary: ✅


AI Review

Summary

This PR changes tests/docker_scripts/upgrade_runner.sh so the upgrade-check mutation probe distinguishes a failed probe from a genuine "mutation not finished" result, captures the failed probe's stderr into a dedicated artifact, and keeps the existing failure path for a real unfinished mutation unchanged. I did not find a new correctness, contract, or metadata issue in the current diff after checking the patch, the surrounding script logic, and the prior PR discussion.

Final Verdict
  • Status: ✅ Approve

FROM system.mutations WHERE database = 'default' AND table = 'mutation_across_upgrade')
AND (SELECT sum(v) FROM default.mutation_across_upgrade) = 500500") ||:
AND (SELECT sum(v) FROM default.mutation_across_upgrade) = 500500" \
2> /test_output/mutation_across_upgrade_error.txt) || mutation_across_upgrade_finished=cannot_check

@azat azat Sep 23, 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.

Lots of sloppy comments but the most useful part is just "2>&1"

@azat
azat added this pull request to the merge queue Sep 23, 2026
@azat azat self-assigned this Sep 23, 2026
Merged via the queue into ClickHouse:master with commit de6b47a Sep 23, 2026
176 of 349 checks passed
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 23, 2026
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-ci-infrastructure CI/CD pipelines (GitHub Actions, CI scripts, runners). groeneai-origin-request PR origin: a maintainer pinged or directed groeneai 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