Skip to content

Fix 04105_system_pause_view and 04319_system_stop_all_background when STOP reaches the server after the refresh finished - #127917

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-04105-04319-stop-lands-after-refresh
Oct 28, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-04105-04319-stop-lands-after-refresh

Conversation

@groeneai

@groeneai groeneai commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #125034

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

Fix rare failures of the tests 04105_system_pause_view and 04319_system_stop_all_background where the SYSTEM STOP or SYSTEM CANCEL of a refresh reached the server after that refresh had already finished.

Description

Failing job: Stateless tests (amd_tsan, s3 storage, parallel, 3/3), <3a: stop after pause cancels the refresh> printed 10 0 instead of 0 1: the refresh completed with no exception.

The STOP/CANCEL tests (04105 Tests 3 and 3a, 04319 Tests 2 and 3) start a 10-row x 1 s refresh, poll from a new client until it has read a row, then send the interrupting statement from another client (3a: a third one for PAUSE). Nothing checks that the refresh is still running when the STOP is processed, so on a slow host the client start-ups can outlast it. On public amd_msan master runs the STOP already lands 1.1-3.3 s into the refresh. The engine is fine: a STOP processed before the result swap always cancels.

As in Test 1 (#125034), the check status = 'Running' and read_rows between 1 and 8 and the interrupting statements now go in one client call. read_rows counts the row being slept on, so read_rows <= 8 leaves at least 2 s. If the check misses, the view is re-created, up to 10 times. The check result is a new reference line, so an all-miss is a labelled mismatch, and a STOP that does not interrupt still fails the 0 1 line.

Validation:

  • sleep 11 after the old poll: the reported 10 0 diffs (10 1 for CANCEL).
  • sleep 9 in the first attempt: OK after 2 attempts; in every attempt: fails on the new line only.
  • PAUSE instead of STOP, or a no-op instead of CANCEL: fails with 10 0 / 10 1.
  • 50/50 OK per test on a debug build (random settings, -j 8), 10/10 on the CI amd_msan binary, all on the first attempt; the STOP lands 0.06-0.35 s into the refresh.

🤖 Generated with Claude Code


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

Version info

  • Merged into: 26.11.1.855-master (included in 26.11 and later)

… STOP lands after the refresh

The STOP/CANCEL tests relied on a 10-row x 1 s refresh outlasting the client
start-ups between "the refresh started" and "the interrupting statement reaches
the server": a poll client (wait_running_with_progress) and then a separate STOP
client, plus a third PAUSE client in 3a. Nothing proved the refresh was still
running when STOP was processed, so on a slow sanitizer host the refresh could
finish first and the assertion read the completed state (`10 0` instead of `0 1`).

Put the "still running" check and the interrupting statements in ONE client call,
the shape ClickHouse#125034 used for Test 1: `status = 'Running' and read_rows between 1 and 8`
(read_rows runs one row ahead of the 1 s transform, so <= 8 leaves ~2 s), followed
on the same connection by STOP / PAUSE+STOP / CANCEL. If a slow server let the
refresh get past row 8 before the check, the view is re-created and the attempt
repeated (at most 10). The check result is printed as a new label line, so an
environment where every attempt misses is a labelled mismatch rather than a silent
pass, and a STOP that stops interrupting still fails the existing `0 1` line.

wait_running_with_progress becomes unused and is removed from both files.

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 (3 nits, none blocking).

# Sev Finding Verdict Evidence / action
1 💡 The check runs right after SYSTEM REFRESH, so it can land before the first row is read DISAGREE read_rows is 1 within 0.02 s of the refresh start; 50/50 (debug) and 10/10 per test (amd_msan) hit on the first attempt; a miss is retried and an all-miss prints 0 on the new line
2 💡 Helper comment names only the too-late miss AGREE noted, wording only
3 💡 PR text said the source runs one row ahead AGREE reworded: read_rows counts the row being slept on

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are terminal per finding.

Session id: cron:clickhouse-review-slot-8:20261027-065300

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. The unfixed files with sleep 11 after the wait_running_with_progress poll fail every time with the reported lines: <3: stop cancels the refresh> 10 0, <3a: ...> 10 0 (04105), <2: ...> 10 0, <3: cancel ...> 10 1 (04319).
b Root cause explained? The STOP/CANCEL tests spawn a poll client and then a separate interrupting client after starting a 10 s refresh; nothing checks the refresh is still running when the STOP is processed, so slow client start-ups let it finish first and the assertion reads the completed refresh. The engine always cancels a STOP processed before the result swap.
c Fix matches root cause? Yes. The "still running" check (status = 'Running' and read_rows between 1 and 8) and the interrupting statements share one client call; a miss re-creates the view and retries (max 10). No widened bound, no tag, the 10-row fixture is kept.
d Test intent preserved / new tests added? Yes. The 0 1 assertions are unchanged and still fail when the command does not interrupt (PAUSE instead of STOP: 10 0; a no-op instead of CANCEL: 10 1). A new label line per case makes an all-miss a visible mismatch.
e Both directions demonstrated? Yes. Unfixed + delay: fails as above. Fixed + the same delay in the first attempt: OK after 2 attempts. Fixed: 50/50 per test on a debug build with random settings and -j 8, 10/10 per test on the CI amd_msan binary, all on the first attempt.
f Fix is general across code paths? Yes. All four interrupting-command cases in both files (04105 Tests 3, 3a; 04319 Tests 2, 3) use the helper; Test 1 already has the shape since #125034.
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A (test-only fix). Runs used randomized settings.
h Backward compatible? (maintainer-approved exception only) N/A (test-only fix).
i Invariants and contracts preserved? Yes. Each attempt drops and re-creates the view, src is read-only, and the later wait_status checks (Disabled / Scheduled) hold after a successful attempt in every run.

Session id: cron:clickhouse-impl-slot-4:20261027-062200

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @tuanpach, could you review this and add the can be tested label so CI runs? It applies the #125034 shape to the STOP/CANCEL cases of 04105 and 04319: the "refresh still running" check and the interrupting statement now share one client call (re-creating the view on a miss), so the STOP can no longer reach the server after the 10 s refresh has finished.

@clickhouse-gh

clickhouse-gh Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [08593cc]

Summary: ✅


AI Review

Summary

PR #127917 reduces timing failures in 04105_system_pause_view and 04319_system_stop_all_background by checking refresh progress and issuing cancellation commands through the same client, with bounded retries and explicit failure output. Reviewed all prior discussion, the complete diff at 08593cca2e8bcdef83258c3d1905e3f9f4c53389, and the relevant refresh execution paths. No actionable findings.

Missing context / blind spots
  • ⚠️ Sanitizer stateless CI results were still pending during review, and the scripts were not rerun locally because no ClickHouse binary was available. Runtime evidence comes from the PR's documented repeated debug/MSan runs and deliberate delay and cancellation mutations; completed sanitizer CI would provide independent confirmation.
Final Verdict

Status: ✅ Approve. No changes requested.

@clickhouse-gh clickhouse-gh Bot added pr-ci comp-testing Test content only (no production code). labels Oct 27, 2026
@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Oct 27, 2026
@alexey-milovidov alexey-milovidov self-assigned this Oct 28, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 28, 2026
Merged via the queue into ClickHouse:master with commit ea4869c Oct 28, 2026
526 of 528 checks passed
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 28, 2026
Blargian pushed a commit to Blargian/ClickHouse that referenced this pull request Nov 3, 2026
… the database disk on object storage

`interrupt_running_refresh` checks `status = 'Running' and read_rows between 1 and 8` one client
start-up after `SYSTEM REFRESH VIEW`. The refresh is already `Running` while it creates its target
table, and with the database disk on object storage that takes seconds, so the check saw
`read_rows = 0` and printed 0. Re-creating the view repeated the same timing, so all 10 attempts
missed: `<3a: refresh running before stop: 0>` in `Stateless tests (amd_asan_ubsan, db disk,
distributed plan, targeted)` (reported on ClickHouse#92472; there the check ran 0.4-0.6 s after the refresh
started and the refresh INSERT 0.6-2.6 s after it).

Wait until the refresh has read its first row, or failed, before the one-call check. A new view's
`read_rows` keeps its value after the refresh, so the wait cannot miss it (no hang like the one
ClickHouse#125034 fixed), and `clickhouse_test_time_left` bounds it. The `read_rows <= 8` check, the one-call
statements and the retry from ClickHouse#127917 are unchanged, so a STOP that lands after the refresh is
still retried and an all-miss is still a labelled mismatch.

Validated on master 4944813 CI builds: with the database disk on MinIO and 10 ms injected
latency each way, before 14/14 FAIL (release and asan_ubsan), after 56/56 and 42/42 OK, one attempt
per helper call; a failpoint that holds the refresh before it reads fails before and passes after;
50/50 OK per test with random settings on a local disk and on the database disk.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh clickhouse-gh Bot added comp-refreshable-materialized-view Refreshable materialized views: scheduled/periodic refresh, refresh state machine, refresh orches... and removed comp-testing Test content only (no production code). labels Nov 22, 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-refreshable-materialized-view Refreshable materialized views: scheduled/periodic refresh, refresh state machine, refresh orches... 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