Skip to content

Fix flaky test_parallel_replicas_protocol backward-compat OPTIMIZE hang - #110129

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-flaky-parallel-replicas-protocol-optimize-hang
Jul 12, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-flaky-parallel-replicas-protocol-optimize-hang

Conversation

@groeneai

@groeneai groeneai commented Jul 12, 2026 •

Copy link
Copy Markdown
Collaborator

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

Fixes the flaky integration test test_backward_compatibility/test_parallel_replicas_protocol.py::test_backward_compatability, which intermittently fails with the client 600s timeout on optimize table t final.

test_backward_compatability builds a 3-replica ReplicatedMergeTree mixing old release binaries (25.3, CLICKHOUSE_CI_MIN_TESTED_VERSION) with the build under test. It inserts once from nodes[0] and then ran optimize table t final.

With a single insert the table has exactly one part, so FINAL only merges a part into itself (server log: Merging 1 parts: from all_0_0_0 to all_0_0_0). That no-op merge still creates a MERGE_PARTS log entry every replica must execute. The old (25.3) replicas produce a byte-different merge result from the new build (CHECKSUM_DOESNT_MATCH: Different number of files: 3 compressed (expected 3) and 2 uncompressed ones (expected 3)), so they discard their own merge and fall back to fetching the canonical part from the new replica. That fetch fallback only fires after a merge-retry backoff that can take minutes, while the synchronous OPTIMIZE (alter_sync=1) issued from an old replica blocks on its own queue entry and hits the integration client's 600s timeout.

The two parallel-replicas assertions (sum(a) and order by a limit 10) do not depend on part layout, so the no-op FINAL merge serves no purpose. Removing it eliminates the cross-version MERGE_PARTS entry entirely; the existing system sync replica t loop still guarantees every replica sees the data before the assertions.

Not PR-caused: the failure recurs on master and across unrelated PRs (~0.1% on Integration tests (arm_binary, distributed plan, 3/4)); e.g. master run sha b5bea174, 2026-07-10.

Verified with 20 consecutive local runs mixing 25.3 and the current build.

Version info

  • Merged into: 26.7.1.829 (included in 26.7 and later)

test_backward_compatability builds a 3-replica ReplicatedMergeTree mixing old
release binaries (25.3, CLICKHOUSE_CI_MIN_TESTED_VERSION) with the build under
test. It inserts once from nodes[0] and then ran `optimize table t final`.

With a single insert the table has exactly one part, so FINAL only merges a part
into itself (server log: "Merging 1 parts: from all_0_0_0 to all_0_0_0"). That
no-op merge still creates a MERGE_PARTS log entry that every replica must execute.
The old (25.3) replicas produce a byte-different merge result from the new build
(CHECKSUM_DOESNT_MATCH: "3 compressed (expected 3) and 2 uncompressed ones
(expected 3)"), so they discard their own merge and fall back to fetching the
canonical part from the new replica. That fetch fallback only fires after a
merge-retry backoff that can take ~10 minutes, while the synchronous OPTIMIZE
(alter_sync=1) issued from an old replica blocks on its own queue entry and hits
the integration client's 600s timeout, failing the test at the optimize line.

The two parallel-replicas assertions (sum(a) and order by a limit 10) do not
depend on part layout, so the no-op FINAL merge serves no purpose. Removing it
eliminates the cross-version MERGE_PARTS entry entirely; the existing
`system sync replica t` loop still guarantees every replica sees the data before
the assertions. Verified with 20 consecutive local runs mixing 25.3 and the
current build.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Check Result
a Deterministic repro? Partial. The mechanism is proven from CI server logs (cross-version CHECKSUM_DOESNT_MATCH -> fetch-fallback backoff -> 600s client timeout on the synchronous OPTIMIZE). The ~0.1% timing tail is not reproducible on a fast host (15/15 + 20/20 local runs pass), as expected for a CI-host-load convergence tail.
b Root cause explained? Yes. Single insert -> one part -> optimize table t final is a no-op single-part merge (log: "Merging 1 parts: all_0_0_0 -> all_0_0_0"), which still creates a MERGE_PARTS entry the old (25.3) replicas cannot reproduce byte-identically vs the new build, forcing a minutes-long fetch fallback while the synchronous OPTIMIZE blocks past 600s.
c Fix matches root cause? Yes. Removes the no-op FINAL that is the sole creator of the cross-version MERGE_PARTS entry; not a timeout bump or assertion relaxation.
d Test intent preserved? Yes. The test's stated intent ("all we want is the query to run without errors") is the parallel-replicas SELECT across versions. sum(a) and order by a limit 10 are part-layout-independent; system sync replica t still guarantees data convergence before the assertions.
e Demonstrated in both directions? Partial. Fix side: 20/20 consecutive local runs green (25.3 + current build). Fail side: the tail is host-load dependent and not deterministically reproducible locally; failure evidence is the CI logs + CIDB history (master + unrelated PRs).
f Fix general, not a narrow patch? Scoped deliberately. A sibling no-op optimize table ts final exists in test_split_topology_rolling_upgrade but uses adjacent 26.5 images (no cross-version part-format difference for a plain UInt64 column) and has never failed in CIDB, so it is left unchanged rather than speculatively edited.
g Generalizes across inputs? N/A (integration test stabilization, not a code path).
h Backward compatible? N/A (test-only change).
i Invariants preserved? Yes. Replica data convergence is still enforced by system sync replica t; no server behavior changed.

Session id: cron:clickhouse-worker-slot-3:20260712-001000

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @nickitat — could you review this? It removes a no-op optimize table t final from test_parallel_replicas_protocol's backward-compat test: with the single insert the table is one part, so FINAL only creates a cross-version MERGE_PARTS entry the old 25.3 replicas can't reproduce byte-identically, and the synchronous OPTIMIZE hangs on the fetch-fallback backoff past the 600s client timeout. system sync replica already guarantees convergence for the assertions.

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Jul 12, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [2f69c7a]

Summary: ✅


AI Review

Summary

This PR removes an unnecessary OPTIMIZE TABLE t FINAL from test_backward_compatability in test_parallel_replicas_protocol.py. With the current single-insert setup, that step does not strengthen the parallel-replicas protocol coverage; it only adds an unrelated mixed-version merge path. The remaining SYSTEM SYNC REPLICA loop plus the per-node query assertions still cover the intended mixed-version read behavior, so I did not find a contract regression in the test.

Missing context / blind spots
  • ⚠️ I could not rerun the mixed-version integration test locally because this checkout does not include a built clickhouse binary. A focused python -m ci.praktika run "integration" --test "test_backward_compatibility/test_parallel_replicas_protocol.py::test_backward_compatability" run would close that gap.
Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jul 12, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — 2f69c7a

All CI checks passed (Finish Workflow / Mergeable Check green, all Integration test batches green including the previously-flaky Integration tests (arm_binary, distributed plan, 3/4) that this PR stabilizes). No failures to attribute.

Check / test Reason Owner / fixing PR
(none) — all green

Session id: cron:our-pr-ci-monitor:20260712-053000

@alexey-milovidov alexey-milovidov self-assigned this Jul 12, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jul 12, 2026
Merged via the queue into ClickHouse:master with commit f95e28a Jul 12, 2026
176 checks passed
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 12, 2026
pull Bot pushed a commit to peijunlin2008/ClickHouse that referenced this pull request Jul 13, 2026
…rolling_upgrade

A single insert is one part, so OPTIMIZE FINAL is a no-op merge whose
MERGE_PARTS log entry the 26.5 replicas cannot reproduce byte-identically
across versions. It can hang for minutes and occasionally raises code 341
(log entry not processed, replica shut down), as seen on the amd_tsan
Integration run. The assertions are part-layout-independent and the
existing system sync replica loop already guarantees convergence.

Mirrors the sibling fix in ClickHouse#110129 which removed the same no-op OPTIMIZE
FINAL from test_backward_compatability.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…-replicas-protocol-optimize-hang

Fix flaky test_parallel_replicas_protocol backward-compat OPTIMIZE hang
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…rolling_upgrade

A single insert is one part, so OPTIMIZE FINAL is a no-op merge whose
MERGE_PARTS log entry the 26.5 replicas cannot reproduce byte-identically
across versions. It can hang for minutes and occasionally raises code 341
(log entry not processed, replica shut down), as seen on the amd_tsan
Integration run. The assertions are part-layout-independent and the
existing system sync replica loop already guarantees convergence.

Mirrors the sibling fix in ClickHouse#110129 which removed the same no-op OPTIMIZE
FINAL from test_backward_compatability.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
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 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