Skip to content

Upgrade check: cancel the stress phase's leftover queries before restarting replicas - #123841

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:upgrade-check-cancel-leftover-queries-before-restart
Oct 9, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:upgrade-check-cancel-leftover-queries-before-restart

Conversation

@groeneai

@groeneai groeneai commented Oct 4, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #123376
Related: #123069

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

Upgrade check: cancel the queries left over from the stress phase before replicas are restarted, so a leftover query holding a table lock cannot make the restart time out and fail the job.

Description

Upgrade check (amd_release) failed on #123069, which only changes proxy code, with Cannot run the mutation entries left behind by the killed mutations, a row added by #123376: report. Requested by @ alexey-milovidov in #123069 (comment).

Root cause. A stress query (01169_old_alter_partition_isolation_stress.sh, SELECT ... FROM merge(currentDatabase(), '')) outlived the stress phase. Its database still had the S3 table that an interrupted 04627_object_storage_lazy_hive_partitioning left on http://localhost:1, so the query kept retrying the listing (attempt 189 of 501) while it held a shared lock on every table of the database. The drain's SYSTEM RESTART REPLICA shuts the replica down and then waits for the exclusive lock. After lock_acquire_timeout (60 s in CI) it failed with DEADLOCK_AVOIDED, naming that query. The replica stayed read-only, so SYSTEM SYNC REPLICA ... PULL failed with TABLE_IS_READ_ONLY. No MUTATE_PART was queued.

Change. Run KILL QUERY WHERE 1 SYNC once, after the Tables count probe and before the mutation section. Nothing uses these queries: their clients are gone, and the old server's stop does not cancel them either (the test config sets shutdown_wait_unfinished_queries, so the stop waits 60 s and exits with them still running, as in this job). The drain and its fail-closed checks are unchanged.

Validation. Local rig on 26.9.9.28 (the release CI used): a killed mutation on a replicated table, plus the same merge() query over an unreachable S3 table, with its client gone. Without the change, 3 of 3 runs give the CI failure row (TABLE_IS_READ_ONLY, DEADLOCK_AVOIDED on that query). With it, 5 of 5 runs cancel the query in under 1 s and pass, and the step takes 1.7 s instead of 120 s. With nothing to cancel, and on the #123376 fixtures, the rows are unchanged.


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

Version info

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

…arting replicas

A stress query can outlive the stress phase and keep a shared lock on a
replicated table. In the failing job a `merge()` SELECT of
01169_old_alter_partition_isolation_stress kept retrying the S3 listing of a
table left on an unreachable endpoint by 04627. The drain's
`SYSTEM RESTART REPLICA` shut the replica down, timed out after
lock_acquire_timeout waiting for the exclusive lock (DEADLOCK_AVOIDED, owner =
that query), and left the replica read-only, so `SYSTEM SYNC REPLICA ... PULL`
failed with TABLE_IS_READ_ONLY and the step reported a failure with nothing
left to drain.

Cancel every running query once, before the mutation section. Nothing uses
their results: their clients are gone, and the stop of the old server does not
cancel them either (the test config sets shutdown_wait_unfinished_queries, so
the stop waits shutdown_wait_unfinished and exits with them still running). The
drain itself is unchanged and still fails closed.

Co-Authored-By: Claude Opus 5.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 Oct 4, 2026
@groeneai

groeneai commented Oct 4, 2026

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

Pre-publication review by an independent model (engine: codex, 2 runs; 1 finding) plus my own cold review (1 finding, 1 nit).

# Sev Finding Verdict Evidence / action
1 ⚠️ The comment and commit message said the old server's stop cancels the leftover queries anyway (tests/docker_scripts/upgrade_runner.sh) AGREE, fixed @ d41d151 tests/config sets shutdown_wait_unfinished_queries, so the stop waits 60 s and exits with them still running, as in the failing job. Wording corrected; no executable change.
2 💡 "the locks of the tables it reads": one leftover held an exclusive lock (a DROP) AGREE, fixed @ d41d151 Now "hold its table locks".
3 ⚠️ The KILL QUERY is best effort (||:), so its failure or timeout does not fail the job DISAGREE It only frees the locks the two restarts need: a survivor that blocks one still fails the step with the existing row; one that blocks nothing affects nothing this check measures (previous-release server, no hung check here, the stop abandons it). Under set -e a propagated failure would abort the job before the upgrade.

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:20261004-082300

@clickhouse-gh clickhouse-gh Bot added the manual approve Manual approve required to run CI label Oct 4, 2026
@groeneai

groeneai commented Oct 4, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. On 26.9.9.28 (CI's previous release): a replicated table with an unfinished mutation plus a merge() query over an S3 table on http://localhost:1, its client killed. Master's mutation section gives the CI row (TABLE_IS_READ_ONLY, DEADLOCK_AVOIDED names that query), 3 of 3 runs.
b Root cause explained? A stress query that outlives the stress phase holds a shared lock on a replicated table. SYSTEM RESTART REPLICA shuts the replica down, then times out waiting for the exclusive lock (60 s), and the replica stays read-only, so the following SYSTEM SYNC REPLICA ... PULL fails although no MUTATE_PART is queued.
c Fix matches root cause? Yes. It removes the lock holder: the leftover queries are cancelled before the section that needs exclusive locks. The drain's checks, bounds and failure rows are unchanged.
d Test intent preserved / new tests added? No test changed. No harness runs upgrade_runner.sh, so I validated it on a local rig, as for #121409 and #123376.
e Both directions demonstrated? Yes. Without the change, 3 of 3 runs fail and the step takes 120 s. With it, 5 of 5 runs pass in 1.6 to 1.8 s, and the query is cancelled 0.83 to 0.88 s after the KILL.
f Fix is general across code paths? Yes. One statement before the mutation section covers both exclusive-lock restarts (#121409 read-only replica, #123376 drain). Not in stress.py: the Stress test's hung check shares it and must still see such queries.
g Fix generalizes across inputs (params/datatypes/wrappers)? Exercised with a holder whose client is gone, with nothing to cancel (same rows as master), and on the #123376 fixtures, including a full upgrade onto master with 0 CHECKSUM_DOESNT_MATCH. WHERE 1 matches every running query except the KILL itself.
h Backward compatible? (maintainer-approved exception only) Yes. This is a CI script change only, checked against the 26.9.9.28 server that CI uses as the previous release.
i Invariants and contracts preserved? Still fails closed: a query surviving the best-effort KILL (2 min bound) fails the restart with master's row. Only the previous release's stress leftovers are cancelled; nothing uses their results, and without the KILL the old server's stop waits 60 s and exits with them running.

Session id: cron:clickhouse-impl-slot-4:20261004-081900

@clickhouse-gh

clickhouse-gh Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [d41d151]

Summary: ✅


AI Review

Summary

This PR updates tests/docker_scripts/upgrade_runner.sh to cancel orphaned stress-phase queries before the mutation-cleanup / replica-restart block. That matches the reported failure mode: a dead client can leave a long-lived query holding table locks, and the later SYSTEM RESTART REPLICA then times out with DEADLOCK_AVOIDED and leaves the replica read-only. I did not find an unresolved correctness or safety issue in the change: KILL QUERY WHERE 1 SYNC is bounded, excludes the current KILL statement when matching, and the existing fail-closed restart/drain checks still surface any survivor that continues to block the upgrade path.

Final Verdict
  • Status: ✅ Approve

@alexey-milovidov alexey-milovidov left a comment

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.

At least it does not harm.

@alexey-milovidov alexey-milovidov self-assigned this Oct 9, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 9, 2026
Merged via the queue into ClickHouse:master with commit 9708889 Oct 9, 2026
149 checks passed
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 9, 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-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