Skip to content

Make the taken-active-node test claim the replica one host at a time - #121820

Merged
Algunenano merged 1 commit into
ClickHouse:masterfrom
groeneai:flaky-active-node-taken-sequential-claim
Sep 24, 2026
Merged

Algunenano merged 1 commit into
ClickHouse:masterfrom
groeneai:flaky-active-node-taken-sequential-claim

Conversation

@groeneai

@groeneai groeneai commented Sep 23, 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):

Not required (test-only change).

Description

test_active_node_owned_by_another_server, which I added in #114408 (merged 2026-09-23 00:55Z),
is flaky at ~2.2% on master: 13 failures in 599 runs since that merge, across 12 unrelated PRs, one
master run and 8 check flavours. Failing jobs:

The test used CREATE DATABASE ... ON CLUSTER, so both hosts claimed the same replica record at
once. A host that finds the record present with the same database UUID takes it over and the CREATE
succeeds; a host that reads it as absent re-reads it while creating, finds the other host's id and
fails with REPLICA_ALREADY_EXISTS, which the initiator returns to the client. The test tolerated
only the first ordering, so it raised at the CREATE before reaching what it is actually about: the
contended active node, reported asynchronously by the losing replica.

Now node1 creates the database, the test waits until node1 holds the active node, and node2 claims
the same identity carrying node1's database UUID, which is the statement ON CLUSTER sends to each
host. Only the active node is contended, so the loser is determinate: the assertions move to node2,
and a new one pins that node1 never reports the error. The cluster config has no reader left and is
removed.

Measured: the pre-fix test fails 3 of 20 fresh local runs (15%), the loser symmetric across that
sample; the new test passes 50 of 50. As a negative control, turning the underlying error back into
a logical error makes the new test fail again, so it still catches the regression #114408 fixed.

Both orderings report the misconfiguration correctly; the wedged database it leaves behind stays
#115818's subject.


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

Version info

  • Merged into: 26.10.1.597-master (included in 26.10 and later)

CREATE DATABASE ... ON CLUSTER made both hosts claim the same replica record at once. The host
that lost that claim failed the CREATE itself with REPLICA_ALREADY_EXISTS, which the initiator
returned to the client, so the test raised at the CREATE before it could observe the error it is
about: the contended <replica_path>/active node reported asynchronously by the losing replica.
Measured 6 failures in 420 post-merge runs (1.4%) across 6 unrelated PRs and 4 check flavours.

Create the database on node1, wait until it holds the active node, then have node2 claim the same
identity with node1's database UUID, which is the statement ON CLUSTER sends to each host. Only
the active node is contended now, so the loser is determinate: assert on node2 and assert that
node1 never reports it. The cluster config has no reader left and is removed.

Co-Authored-By: Claude Opus 5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding labels Sep 23, 2026
@groeneai

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

Pre-publication review by an independent model (engine: codex; 0 findings; bounded: 1 full pass +
1 fix round + 1 delta recheck). Reviewed diffstat matched the intended change set exactly
(2 files, +30/-49, no new untracked files). A separate cold reviewer pass raised no blocker and no
major; its nits are recorded below.

# Sev Finding Verdict Evidence / action
1 💡 The measured flake rate in this description was a plan-phase number and had gone stale AGREE, corrected before opening Re-measured over the same window: 13 failures in 599 runs (2.2%), 12 unrelated PRs, 8 check flavours, and one head_ref = master run (Integration tests (amd_llvm_coverage, 3/8), 15:26:26Z). Description updated; both linked jobs are still among the 13
2 💡 Two hosts now share one database UUID, so store/<uuid>/ could collide on a shared database disk and turn node2's CREATE into DATABASE_ALREADY_EXISTS DISAGREE prepareOnClusterQuery already gave both hosts one shared UUID before this change, and the db disk flavour has run the module against that on master; independently, helpers/remote_database_disk.xml's endpoint carries {shard}|{replica}, which cluster.py defaults per instance, so the two prefixes are disjoint
3 💡 CREATE DATABASE ... ON CLUSTER is no longer executed anywhere in the module DISAGREE No assertion is lost: on the diverging ordering the old test asserted nothing, it raised at the CREATE, which is the flake itself. The statement kept here is the one ON CLUSTER ships to each host, and DDL distribution is covered by test_replicated_database
4 💡 stay_alive=True is unused by the passing path and reads as a leftover DISAGREE It is load-bearing for the negative control, where the server aborts and the container has to outlive it so the log and SELECT 1 stay readable
5 💡 assert not node1.contains_in_log(...) would pass vacuously if the log path were wrong DISAGREE node1 answers four queries in the same test, and node2's positive assertions exercise the identical helper and path in the same run, so a wrong path reddens on node2 first

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are
terminal per finding. Findings on hunks unchanged by the fix round are auto-dropped.

Session id: cron:clickhouse-review-slot-11:20260923-172700

@clickhouse-gh clickhouse-gh Bot closed this Sep 23, 2026
@clickhouse-gh clickhouse-gh Bot reopened this Sep 23, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. The pre-fix test fails 3 of 20 fresh local runs (15%, vs 2.2% in CI), with the verbatim `Code: 253 ... Replica node '.../replicas/s1
b Root cause explained? Yes. ON CLUSTER makes both hosts claim the same replica record at once. A host finding it present with the same database UUID takes it over and the CREATE succeeds; a host reading it as absent re-reads it while creating, finds the other host's id and fails with REPLICA_ALREADY_EXISTS, which the initiator returns to the client before the asynchronous channel the test observes.
c Fix matches root cause? Yes. It removes the concurrent claim (sequences the two claims) instead of widening the oracle to accept the synchronous error. Widening was rejected: on that path the contended active node is never reached, so the remaining assertions would be vacuous in ~2.2% of runs.
d Test intent preserved / new tests added? Preserved and tightened. Every assertion the parent PR needs remains; the loser is now determinate, so any(node ...) becomes node2 and a new assertion pins that node1 never reports the error.
e Both directions demonstrated? Yes: pre-fix 3/20 FAIL, post-fix 50/50 PASS. Plus a negative control: turning the underlying error back into a logical error makes the new test fail again (the wait times out and the server aborts), on a Build-ID-pinned binary.
f Fix is general across code paths? Yes. The two DeleteEphemeralNodeIfContentMatches* unit tests already pin this error code deterministically at the ZooKeeper layer and are unchanged; the other tests creating a Replicated database with literal 's1','r1' are single-node, so no second claimant exists there.
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A (test-sequencing fix, no new source path and no type/parameter matrix). The one input axis that matters is which host loses, and it is now determinate and asserted in both directions.
h Backward compatible? (maintainer-approved exception only) N/A. No setting, no settings-history entry, no versioned format, zero src/ lines.
i Invariants and contracts preserved? Yes. The invariant is that the observation channel is the contended active node on a determinate loser and that the losing server survives; it now holds on every run instead of ~97.8% of them. session_timeout_ms=3000 still bounds the wait at 9 s and is now always exercised. Both waits raise on timeout rather than returning silently.

Session id: cron:clickhouse-impl-slot-5:20260923-161100

@clickhouse-gh

clickhouse-gh Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [a2ff290]

Summary: ❌

job_name test_name status info comment
Code Review ERROR

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - a2ff290

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task whose
fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Code Review CI infrastructure, not this diff: the review itself finished and returned Approve with no findings, then the job resolved the pull-request number as -1 and died in post-processing. ci.praktika.gh post-or-update printed PR number (got -1); skipping comment update and exited 1, so the finished review was never posted; the CIDB insert was then rejected with Code: 72 ... Unsigned type must not contain '-' symbol: (while reading the value of key pull_request_number), and get_s3_prefix_static's assert pr_number > 0 or branch failed, so the job log never reached S3 either. The workflow env for this run is correct (PR_NUMBER: 121820), and the head carries the familiar duplicate dispatch: two pull_request runs 9 s apart with the older one cancelled a fix task is created (investigating at full effort - fixing-PR link to follow here). Deliberately NOT linked as the owner: my merged #116701, which stops two PR workflows running at one commit, is already in the tree this job ran on (its merge commit 23c30347d281 is an ancestor of this head, behind_by: 0), so by rule 3d the -1 resolution in the surviving run is a residual it does not cover
PR aggregator row, mirrors the row above, no independent failure a fix task is created (the same one as above; its fixing-PR link will be posted here)

Measured at this head, not inherited: all 349 check runs are complete, Finish Workflow and
Mergeable Check are green, the 175 cancelled entries all belong to the superseded duplicate run,
and CIDB has zero FAIL/ERROR test rows for this pull request. CH Inc sync is green here, so
nothing is exempt.

Neither row can come from this diff, which changes one integration test plus its config
(tests/integration/test_replicated_database_active_node_taken/) and no product code: the failure is
in the CI job that reviews the diff, and the same job reports success on 848 other pull requests
over the last three days.

Session id: cron:our-pr-ci-monitor:20260924-020454

@Algunenano
Algunenano added this pull request to the merge queue Sep 24, 2026
Merged via the queue into ClickHouse:master with commit 63751de Sep 24, 2026
174 of 349 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 Sep 24, 2026
valerypetrov added a commit to valerypetrov/ClickHouse that referenced this pull request Sep 24, 2026
Picks up ClickHouse#121820, which fixed the REPLICA_ALREADY_EXISTS race in
test_active_node_owned_by_another_server that was the only diff-unrelated red.

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

can be tested Allows running workflows for external contributors comp-database-engines Database engine implementations (e.g., Atomic/Replicated) and database-level behavior. groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding 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