Skip to content

Backport #108441 to 26.3: Stop refreshable MV gracefully on Keeper without MULTI_READ on ATTACH/restore - #119364

Merged
PedroTadim merged 3 commits into
26.3from
backport/26.3/108441
Sep 11, 2026
Merged

PedroTadim merged 3 commits into
26.3from
backport/26.3/108441

Conversation

@robot-ch-test-poll2

@robot-ch-test-poll2 robot-ch-test-poll2 commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Original pull-request #108441
Cherry-pick pull-request #118300

This pull-request is a last step of an automated backporting.
Treat it as a standard pull-request: look at the checks and resolve conflicts.
Merge it only if you intend to backport changes to the target branch, otherwise just close it.

The PR source

The PR is created in the CI job

Version info

  • Merged into: 26.3.33.54

@robot-ch-test-poll2 robot-ch-test-poll2 added pr-backport Changes, backported to release branch. Do not use manually - automated use only! pr-bugfix Pull request with bugfix, not backported by default labels Sep 10, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [BackportPR], commit [eb1aa59]

Summary: ✅

@groeneai

Copy link
Copy Markdown
Collaborator

The two integration reds here are this cherry-pick, but they are not a product problem on 26.3. The
backported fix works; the test's wait idiom needs a prerequisite that 26.3 does not have.

The product fix works. In the failing tsan run the graceful stop fires one second after the
restart on the downgraded Keeper:

00:42:56.995834 [ 957 ] <Error> RefreshTask(rdb.mv): Keeper server doesn't have all feature flags
required by refreshable MV: MULTI_READ, CREATE_IF_NOT_EXISTS. The view is stopped.

No abort, and zero occurrences of Unexpected exception in refresh scheduling in the whole log. That
is exactly what #108441 is for, and it holds on 26.3.

What hangs is SYSTEM WAIT VIEW, after the view is already stopped. The query at test.py:85
starts at 00:42:57.918, i.e. 0.9 s after the log line above, never returns, and at
00:52:58.322 the harness tears the server down with Closed all listening sockets. Waiting for 1 outstanding connections. That is 600.4 s, the client's DEFAULT_QUERY_TIMEOUT, so the failure is a
hang and not an assertion diff.

Why. On 26.3, RefreshTask::wait() ends in an unbounded loop:

if (coordination.coordinated && !refresh_append)
    while (true)
    {
        UUID expected_table_uuid = coordination.root_znode.last_success_table_uuid;
        ...
        if (storage && storage->getStorageID().uuid == expected_table_uuid)
            return;
        std::this_thread::sleep_for(std::chrono::milliseconds(10));

The give-up path returns before readZnodesIfNeeded, so after the restart coordination.root_znode
is still default constructed and last_success_table_uuid is the nil UUID. The target table's real
UUID never equals nil, and throw_if_error() cannot fire either because last_attempt_time is epoch
0, so the loop spins until the client is killed.

Master does not have that shape: 9ee280c5feca4 ("Refreshable MV dependencies overhaul", 2026-05-07)
added if (state == RefreshState::Disabled) return; ahead of that wait and replaced the loop with the
bounded waitForLatestTargetTable(). It is on 26.6 and 26.7, and absent on 26.3, 26.4 and 26.5.

CI already ran the control. The 26.6 arm #118301 passed this exact test in the same two job
families (amd_tsan, and asan + db disk + old analyzer); here it fails in both. Over 30 days the
CI database has exactly two FAIL rows for this test, both on this PR, and none on master. Same
content, so the only variable is the prerequisite.

I cannot push to backport/26.3/108441 (push: false for me on this repository), so this is a
decision for whoever can. My ranking:

  1. Adapt the test on the backport branch: the two SYSTEM WAIT VIEW rdb.mv calls that wait for the
    Disabled state (lines 85 and 107) become bounded polls. Every assertion after them is already
    satisfied by the state the log above shows, so this keeps the full regression coverage and touches
    no product code. query_with_retry exists on 26.3 with the same signature, so no new import is
    needed. Diff below, syntax checked against this PR's file.
  2. Additionally give 26.3's RefreshTask::wait() the if (state == RefreshState::Disabled) return;
    early exit. It restores master's SYSTEM WAIT VIEW semantics and closes the same hang for users,
    but it is a product change beyond the cherry-picked commit.
  3. Drop the test from the 26.3 backport and keep the product fix. Cheapest, loses the coverage.

Backporting 9ee280c5feca4 itself does not look reasonable to me: 720 insertions and 458 deletions
across 11 files, on a stable branch.

Option 1 diff (tests/integration/test_refreshable_mv_no_multi_read/test.py)
@@ -79,14 +79,13 @@
     # The server must be up and answering queries (no crash, no crash-loop).
     assert node.query("SELECT 1").strip() == "1"
 
-    # Attach schedules the graceful-stop pass asynchronously, so the status read can otherwise
-    # observe the transient Scheduling state before doScheduling reaches the Disabled state. Wait
-    # for the scheduled pass to settle (WAIT VIEW returns immediately once the view is Disabled).
-    node.query("SYSTEM WAIT VIEW rdb.mv")
-
-    # The view must have stopped gracefully, reporting the reason rather than aborting.
-    status = node.query(
-        "SELECT status, exception FROM system.view_refreshes WHERE view = 'mv'"
+    # The view must have stopped gracefully, reporting the reason rather than aborting. Attach
+    # schedules the graceful-stop pass asynchronously, so poll for it to settle rather than
+    # observing the transient Scheduling state.
+    status = node.query_with_retry(
+        "SELECT status, exception FROM system.view_refreshes WHERE view = 'mv'",
+        check_callback=lambda x: "Disabled" in x,
+        retry_count=120,
     )
     assert "Disabled" in status, status
     assert "multi-read" in status.lower() or "multi_read" in status.lower(), status
@@ -103,10 +102,11 @@
     assert node.query("SELECT 1").strip() == "1"
     # SYSTEM REFRESH VIEW is async: run() moves the task to Scheduling, and only the background
     # scheduler later hits the coordination.unavailable branch and switches it back to Disabled.
-    # Wait for that scheduled pass before asserting, so the read never observes transient Scheduling.
-    node.query("SYSTEM WAIT VIEW rdb.mv")
-    status = node.query(
-        "SELECT status FROM system.view_refreshes WHERE view = 'mv'"
+    # Poll for that scheduled pass, so the read never observes transient Scheduling.
+    status = node.query_with_retry(
+        "SELECT status FROM system.view_refreshes WHERE view = 'mv'",
+        check_callback=lambda x: x.strip() == "Disabled",
+        retry_count=120,
     ).strip()
     assert status == "Disabled", status
     assert not node.contains_in_log("Unexpected exception in refresh scheduling")

The SYSTEM WAIT VIEW at line 71 is left alone: MULTI_READ is still present there, the znodes were
read, so it returns normally.

The other three reds are pre-existing 26.3 conditions rather than anything from this cherry-pick.
test_filesystem_cache/test.py::test_bypass_cache_does_not_overread_non_last_segment is 0 OK / 3 FAIL
on 26.3 against 4683 OK / 0 FAIL on master over 30 days, and it failed the same day on the bare 26.3
branch and on other backport/26.3/* PRs; the 04611_iceberg_parquet_schema_evolution_prewhere_rename
failure is tracked separately.

PedroTadim and others added 2 commits September 11, 2026 09:08
26.3's wait() lacks master's early return for a Disabled view and enters
the target-table UUID handshake; with coordination.unavailable root_znode
was never read, so it spins forever and the new test times out.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@clickhouse-gh clickhouse-gh Bot added the external Author is not a member of the ClickHouse organization label Sep 11, 2026
@maxknv maxknv removed the external Author is not a member of the ClickHouse organization label Sep 11, 2026
@PedroTadim
PedroTadim merged commit 951f359 into 26.3 Sep 11, 2026
35 checks passed
@PedroTadim
PedroTadim deleted the backport/26.3/108441 branch September 11, 2026 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backport Changes, backported to release branch. Do not use manually - automated use only! pr-bugfix Pull request with bugfix, not backported by default

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants