Skip to content

Fix flaky test_rename_distributed_parallel_insert_and_select - #111121

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-rename-distributed-parallel-select-flaky
Jul 20, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-rename-distributed-parallel-select-flaky

Conversation

@groeneai

@groeneai groeneai commented Jul 20, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #110970

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 chronic flaky test_rename_column/test.py::test_rename_distributed_parallel_insert_and_select (Code: 47 UNKNOWN_IDENTIFIER on amd_msan/amd_tsan).

The cleanup renames back to num2 run via ON CLUSTER (async distributed DDL + async ReplicatedMergeTree metadata replication) with ignore_exception=True, so a failed or late rename is swallowed. The strict final selects then run immediately with no wait for schema convergence. When a distributed SELECT ... WHERE num2 ... is forwarded to a shard replica whose local _replicated metadata has not yet converged to num2 (still foo2/foo3), that shard's analyzer throws UNKNOWN_IDENTIFIER. This is correct engine behaviour (per-shard schema during async metadata replication); the test asserted before its precondition held.

Replaces the fixed cleanup renames with wait_for_rename_to_num2, which re-drives the idempotent ON CLUSTER rename-back and polls system.columns until num2 is present on every node's Distributed and _replicated table before the strict selects. This repairs both a swallowed cleanup rename and async replication lag. Test-only change; strict assertions unchanged.

Reproduced deterministically: a local-only RENAME num2 -> foo2 on node1 makes the Distributed schema outrun a shard replica, and a strict SELECT ... WHERE foo2 then fails with the exact Code: 47 from CI (Received from node4:9000 ... Identifier '__table1.foo2' cannot be resolved); with the wait it passes. Fixed test: 10/10 runs pass.

Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=110970&sha=b16c36ef0ff5c635f3cd4ffb7175c840a7198cc3&name_0=PR&name_1=Integration%20tests%20%28amd_msan%2C%208%2F8%29

Version info

  • Merged into: 26.7.1.1254 (included in 26.7 and later)
  • Backported to: 26.6.8.8, 26.3.33.92

The cleanup renames back to num2 run ON CLUSTER (async distributed DDL plus
async ReplicatedMergeTree metadata replication) with ignore_exception=True, so
a failed or late rename is swallowed. The strict final selects then run with no
wait for schema convergence. A distributed SELECT for num2 forwarded to a shard
replica whose local _replicated metadata has not yet converged (still foo2/foo3)
fails with UNKNOWN_IDENTIFIER at the analyzer. This is correct engine behaviour
for per-shard schema during async metadata replication; the test asserted before
its precondition held.

Replace the fixed cleanup renames with wait_for_rename_to_num2, which re-drives
the idempotent ON CLUSTER rename-back and polls system.columns until num2 is
present on every node before the strict selects, repairing both a swallowed
rename and replication lag.

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

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

Two independent review passes before opening this PR.

Gate A (approach review) — 1 finding, agreed and addressed:

  • band-aid-1 (major): a read-only convergence wait alone cannot repair a cleanup rename whose exception was swallowed (ignore_exception=True); it would only convert UNKNOWN_IDENTIFIER into a timeout. AGREE. Revised the fix so wait_for_rename_to_num2 re-drives the idempotent ON CLUSTER rename-back AND polls system.columns for convergence, repairing both the async-lag case and a genuinely failed/late rename.

Gate B (diff review) — 0 findings.

Diffstat reviewed: 1 file changed, +32/-8.

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. A local-only RENAME num2 -> foo2 on node1 makes the Distributed schema outrun a shard replica; a strict SELECT ... WHERE foo2 then fails 100% with the exact CI Code: 47 (Received from node4:9000 ... Identifier '__table1.foo2' cannot be resolved). Not "~1%".
b Root cause explained? Yes. Cleanup renames back to num2 are ON CLUSTER (async distributed DDL + async ReplicatedMergeTree metadata replication) with ignore_exception=True. The strict final selects run with no wait for convergence; a distributed select forwarded to a shard replica whose local _replicated schema is not yet num2 throws UNKNOWN_IDENTIFIER at the analyzer.
c Fix matches root cause? Yes. wait_for_rename_to_num2 re-drives the idempotent ON CLUSTER rename-back and polls system.columns until num2 is present on every node before the strict selects.
d Test intent preserved? Yes. Still verifies data via num2 after the parallel rename storm; strict selects (ignore_exception=False) unchanged. No no-random tag, no weakened assertion, no reduced data.
e Both directions? Yes. Fails (Code 47) without the wait; passes with it. Deterministic; fixed test 10/10 runs pass.
f General, not narrow? Covers both old names (foo2, foo3) and both tables (Distributed and _replicated) on all 4 nodes, i.e. the full divergence surface.
g Generalizes across inputs? N/A (test synchronization fix; no datatype/wrapper/parameter matrix).
h Backward compatible? N/A (test file only; no source, setting, or format change).
i Invariants/contracts preserved? Yes. No engine change. The helper only reads system.columns and re-issues idempotent ON CLUSTER renames, upholding the test's own precondition (schema converged before strict query).

Session id: cron:clickhouse-author-slot-4:20260720-170100

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @tavplubix could you review this? It fixes the flaky test_rename_distributed_parallel_insert_and_select (Code 47 UNKNOWN_IDENTIFIER): the test's final strict selects raced the async ON CLUSTER rename-back, so a distributed query could reach a shard replica whose local schema had not yet converged to num2. The fix re-drives the idempotent rename-back and waits on system.columns before asserting.

@PedroTadim PedroTadim added the can be tested Allows running workflows for external contributors label Jul 20, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 20, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [51eea39]

Summary: ✅


AI Review

Summary

This PR replaces the one-shot best-effort rename-back at the end of test_rename_distributed_parallel_insert_and_select with wait_for_rename_to_num2, which re-drives the idempotent foo2/foo3 -> num2 cleanup and waits until system.columns reports num2 on both the Distributed and _replicated tables on all four nodes before the final strict INSERT/SELECT. I did not find a remaining correctness issue in the changed test logic.

Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jul 20, 2026
@alexey-milovidov alexey-milovidov self-assigned this Jul 20, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jul 20, 2026
Merged via the queue into ClickHouse:master with commit 5436e00 Jul 20, 2026
178 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 21, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…uted-parallel-select-flaky

Fix flaky test_rename_distributed_parallel_insert_and_select
@PedroTadim

Copy link
Copy Markdown
Member

Backporting to fix CI

@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Sep 15, 2026
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Sep 15, 2026
clickhouse-gh Bot pushed a commit that referenced this pull request Sep 15, 2026
clickhouse-gh Bot added a commit that referenced this pull request Sep 15, 2026
Backport #111121 to 26.6: Fix flaky test_rename_distributed_parallel_insert_and_select
alexey-milovidov added a commit that referenced this pull request Sep 15, 2026
Backport #111121 to 26.3: Fix flaky test_rename_distributed_parallel_insert_and_select
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Sep 18, 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 pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-ci pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo v26.3-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants