Skip to content

Stabilize flaky test_modify_column_comment_only_on_cluster - #108983

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/fix-flaky-modify-column-comment-on-cluster
Jul 2, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/fix-flaky-modify-column-comment-on-cluster

Conversation

@groeneai

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

Stabilize the flaky integration test test_alter_settings_or_comment_on_cluster::test_modify_column_comment_only_on_cluster (and its two sibling tests in the same file).

An ALTER ... ON CLUSTER returns once the distributed DDL task has finished on every host. That does not guarantee the just-applied change is already reflected in a host's in-memory metadata, which is what SHOW CREATE / system.columns read: the replicated ALTER_METADATA log entry (or the local settings/comment fast path) can still be in flight on a replica, especially right after the replica restart this test performs. The test asserted on a single immediate SHOW CREATE read per replica, so it raced that propagation window and intermittently failed (observed almost exclusively on slow builds, e.g. arm_binary, distributed plan and amd_msan; 0 master failures).

Failure signature (e.g. Integration tests (arm_binary, distributed plan)):

File: test_alter_settings_or_comment_on_cluster/test.py:253 - in test_modify_column_comment_only_on_cluster
    assert "modcol-with-type" in show_create, (node.name, show_create)
E   AssertionError: ('ch1', "CREATE TABLE test_db.modcol_comment ... COMMENT 'modcol-placement-comment' ...")

The previous comment is still shown because the last MODIFY COLUMN ... String COMMENT 'modcol-with-type' had not yet become visible on ch1 when the assert ran.

Fix (test-only): poll SHOW CREATE / system.columns until the expected value converges before asserting, via two small helpers (wait_show_create, wait_column_order) — the same assert_eq_with_retry convergence idiom already used by the sibling test_alter_comment_on_cluster. The asserts themselves are unchanged, so a value that never converges still fails the test with the final SHOW CREATE: the test keeps its full ability to catch a real routing/divergence regression. The ZooKeeper /metadata version checks stay immediate — they read ZooKeeper directly (synchronous source of truth) and are what verify the routing (fast-path vs replicated-log) correctness.

Validated with the local integration runner (debug build): the whole suite passed 30/30 (10 iterations x 3 tests). A standalone simulation of a lagging SHOW CREATE confirms the old single-read pattern fails the race while the polling helper converges, and a never-converging value still fails (intent preserved).

An ON CLUSTER ALTER returns once the distributed DDL task is finished on
every host, which does not guarantee the change is already visible in that
host's in-memory metadata (what SHOW CREATE / system.columns read): the
replicated ALTER_METADATA entry or the local settings/comment fast path can
still be in flight, especially right after the replica restart the test
performs. The test asserted on a single immediate SHOW CREATE read per
replica and raced that window (failed on slow builds, 0 master).

Poll SHOW CREATE / system.columns until the expected value converges before
asserting (wait_show_create / wait_column_order helpers), matching the
assert_eq_with_retry idiom of the sibling test_alter_comment_on_cluster. The
asserts are unchanged, so a value that never converges still fails the test.
The ZooKeeper /metadata version checks stay immediate (synchronous source of
truth that verifies routing correctness).

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

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? The CI failure is a low-frequency timing race (1 per PR on slow builds, 0 on master), not forceable by brute count. Modeled deterministically: a standalone simulation of a lagging SHOW CREATE (returns the old comment for N reads, then converges) makes the old single-read assert fail every time.
b Root cause explained? ALTER ... ON CLUSTER returns when the distributed DDL task is finished on every host, which does NOT guarantee the change is already visible in that host's in-memory metadata (what SHOW CREATE / system.columns read). The replicated ALTER_METADATA entry or local settings/comment fast path can still be in flight on a replica, especially right after the replica restart this test performs. The test read SHOW CREATE once, immediately, per replica and asserted, so it raced that propagation window.
c Fix matches root cause? Yes. The fix polls SHOW CREATE / system.columns until the expected value converges before asserting, which directly bridges the propagation window from (b). It does not weaken or skip anything.
d Test intent preserved / new tests added? Yes. The asserts are unchanged; the helper only retries before the existing assert, and a value that never converges still fails with the final SHOW CREATE. The ZooKeeper /metadata version checks (the routing-correctness signal) stay immediate. No test removed/weakened.
e Both directions demonstrated? Yes. Standalone simulation: old single-read pattern FAILS the lagging-value race; the polling helper PASSES (converges); a never-converging value still FAILS (intent preserved). Real integration runner (debug build): whole suite 30/30 (10 iterations x 3 tests).
f Fix is general across code paths? Yes (generalized). The same race exists in the two sibling tests in the file (test_mixed_settings_and_comment_alter_on_cluster, test_mixed_setting_escape_index_filenames_on_cluster) and in the post-restart column-order reads; all per-replica metadata reads after an ON CLUSTER ALTER now use the convergence helpers, not only the one failing line.
g Fix generalizes across inputs? N/A — test-side stabilization, not a code bug. The helper is substring/order agnostic and applied to every post-ON-CLUSTER read in the file.
h Backward compatible? N/A — test-only change, no product/setting/format behavior touched.
i Invariants and contracts preserved? Yes. No source/invariant touched. The convergence helpers only add bounded polling before the unchanged asserts; the ZK-version asserts that verify the fast-path-vs-replicated-log routing invariant remain immediate.

Session id: cron:clickhouse-worker-slot-1:20260630-185600

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @tavplubix — could you review this? It stabilizes the flaky test_modify_column_comment_only_on_cluster (and its two siblings): an ALTER ... ON CLUSTER returns before the change is necessarily visible in each replica's in-memory metadata, so the test's single immediate SHOW CREATE read raced the DDL-propagation window. The fix polls SHOW CREATE / system.columns until convergence before asserting (same assert_eq_with_retry idiom as the sibling test_alter_comment_on_cluster); asserts and the ZooKeeper /metadata-version routing checks are unchanged.

@clickhouse-gh

clickhouse-gh Bot commented Jun 30, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [9369f93]

Summary: ✅


AI Review

Summary

This PR stabilizes test_alter_settings_or_comment_on_cluster by polling SHOW CREATE and system.columns reads after ALTER ... ON CLUSTER operations, while keeping the existing ZooKeeper metadata-version assertions immediate. I reviewed the current diff, prior PR discussion, the relevant routing/storage paths, and the Praktika PR report; I did not find a current correctness issue or a weakened assertion that warrants an inline finding.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jun 30, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.78% 85.82% +0.04%
Functions 91.47% 91.47% +0.00%
Branches 78.13% 78.27% +0.14%

Changed lines: No C/C++ source files changed — skipping uncovered code analysis.

Newly covered by added/modified tests: 300 line(s) across 14 file(s) · Details

Top files
  • src/Parsers/ExpressionElementParsers.cpp: 121 line(s)
  • src/Formats/FormatFactory.cpp: 66 line(s)
  • src/Processors/Formats/Impl/CSVRowInputFormat.cpp: 54 line(s)
  • src/Core/SettingsChangesHistory.cpp: 38 line(s)
  • src/Core/FormatFactorySettings.h: 8 line(s)

Full report

@alexey-milovidov

Copy link
Copy Markdown
Member

That does not guarantee the just-applied change is already reflected in a host's in-memory metadata

But why?

@alexey-milovidov alexey-milovidov self-assigned this Jul 2, 2026
@groeneai

groeneai commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator Author

Because ON CLUSTER returns once every host has written its .../finished/<host> node (DistributedQueryStatusSource::generate stops when num_hosts_finished >= waiting_hosts.size()), and a host writes that node right after its DDL task returns (DDLWorker::processTask, step 3). For the failing case, ALTER TABLE ... MODIFY COLUMN x String is a real replicated ALTER: taskShouldBeExecutedOnLeader returns supportsReplication() == true, so it runs on a single replica.

  • The executing replica runs StorageReplicatedMergeTree::alter, writes /metadata + /columns and appends an ALTER_METADATA entry to /log, then with the default alter_sync = 1 calls waitForLogEntryToBeProcessedIfNecessary, which waits for only its own replica: tryWaitForReplicaToProcessLogEntry(zookeeper_path, replica_name, ...).
  • The other replica does not run alter(). In tryExecuteQueryOnSingleReplica it observes the leader's is_executed_path, returns success and writes its finished node. The ALTER_METADATA entry is applied to its in-memory metadata later, asynchronously, by its own replication queue (executeLogEntry -> executeMetadataAlter).

So when the ON CLUSTER query returns, only the executing replica is guaranteed to have the new metadata in memory; the other replica has reported finished but may not have run executeMetadataAlter yet. SHOW CREATE / system.columns read that in-memory metadata, so an immediate read on the non-executing replica can still show the old value. The observed ('ch1', ...) failure is consistent with ch2 being the executing replica and ch1 reporting finished before its background apply; the replica restart right before this ALTER widens the window. alter_sync = 2 would wait for all replicas, but ON CLUSTER does not set it.

The settings/comment fast path is different (routed to every replica and applied inline), but the poll is applied uniformly and the asserts themselves are unchanged, so nothing is weakened.

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jul 2, 2026
Merged via the queue into ClickHouse:master with commit 3d0e5eb Jul 2, 2026
174 checks passed
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 2, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…-modify-column-comment-on-cluster

Stabilize flaky test_modify_column_comment_only_on_cluster
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