Skip to content

Upgrade check: kill the mutations left unfinished by the stress phase - #120978

Merged
alexey-milovidov merged 5 commits into
masterfrom
upgrade-check-kill-stuck-mutations
Sep 20, 2026
Merged

alexey-milovidov merged 5 commits into
masterfrom
upgrade-check-kill-stuck-mutations

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Sep 19, 2026 •

Copy link
Copy Markdown
Member

Related: #120881
Related: #120975

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

...

Description

The post-upgrade <Error> log scan of Upgrade check keeps acquiring new allow-list entries for the same thing. A test deliberately starts a mutation that can never succeed - toUInt32 of a non-numeric string, throwIf(1), a type mismatch, a DELETE WHERE on a virtual column - and kills it at the end of the test file. The stress runner regularly stops a test file before its last statement (memory fault injection, the random query and client killer, the global time limit), and --upgrade-check implies --fake-drop, so the table and its broken mutation survive. The upgraded server resumes the mutation, retries it for the whole post-upgrade window, and its error reaches the scan. The last few entries added for exactly this - 16058d92c542d (04510), a271dbefd7977's neighbours, the throwIf entry - and #120881, which is the same thing again for 03640_multiple_mutations_with_error_with_rewrite_parts.

So instead of another entry: after the stress phase, on the old server, before it is stopped and upgraded, kill every mutation that is not done.

A mutation an interrupted stress run left behind is test garbage, not a backward-compatibility signal, and the scan had to suppress the mutation error messages wholesale anyway (MutateFromLogEntryTask matched every replicated one). With nothing left for the upgraded server to resume, the whole class is retired at once, and the scan gets stricter: a mutation error after the upgrade is now an anomaly rather than an expected message to be filtered out.

The entries that only ever masked a retried broken mutation are removed with it: the Cannot parse string ... as UInt32/UInt64/Int8 list, MutateFromLogEntryTask, Value passed to 'throwIf' function is non-zero, Unexpected const virtual column: _table, and Prevent converting Nullable type to non-Nullable type inside mutation. Code: 236 ... Cancelled mutating parts stays, because the new server's own shutdown emits it.

The mutations are listed into unfinished_mutations.txt in the job output before they are killed, so one that could not be killed can be attributed. KILL MUTATION throws for a read-only table, and set -e would abort the job, so they are killed one at a time rather than by a single statement that one such table would stop; each is addressed by a hash of its key, because database and table names are arbitrary strings that must not be carried through the shell.

KILL MUTATION throws for a read-only table, and set -e would abort the job, so they are killed one at a time rather than by a single statement that one such table would stop, each of them tolerating a failure. That tolerance is then accounted for in one place: the count of unfinished mutations after the loop, or a count that cannot be taken at all, is a FAIL before the server is upgraded, with the mutations still standing written to unkilled_mutations.txt. The invariant the removed allow-list entries rest on is checked where it is established, rather than rediscovered after the upgrade as an error message with nothing pointing back at this step.

A valid mutation still crosses the upgrade, now on purpose

Killing everything also takes away what the stress phase incidentally left of a real contract: a mutation submitted to the old server and finished by the new one. So the job now submits one deliberately, after the kill loop so that loop does not kill it - a table, UPDATE v = v + 1, held unfinished by SYSTEM STOP MERGES. That is in-memory state, so the upgraded server starts with merges enabled and has to resume the mutation on its own; afterwards the job requires it to be done with an empty latest_fail_reason, and sum(v) to have changed, so it has to have been applied to the data and not only marked done.

This is strictly better than what it replaces, because what the stress phase leaves behind is decided by which test file the runner happened to interrupt, and need not be valid at all.

Why the kill cannot be narrowed to the broken mutations

unfinished_mutations.txt from this pull request's own Upgrade check on dcefe415cd0 lists 15 unfinished mutations, all from 04338_on_fly_mutation_read_overwritten_lc_source, and all 15 with an empty latest_fail_error_code_name and latest_fail_reason - that test holds its mutations with SYSTEM STOP MERGES, so none had ever been attempted. Reproducing that state locally and restarting:

  • 12 of them resume and finish.
  • 3 of them (t_overwrite_before_consume, whose MODIFY COLUMN v UInt64 meets the on-disk 'x') fail forever with Code: 6 ... Cannot parse string 'x' as UInt64, 45 <Error> lines in the first 45 seconds, in the three shapes MutatePlainMergeTreeTask, executeStep() and MergeTreeBackgroundExecutor that the removed Cannot parse string 'x' as UInt64 entry was masking.

At kill time those three are indistinguishable from the twelve healthy ones, so no predicate over failure state can separate them - only the restart does, and by then the broken ones are already logging. This is why the kill is unconditional and why the valid case is supplied by a fixture instead.

master acquired #120881's entry while this was open; the merge drops it, since it is the same class and this change removes it without an entry.

Verification

Against a local server holding five broken mutations of these shapes - plain MergeTree, ReplicatedMergeTree, a table name containing a quote, throwIf(1), and a valid mutation chained behind a broken one - measuring the <Error> lines the scan leaks over the 60 s after a restart:

allow list mutations leaked <Error> lines
current alive 48
this change alive 224
current killed 0
this change killed 0

The second row is the point of the first half of the change - those 224 lines are what the removed entries were hiding, and the kill is what removes them. The 48 lines the current allow list still leaks are exactly the 03640 TYPE_MISMATCH mutation that #120881 adds an entry for, and this change removes them without one.

Additionally, for the parts added while addressing review: the invariant check reports OK after the loop kills the three broken mutations of 04338_on_fly_mutation_read_overwritten_lc_source, 1 mutations could not be killed before the upgrade when one is left alive, and Cannot count the mutations left unfinished by the stress phase against a dead port. The submitted mutation's check is 0 while it is held by SYSTEM STOP MERGES and 1 on the first poll after a restart, with sum(v) = 500500.

This should also retire #120975 (92 occurrences across 86 pull requests in 30 days), which is the same shape: 04653_mutation_rewrite_stale_part_column_type leaves a DETACH PART tombstone whose mutation is unfinished when the stress phase kills the server, and the restart resumes it into UNKNOWN_IDENTIFIER until cleanup drops the part. The mutation is not done before the restart either - that is why it is retried after one - so the kill removes it.


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

Version info

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

The post-upgrade `<Error>` log scan of `Upgrade check` keeps acquiring new
allow-list entries for the same thing: a test deliberately starts a mutation
that can never succeed - `toUInt32` of a non-numeric string, `throwIf(1)`, a
type mismatch, a `DELETE WHERE` on a virtual column - and kills it at the end
of the test file, but the stress runner regularly stops a test file before its
last statement, and `--upgrade-check` implies `--fake-drop`, so the table and
its broken mutation survive. The upgraded server resumes the mutation, retries
it for the whole post-upgrade window, and its error reaches the scan.

Kill the mutations instead, on the old server, between the stress phase and the
upgrade. A mutation an interrupted stress run left behind is test garbage, not
a backward-compatibility signal, and the scan had to suppress the mutation
error messages wholesale anyway. With nothing left for the upgraded server to
resume, the whole class is retired at once and the scan gets stricter: a
mutation error after the upgrade is now an anomaly rather than an expected
message to be filtered out.

So the entries that only ever masked a retried broken mutation are removed:
the `Cannot parse string ... as UInt32/UInt64/Int8` list, `MutateFromLogEntryTask`,
`Value passed to 'throwIf' function is non-zero`, `Unexpected const virtual
column: _table` and `Prevent converting Nullable type to non-Nullable type
inside mutation`. `Code: 236 ... Cancelled mutating parts` stays: the new
server's own shutdown emits it.

The list of mutations found before they are killed is written to
`unfinished_mutations.txt` in the job output, so a mutation that could not be
killed can be attributed. `KILL MUTATION` throws for a read-only table and
`set -e` would abort the job, so the mutations are killed one at a time rather
than by a single statement that one such table would stop; each is addressed by
a hash of its key, because database and table names are arbitrary strings that
must not be carried through the shell.

Verified against a local server holding five broken mutations of these shapes
(plain `MergeTree`, `ReplicatedMergeTree`, a table name containing a quote, and
a valid mutation chained behind a broken one). Over 60 seconds after a restart:

    allow list   mutations    leaked `<Error>` lines
    current      alive        48
    this change  alive        224
    current      killed       0
    this change  killed       0

The 48 lines the current allow list still leaks are exactly the
`03640_multiple_mutations_with_error_with_rewrite_parts` `TYPE_MISMATCH`
mutation that #120881 adds an entry for; this change removes them without one,
so it supersedes that pull request.

Related: #120881
@clickhouse-gh

clickhouse-gh Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [7ed43d6]

Summary: ✅


AI Review

Summary

This PR makes Upgrade check stricter by killing unfinished stress-phase mutations before the version hop, removing the matching log allow-list entries, and adding a synthetic mutation that must finish after restart. The direction is good, but the current script still weakens coverage for replicated mutations and its new success criterion can fail on already-killed rows, so I would not merge it yet.

Findings

⚠️ Majors

  • [tests/docker_scripts/upgrade_runner.sh:257] The replacement mutation only exercises the plain MergeTree executor. The allow-list entries removed here also covered MutateFromLogEntryTask, so after killing every leftover real mutation the upgrade check no longer exercises Keeper-backed ReplicatedMergeTree mutation replay across restart. Add a replicated sibling fixture or keep the claim / allow-list removal scoped to the plain path.
  • [tests/docker_scripts/upgrade_runner.sh:220] The post-kill invariant is stronger than KILL MUTATION guarantees. system.mutations explicitly allows a row to stay in is_killed = 1 and is_done = 0 for a while, and existing tests poll killed mutations with NOT is_done AND NOT is_killed for that reason. Counting every NOT is_done row as “could not be killed” will false-fail the job on an already-killed queue that the upgraded server will not resume.
Final Verdict

⚠️ Request changes — the cleanup is useful, but the replacement coverage is incomplete for replicated mutations and the leftover-mutation check can misclassify already-killed rows as failures.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Sep 19, 2026
Comment thread tests/docker_scripts/upgrade_runner.sh Resolved
# `04510_mutation_query_plan_only_virtual_columns`, whose `DELETE WHERE _table != ''` mutation is asserted to
# fail. Only a mutation command naming `_table` reaches that throw, since a query read fills it from the
# storage id, so the column name and the `MergeTreeSequentialSource` read path are matched together below.
# Mutation errors are deliberately absent from this list: the mutations left unfinished by the stress

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.

This blanket KILL MUTATION changes the upgrade contract the job covers. system.mutations is persisted old-server state: the docs for ALTER explicitly say a submitted mutation continues executing after restart, and the removed allow-list entry for Prevent converting Nullable type to non-Nullable type inside mutation is already one example where replaying an old mutation on the new binary exposed a compatibility issue. After killing every unfinished mutation here, the upgrade check can no longer catch regressions in resuming a legitimate old mutation across the version hop.

If the goal is to retire only the intentionally broken test mutations, this needs a narrower predicate; otherwise we need some other path that still exercises a valid unfinished mutation through the restart.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

🕵 Addressed in 417370f, and the report artifact of this pull request's own Upgrade check answers both halves of this with data.

unfinished_mutations.txt of the run on dcefe415cd0 lists 15 unfinished mutations, all from 04338_on_fly_mutation_read_overwritten_lc_source, and all 15 with an empty latest_fail_error_code_name and latest_fail_reason — that test holds its mutations with SYSTEM STOP MERGES, so none of them had ever been attempted. I reproduced that state locally from the artifact (same five tables, same 15 rows, same empty failure state) and restarted the server:

  • 12 resumed and finished. That is the coverage you are pointing at, and it is real.
  • 3 (t_overwrite_before_consume, whose MODIFY COLUMN v UInt64 meets the on-disk 'x') fail forever with Code: 6 ... Cannot parse string 'x' as UInt64 — 45 <Error> lines in the first 45 seconds, in the three shapes MutatePlainMergeTreeTask, executeStep() and MergeTreeBackgroundExecutor, which is exactly what the removed Cannot parse string 'x' as UInt64 entry was masking.

So a narrower predicate over failure state cannot work: at kill time those three are indistinguishable from the twelve healthy ones — no error code, no fail reason, nothing. It is the restart that separates them, and that is too late, because by then the broken ones are already logging.

Taking the other path you offer instead. 417370f submits one mutation deliberately, after the kill loop so it is not killed: a table, UPDATE v = v + 1, held by SYSTEM STOP MERGES. That is in-memory state, so the upgraded server starts with merges enabled and has to resume it on its own; after the upgrade the job requires it to be done with an empty latest_fail_reason and sum(v) to have changed, so it must have been applied to the data and not only marked done. Verified locally: the check is 0 while the mutation is held and 1 on the first poll after a restart, with sum(v) = 500500.

The coverage is therefore not just preserved but made deterministic — it no longer depends on which test file the stress runner happened to interrupt, or on whether what it left behind was valid in the first place.

On Prevent converting Nullable type to non-Nullable type inside mutation: that entry described the new version applying stricter validation to a mutation created before the validation existed, and the job's response to it was to suppress it permanently. It was not acting as a detector.

Artifact: https://s3.amazonaws.com/clickhouse-test-reports/PRs/120978/dcefe415cd055caaa25ad62e37a4935de124315e/pr/upgrade_check_amd_release/unfinished_mutations.txt

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.

417370f restores one cross-upgrade mutation, but it only exercises the plain MergeTree path. The removed allow-list entries were also masking failures from MutateFromLogEntryTask, and after the cleanup there is no replicated unfinished mutation left for the restart to replay. So a regression in resuming Keeper-backed ReplicatedMergeTree mutations can still slip through: the synthetic replacement at tests/docker_scripts/upgrade_runner.sh:257 uses ENGINE = MergeTree, not ReplicatedMergeTree.

If this check is meant to preserve the old contract across both engines, it needs a replicated sibling fixture as well, or the “mutation errors are real findings now” claim below stays too broad.

@clickhouse-gh clickhouse-gh Bot added the comp-ci-infrastructure CI/CD pipelines (GitHub Actions, CI scripts, runners). label Sep 19, 2026
Conflict in `tests/docker_scripts/upgrade_runner.sh`: #120881 landed on
`master` while this branch was open and added an allow-list entry for the
`03640_multiple_mutations_with_error_with_rewrite_parts` mutation
(`Code: 53. DB::Exception: Cannot convert string 'b' to type UInt64: while
executing 'FUNCTION equals(c0.size`) in the same two hunks this branch
deletes.

Resolved in favour of this branch, so the new entry is removed as well.
That mutation is the very case measured in this pull request: with the
allow list of `master` and the mutations left alive it is the 48 `<Error>`
lines that still leak, and killing the mutations before the upgrade brings
them to zero without any entry. Keeping the entry would leave a dead
pattern in a list the branch documents as deliberately free of mutation
errors.

Related: #120881
The keys of the mutations to kill were listed by a command substitution in
the list of a `for` loop. That is not a command `set -ex` watches, so a
listing that failed or timed out was indistinguishable from an empty result:
the loop ran zero times, the job carried on, every unfinished mutation
survived into the upgraded server, and the post-upgrade `<Error>` scan - which
this pull request stops tolerating mutation errors in - failed much later,
with nothing pointing back at the skipped step. Demonstrated on a standalone
script: `for k in $(bash -c 'exit 124')` under `set -e` neither aborts nor
reports, while the assignment form below returns the exit code.

List into a variable, so the exit code is the condition of an `if`, and write
a `FAIL` row naming the step when it is non-zero. The kill statements
themselves keep their `||:` - `KILL MUTATION` legitimately throws for a
read-only table, and one such table must not stop the rest.

The mutations that survive a kill are still reported: `unfinished_mutations.txt`
holds the ones found and `Unfinished mutations left:` the count after the loop.
Comment thread tests/docker_scripts/upgrade_runner.sh Resolved
Killing every unfinished mutation also takes away the one thing they were
incidentally covering: a mutation submitted to the old server and finished by
the new one, which is a real contract - a submitted mutation is persisted and
continues to execute after a restart.

That coverage was never dependable, because which mutations reach the upgrade,
and whether they are valid at all, is decided by which test file the stress
runner happened to interrupt. Replace it with a fixture: after the kill loop,
create a table, submit `UPDATE v = v + 1` to it and hold the mutation with
`SYSTEM STOP MERGES`. `SYSTEM STOP MERGES` is in-memory state, so the upgraded
server starts with merges enabled and has to resume the mutation on its own.
After the upgrade the job requires it to be done with no `latest_fail_reason`,
and `sum(v)` to have changed, so the mutation has to have been applied to the
data and not only marked done.

The report artifact of the `Upgrade check` of this pull request says why both
halves are needed. It lists 15 unfinished mutations, all of them from
`04338_on_fly_mutation_read_overwritten_lc_source`, and **all 15 with an empty
`latest_fail_reason`**, because that test holds its mutations with
`SYSTEM STOP MERGES` and they were therefore never attempted. Reproduced
locally from the artifact - same five tables, same 15 rows, same empty failure
state - and restarted:

- 12 of them resumed and finished. This is the coverage the fixture now makes
  deliberate.
- 3 of them (`t_overwrite_before_consume`, whose `MODIFY COLUMN v UInt64`
  meets the on-disk `'x'`) fail forever with
  `Code: 6 ... Cannot parse string 'x' as UInt64`, 45 `<Error>` lines in the
  first 45 seconds, in the three shapes
  (`MutatePlainMergeTreeTask`, `executeStep()`, `MergeTreeBackgroundExecutor`)
  that the removed `Cannot parse string 'x' as UInt64` entry was masking.

So the kill cannot be narrowed to the broken mutations by a predicate over
failure state: at kill time these three are indistinguishable from the twelve
healthy ones - every one of the 15 has no error code and no fail reason. It is
the restart that separates them, which is exactly too late.

Verified on a local server: the check expression is `0` while the mutation is
held, and `1` on the first poll after a restart, with `sum(v) = 500500`.

Report: https://s3.amazonaws.com/clickhouse-test-reports/PRs/120978/dcefe415cd055caaa25ad62e37a4935de124315e/pr/upgrade_check_amd_release/unfinished_mutations.txt
…killed

Every `KILL MUTATION` is under `||:`, on purpose, so that one read-only table
does not stop the rest of them, and the count that followed the loop only
printed its result. A kill that threw therefore carried its mutation into the
upgrade, where the `<Error>` scan - no longer tolerating mutation errors -
reported it as an unexplained error message with nothing pointing back at this
step.

Check the invariant the removed allow-list entries depend on where it is
established: a non-zero count of unfinished mutations after the loop, or a
count that cannot be taken at all, is a `FAIL` before the server is upgraded,
and the mutations still standing are written to `unkilled_mutations.txt`. The
per-mutation `||:` stays, so the loop still tries all of them.

The check runs before the mutation submitted for the upgrade to resume, which
is meant to be unfinished at that point; the order is noted in the comment.

Verified against a local server holding the three broken mutations of
`04338_on_fly_mutation_read_overwritten_lc_source`: the loop kills all three
and the check reports `OK`, an unkilled mutation gives
`1 mutations could not be killed before the upgrade`, and an unreachable
server gives `Cannot count the mutations left unfinished by the stress phase`.
# at this step. Each `KILL` above is allowed to fail so that one read-only table does not stop the rest of
# them, and this is where those failures are accounted for. This has to stay before the mutation submitted
# below on purpose, which is meant to be unfinished at this point.
if unfinished_mutations=$(timeout 1m clickhouse-client --query "SELECT count() FROM system.mutations WHERE NOT is_done")

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.

KILL MUTATION is not a synchronous “remove the row from system.mutations” operation. The system.mutations contract explicitly allows rows to stay in the normal is_killed = 1 and is_done = 0 state for a while, and existing stateless tests poll killed mutations with NOT is_done AND NOT is_killed for exactly that reason.

With the new SELECT count() FROM system.mutations WHERE NOT is_done, a queue of already-killed mutations is reported as “could not be killed” and fails the upgrade check even though the upgraded server will not resume it. Please either exclude is_killed rows here (and in unkilled_mutations.txt) or wait on a bounded drain condition that distinguishes “still running” from “already killed but not finalized yet.”

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ok.

@alexey-milovidov alexey-milovidov self-assigned this Sep 20, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 20, 2026
Merged via the queue into master with commit 0789222 Sep 20, 2026
176 checks passed
@alexey-milovidov
alexey-milovidov deleted the upgrade-check-kill-stuck-mutations branch September 20, 2026 03:40
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 20, 2026
pull Bot pushed a commit to Dream-hu/ClickHouse that referenced this pull request Sep 27, 2026
The pre-upgrade kill loop added in ClickHouse#120978 reds with "N mutations could not be killed before
the upgrade" on pull requests unrelated to mutations: 4 failures against 331 OK runs of the
counterpart assertion since it landed on 2026-09-20, on 4 unrelated pull requests, in 3 of
them the job's only red.

In the three occurrences whose job logs I read, the kill threw Code: 242 TABLE_IS_READ_ONLY
and the deliberate `||:` discarded it. The chain: 04070_truncate_all_tables_skip_views.sql
runs TRUNCATE ALL TABLES FROM currentDatabase(), which in stress mode is the runner's shared
test_N database, so it covers every table earlier tests left behind (--upgrade-check implies
--fake-drop, so their DROPs were no-ops). On the previous release the unfiltered form still
calls flushAndPrepareForShutdown() on every table in the database;
StorageReplicatedMergeTree::flushAndPrepareForShutdown does
restarting_thread.shutdown(part_of_full_shutdown = true), which sets need_stop, deactivates
the task and calls setReadonly(), so the replica is read-only permanently with no thread left
to re-activate it. The per-table truncate then throws, because truncate() begins with
assertNotReadonly(), so the tables are left read-only and un-truncated with their mutations
intact. Thirteen minutes later the kill loop reaches killMutation(), which also begins with
assertNotReadonly().

ClickHouse#119425 fixed the product half on master, the `if (!truncate || !query.has_tables)` guard in
InterpreterDropQuery, but it is not backported and the stress phase runs the previous
release's binary and queries, so only this script can act. Reproduced on v26.8.10.6-lts,
which find_previous_release picks today.

Three changes, all in the kill step:

- Each KILL MUTATION keeps its stderr in unkilled_mutation_errors.txt, and the FAIL line
  names it. Today the survivor is reported with an empty latest_fail_reason, so the artifact
  says nothing about why the kill did not happen, and attributing one occurrence cost a whole
  investigation.

- If a mutation survives, SYSTEM RESTART REPLICA the read-only replicas that still hold one,
  then run the same kill pass again. Re-attaching the table builds it from its metadata and
  starts a replica that can remove the mutation's ZooKeeper node. Waiting instead cannot work
  for this cause: the restarting thread is deactivated, so no session-expiry check
  re-activates the replica. The no-argument SYSTEM RESTART REPLICAS is unusable here because
  restartReplicas() passes throw_on_error = false, so a table it fails to restart is left
  detached and its mutation silently disappears from system.mutations.

- A restart that does not report success, that changes the number of rows in system.replicas,
  or that leaves its own replica read-only, writes its own FAIL row whatever the count says.
  Without this the change would be fail-open, which is worse than the red it removes, and it
  is fail-open in two distinct ways. doRestartReplica() detaches before rebuilding, so a
  failure after that point leaves the table detached; and because it re-creates the table with
  LoadingStrictnessLevel::ATTACH the storage always goes through
  ReplicatedMergeTreeAttachThread, whose startup() only waits for the first initialization
  attempt and never rethrows, so a restart whose first attempt fails returns success and
  leaves the replica read-only with a retry scheduled initialization_retry_period later.
  system.mutations reports only what an attached, initialized replica holds, because the
  mutation queue is filled by pullLogsToQueue(..., LOAD) on the same success path that later
  calls setNotReadonly(). Either state would otherwise drive the count to zero and report
  success for a mutation still in ZooKeeper. That load order is also why the per-replica check
  is race-free: is_readonly = 0 implies the mutations are already loaded.

Validated against a real v26.8.10.6-lts server, since no harness executes upgrade_runner.sh.
On one fixture of two bricked replicated tables the old block reports FAIL and the new one
OK; on a clean server it does nothing, leaves no artifact, and never enters the recovery
block. Both fail-open shapes were injected and both produce the new FAIL row while
system.mutations has already reached zero: the restart_replica_fail_after_detach failpoint for
the detached table, and a stopped Keeper for the replica that stays read-only, where the
unguarded block reported "The stress phase left no unfinished mutation to the upgrade" for a
mutation whose znode was still there and which executed as soon as the replica came back.
shellcheck reports the same findings as before.

Co-Authored-By: Claude Opus 5 <[email protected]>
alexey-milovidov pushed a commit to JayPokale/ClickHouse that referenced this pull request Oct 19, 2026
The stress phase runs many tests in one shared database per worker, and a
test that is stopped before its last statement leaves its row policies
behind. A database-level one (`02703_row_policy_for_database.sh`:
`ON * USING x=1 TO ALL` on `test_1`) filters every table of that database,
so after the upgrade the eager dictionary of `04365_dictionary_lazy_load`
over `test_1.src`, which has no column `x`, fails to load in the background
with `UNKNOWN_IDENTIFIER` and the log scan fails the job (seen on ClickHouse#126078).
The old server fails the same way, so it is leftover test state, not an
upgrade incompatibility. 15 row policies were alive when the old server
stopped in that run, two of them created by the AST fuzzer.

Drop every row policy not defined in `users.xml` before the upgrade and
fail the job when one survives, as is done for leftover mutations
(ClickHouse#120978). Neutralizing them instead does not work: the test config sets
`throw_on_unmatched_row_policies`, so a table whose policies apply to
nobody throws for every reader. The statements are generated server-side
from `system.row_policies.name`, so no name passes through the shell.

The drop takes away the policies that happened to cross the upgrade, so
one is created deliberately (`k < 3` on a 10-row table) and the new
server has to apply it.

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

comp-ci-infrastructure CI/CD pipelines (GitHub Actions, CI scripts, runners). 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.

2 participants