Skip to content

Fix flaky test_replicated_database_active_node_taken - #121866

Closed
alexey-milovidov wants to merge 1 commit into
masterfrom
fix-flaky-replicated-db-active-node-taken
Closed

alexey-milovidov wants to merge 1 commit into
masterfrom
fix-flaky-replicated-db-active-node-taken

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Sep 23, 2026 •

Copy link
Copy Markdown
Member

test_replicated_database_active_node_taken (added in #114408) fails often on master and in PRs, e.g. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=66f7fa0a44e09f90f6d5c64a3e18f9d9bb5f181f&name_0=MasterCI&name_1=Integration%20tests%20%28arm_binary%2C%20distributed%20plan%2C%203%2F4%29, with:

Replica node '/clickhouse/databases/db_active_node_taken/replicas/s1|r1' in ZooKeeper already exists and contains unexpected value: 'node2:9000:...'. (REPLICA_ALREADY_EXISTS)

CREATE DATABASE ... ON CLUSTER creates the same replica on both hosts concurrently. If a host reads the replica node in Keeper before the other host writes it, createReplicaNodesInZooKeeper finds a foreign host ID, and the query itself fails with REPLICA_ALREADY_EXISTS. The scenario under test (the active node owned by another live server) is never reached. The test only passed when the second host read Keeper after the first one had written the replica. In that case the matching UUID lets it take the replica over, and then it finds active taken.

The test now creates the replicas one after another with the same explicit database UUID, which always takes that path. The unused cluster.xml is removed.

Related: #114408
Related: #115818

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

...

🤖 Generated with Claude Code


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

`CREATE DATABASE ... ON CLUSTER` creates the same replica on both hosts
concurrently. If a host reads the replica node in Keeper before the other host
writes it, `createReplicaNodesInZooKeeper` finds a foreign host ID and the
query itself fails with `REPLICA_ALREADY_EXISTS`, before the scenario under
test (the `active` node owned by another server) is reached.

Create the replicas one after another with the same explicit database UUID
instead, so the second host always takes over the replica written by the first
and then finds its `active` node taken.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=66f7fa0a44e09f90f6d5c64a3e18f9d9bb5f181f&name_0=MasterCI&name_1=Integration%20tests%20%28arm_binary%2C%20distributed%20plan%2C%203%2F4%29
Related: #114408

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [2ecfe2b]

Summary: ✅


AI Review

Summary

This PR rewrites test_replicated_database_active_node_taken so the two nodes get the same replicated-database UUID through two local CREATE DATABASE queries instead of a single ON CLUSTER query. That removes the flaky race in createReplicaNodesInZooKeeper while still driving the same same-UUID / taken-active path that PR #114408 was intended to cover. I did not find a correctness issue in the rewritten reproducer.

Missing context / blind spots
  • ⚠️ I did not run the integration test locally, and the PR CI matrix was still in progress during review.
Final Verdict

✅ No review findings.

@Algunenano Algunenano left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like #121820 approach a bit more (no hardcoded UUID). I'll merge that one instead

@Algunenano Algunenano closed this Sep 24, 2026
xuir268 added a commit to xuir268/ClickHouse that referenced this pull request Sep 24, 2026
Create both replicas sequentially with a shared database UUID so the test reaches the foreign active-node condition instead of failing during concurrent registration. Adapted from ClickHouse#121866.

CI: https://github.com/ClickHouse/ClickHouse/actions/runs/35963033445/job/107527703365?pr=105338
PR: ClickHouse#105338

Validation: Python syntax and diff checks. Full Docker integration test requires CI.
@clickhouse-gh clickhouse-gh Bot added comp-database-engines Database engine implementations (e.g., Atomic/Replicated) and database-level behavior. 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

comp-database-engines Database engine implementations (e.g., Atomic/Replicated) and database-level behavior. pr-ci

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants