Skip to content

Upgrade check: leave single-replica tables out of the killed-mutation drain - #133320

Open
groeneai wants to merge 1 commit into
ClickHouse:masterfrom
groeneai:upgrade-check-drain-single-replica-tables
Open

groeneai wants to merge 1 commit into
ClickHouse:masterfrom
groeneai:upgrade-check-drain-single-replica-tables

Conversation

@groeneai

@groeneai groeneai commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #123376
Related: #127843

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

Upgrade check (amd_release) fails Cannot run the mutation entries left behind by the killed mutations in 3 runs since 2026-11-15 on unrelated PRs (1, 2, 3), always on one table:

Code: 395 ... The replica is missing or read-only after SYSTEM RESTART REPLICA ...
Failed on test_1.t_replace_cover_rep
Code: 242 ... Table is in readonly mode ... (query: SYSTEM SYNC REPLICA ... PULL)
Failed on test_1.t_replace_cover_rep

The previous release's 05259_replace_partition_covers_outdated_parts_replicated creates one replica, stops cleanup, starts a mutation that keeps failing and drops a part without a covering part. Stopped right after the DROP PART (an injected memory fault in run 3), it leaves two parts on disk that Keeper no longer has. The pre-upgrade drain (#123376) restarts every replica of a table with an unfinished mutation; the restart reloads those parts and the replica turns read-only with TOO_MANY_UNEXPECTED_DATA_PARTS.

The drain exists for a leftover MUTATE_PART that clones its source part and fails the checksum check against a replica that applied the mutation; with one replica there is nothing to mismatch. This PR adds total_replicas != 1 to the drain's listing, wait count and dump, so a table Keeper lists with one replica is not restarted or waited on. A table whose Keeper read fails (total_replicas = 0) stays in, and the wait and the dump read Keeper only for tables still holding a MUTATE_PART entry.

Validated locally on the previous release 26.10.8.34, running the step extracted from the script: the old script reproduces both errors on the 05259 state; the new one leaves that table writable, still drains a two-replica table, does not wait on a blocked single-replica entry, and its polls request no Keeper status for 200 idle replicated tables.

The same table still turns read-only at the upgrade restart; #127843 handles that log line.


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

… drain

Before the upgrade, the drain step restarts every replica that shares a Keeper path with a table
holding an unfinished mutation, requires it to be writable afterwards, and then waits for the
MUTATE_PART entries of the killed mutations to run on the old server. It exists for a leftover entry
that clones its source part and then fails the checksum check against another replica that had applied
the mutation (ClickHouse#123376).

05259_replace_partition_covers_outdated_parts_replicated creates one replica, stops cleanup, starts a
mutation that keeps failing on 1_0_0_0 and drops part 1_1_1_0_2 without a covering part. When the
stress runner stops the script right after the DROP PART (an injected memory fault), the table survives
with 1_1_1_0 and 1_1_1_0_2 on disk but not in Keeper. The drain's own SYSTEM RESTART REPLICA reloads the
parts from disk, the attach thread finds 2 of 3 rows in parts Keeper does not have and leaves the replica
read-only with TOO_MANY_UNEXPECTED_DATA_PARTS. The writability check (Code 395) and SYSTEM SYNC REPLICA
PULL (Code 242) then fail, and the row "Cannot run the mutation entries left behind by the killed
mutations" is red on PRs that do not touch any of this.

A leftover entry can only mismatch another replica's part: checkPartChecksumsAndAddCommitOps compares the
new part with the same part of the other replicas in <zookeeper_path>/replicas. With a single replica the
entry clones the part unchanged on either server and logs a warning at most, so the drain has nothing to
do there. Restrict it to tables that Keeper lists with more than one replica (total_replicas != 1) in the
listing, the wait count and the dump of undrained entries. total_replicas is 0 when the Keeper read fails,
so an unknown case stays in the drain as before, and it counts Keeper replicas, not local ones, so a
replica whose sibling is detached stays in. The wait and the dump read total_replicas only for tables that
still hold a MUTATE_PART entry: system.replicas applies the inner IN before it issues Keeper status
requests.

Validated on a local server running the previous release, 26.10.8.34 (the version of the failing runs),
with the step extracted from the script: the base script reproduces both CI errors and the Code 231 on the
05259 state; the patched one leaves that table alone and writable, still restarts and drains a
two-replica table, does not wait on a blocked single-replica entry, and its polls request no status for
200 idle replicated tables.

Failed runs:
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=130655&sha=b50f2e6cdf7f666b029f0e029f22107a64c9e175&name_0=PR&name_1=Upgrade%20check%20%28amd_release%29
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=132154&sha=2ae3d75339eacf467c9ec8c828b76bb4dfbb5e2b&name_0=PR&name_1=Upgrade%20check%20%28amd_release%29
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=129641&sha=a0cafd06957beae685b0a9ee15eb324cb560a671&name_0=PR&name_1=Upgrade%20check%20%28amd_release%29

Related: ClickHouse#123376, ClickHouse#127843

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@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 (1 nit).

# Sev Finding Verdict Evidence / action
1 💡 The wait poll now reads Keeper (total_replicas), so a Keeper hang longer than its 10 s timeout fails the step AGREE, not changed A Keeper error gives total_replicas = 0 and keeps the table counted; the reads cover only tables still holding a MUTATE_PART entry (2 status requests, 0 for 200 idle tables, 18 ms on 26.10.8.34).

Severity: ❌ blocker / ⚠️ major / 💡 nit.

Session id: cron:clickhouse-review-slot-10:20261120-205401

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @maxknv, could you review this? The Upgrade check drain of killed-mutation entries now skips tables Keeper lists with a single replica: their leftover MUTATE_PART cannot mismatch another replica, and restarting the 05259 fixture's single replica turns it read-only (TOO_MANY_UNEXPECTED_DATA_PARTS), which failed the step on 3 unrelated PRs.

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. The step, extracted verbatim from the script, run on a local official 26.10.8.34 server holding 05259's interrupted state (one replica, cleanup stopped, stuck throwIf mutation, DROP PART), gives the CI's FAIL row every time: Code 395 then Code 242 on that table, Code 231 at the drain's restart.
b Root cause explained? The drain restarts every replica sharing a Keeper path with a table holding an unfinished mutation, single-replica tables included. The restart reloads two parts that are on disk but not in Keeper, the attach fails with TOO_MANY_UNEXPECTED_DATA_PARTS, and the writability check and SYSTEM SYNC REPLICA PULL fail.
c Fix matches root cause? Yes. A leftover MUTATE_PART can only mismatch another replica's part (checkPartChecksumsAndAddCommitOps), so the drain is limited to tables that Keeper lists with more than one replica. No table-name exemption, no tolerance of read-only replicas.
d Test intent preserved / new tests added? Test-infrastructure change, so no test of the harness (#119766). The drain still restarts and drains a two-replica table, verified on the local server.
e Both directions demonstrated? Yes. Old script: FAIL row. New script: no FAIL row, the table stays writable. With only the listing change reverted, the FAIL row returns. With only the wait/dump change reverted, the wait sits out its 60 s and the dump lists the blocked single-replica table.
f Fix is general across code paths? The same predicate is in all three queries that define the drained set (listing, wait count, dump). The read-only restart before the kill and the <Error> scan keep their own contracts and are unchanged.
g Fix generalizes across inputs (params/datatypes/wrappers)? total_replicas = 0 (Keeper unreadable, session expired) keeps a table in the drain as before. Keeper counts replicas, so a table whose sibling replica is detached stays in. Any single-replica table of this shape is covered, not only 05259.
h Backward compatible? (maintainer-approved exception only) CI script only, nothing user-visible. The queries run on the previous release (measured on 26.10.8.34).
i Invariants and contracts preserved? Multi-replica leftovers still run before the upgrade. A single-replica leftover runs after it and logs only a <Warning>, which the <Error> scan does not read. The poll reads Keeper only for tables holding an entry: 0 status requests for 200 idle replicated tables, against 200 for the form without the inner IN.

Session id: cron:clickhouse-impl-slot-41:20261120-195600

@clickhouse-gh

clickhouse-gh Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [d5f610a]

Summary: ✅


AI Review

Summary

The PR excludes tables with exactly one Keeper replica from the pre-upgrade killed-mutation drain, consistently updating replica selection, polling, and diagnostics. This avoids restarting interrupted single-replica fixtures while retaining the drain for multiple replicas and unknown replica counts. No actionable findings at d5f610ab285af81f09d7d17220955dc496bbe379.

Missing context / blind spots
  • ⚠️ The full upgrade scenario was not rerun locally. Runtime evidence comes from the PR's documented before/after reproduction and focused checks on 26.10.8.34; the current CI report contains no upgrade-test results. Local shell syntax validation passed.
Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added pr-ci can be tested Allows running workflows for external contributors manual approve Manual approve required to run CI comp-testing Test content only (no production code). labels Nov 20, 2026

This branch has not been deployed

No deployments
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). manual approve Manual approve required to run CI pr-ci

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant