Repository navigation
Conversation
Fixes a long-standing race in `test_keeper_reconfig_replace_leader_in_one_command` and other integration tests that issue `create` while the cluster is unstable (e.g. immediately after a reconfig that removes the current leader). `create` is not idempotent. If the request reaches the server and commits but the response is lost on a transient `ConnectionLoss`, the retry in `KazooClientWithImplicitRetries` performs the same `create`, the server reports `NodeExistsError`, and that error is not retryable, so it propagates out of the wrapper and fails the test even though the original create logically succeeded. When a retried `create` raises `NodeExistsError`, compare the existing value to what we tried to write. If they match, return the path. If they differ or verification fails, re-raise `NodeExistsError` unchanged. First-attempt `NodeExistsError` is left untouched, preserving the contract relied on by `test_keeper_session::test_create2_errors_existing_and_missing_parent` (which creates the same path twice with different values and expects the second call to raise) and `test_server_reload::configure_from_zk` (which catches the first-attempt `NodeExistsError` to decide between create and update). Add `tests/integration/test_kazoo_client_retries/` with seven mock-based cases pinning the new contract.
|
Pre-PR validation gate (per worker policy): a) Deterministic repro? Yes. b) Root cause explained? Kazoo's c) Fix matches root cause? Yes. The wrapper now distinguishes "first-attempt NodeExistsError" (caller's intent, propagate unchanged) from "retried-attempt NodeExistsError with matching value" (lost-response idempotent retry, return path). It does not widen any limit, weaken any assertion, or change any timeout. It addresses the non-idempotency directly at the retry layer. d) Test intent preserved / new tests added?
e) Both directions demonstrated? Yes.
f) Fix is general, not a narrow patch? Yes. The same race affects any test that issues |
|
cc @alesapin could you review this? Small test-infrastructure fix to make |
|
Workflow [PR], commit [8456c96] Summary: ✅ AI ReviewSummaryThis PR narrows the flaky- Final Verdict
|
| return KazooClientWithImplicitRetries(hosts="ignored:9181") | ||
|
|
||
|
|
||
| def test_first_attempt_node_exists_still_raises(): |
There was a problem hiding this comment.
You are adding tests for our testing utils?
Remove them.
There was a problem hiding this comment.
Done in 7e351b4 — directory removed. The wrapper is still exercised by the actual Keeper reconfig integration tests it stabilizes.
|
|
||
| def create(self, *args, **kwargs): | ||
| return self.retry(super().create, *args, **kwargs) | ||
| # `create` is not idempotent: a previous attempt may have committed on |
There was a problem hiding this comment.
@groeneai how does this work with sequence = True and/or ephemeral = True?
There was a problem hiding this comment.
The value-check branch is gated on NodeExistsError, and the server only raises it for non-sequence creates:
-
sequence=True: each commit gets a fresh server-generated suffix (/x0000000001, then/x0000000002, ...), so a retry never hitsNodeExistsErrorand the new branch is unreachable. Whether the first sequence node is orphaned after a lost response is a long-standing kazoo property; this patch does not change it. -
ephemeral=Trueretried onConnectionLoss(same session preserved): the original ephemeral znode is still alive in our session, the server returnsNodeExistsErroron the retry, andget(path)returns the value we wrote, so the wrapper treats it as success. Correct. -
ephemeral=Trueretried onSessionExpiredError(new session): kazoo's retry handler establishes a new session, the previous session's ephemeral znode is cleaned up server-side, the retry succeeds, andNodeExistsErroris never raised. -
sequence=Truecombined withephemeral=True: same assequence=Truealone, noNodeExistsError.
The chronic-flake call is zk4.create(f"/test_four_{100 + i}", b"somedata") (no sequence, no ephemeral), which is exactly the non-idempotent retry shape the patch targets.
There was a problem hiding this comment.
But if it retried on ConnectionLoss same session is not preserved and with that it's wrong ephemeral node
@antonio2368 asked to remove the `tests/integration/test_kazoo_client_retries/` mock-based suite for `KazooClientWithImplicitRetries.create`. The wrapper is exercised end-to-end by the actual Keeper reconfig integration tests it stabilizes (e.g. `test_keeper_reconfig_replace_leader_in_one_command`), so the extra mock suite is removed.
|
@groeneai this doesn't seem that is possible to handle in generic way. Fix each specific failure in the test itself. |
…-reconfig-kazoo-create-idempotent
Per @antonio2368 review feedback on PR ClickHouse#105707: the generic wrapper-level approach has fundamental edge cases (sequence=True suffix mismatch, ephemeral=True session semantics, ambiguous pre-existing-node race) that cannot be handled cleanly at the wrapper level. Restore the simple retry behavior and fix the specific failing test instead.
…_in_one_command The `zk4.create` loop right after the cluster reconfig is hit by a chronic kazoo `NodeExistsError`: the first attempt commits server-side, the response is lost on `ConnectionLoss` (cluster still settling after leader removal), and the implicit kazoo retry then sees the existing znode. Catch `NodeExistsError` locally, verify the existing value matches what we tried to write, and treat that as a successful create. Genuine "node already exists with a different value" mismatches still fail. Per @alexey-milovidov (PR ClickHouse#96130) and @antonio2368 (PR ClickHouse#105707) review directive: fix the specific failure in the test instead of changing the generic `KazooClientWithImplicitRetries` contract.
Pre-PR validation gate (per
|
|
Pivoted per @antonio2368's directive ("this doesn't seem that is possible to handle in generic way. Fix each specific failure in the test itself.") and the parallel ping from @alexey-milovidov on #96130.
Branch HEAD: PR title + description updated. Pre-PR validation gate posted separately above. Pinging @alesapin for the final review (component-tree.yaml owner for |
|
cc @alesapin — pivoted from the generic wrapper approach to a test-local |
LLVM Coverage Report
Changed lines: No C/C++ source files changed — skipping uncovered code analysis. Newly covered by added/modified tests: 328 line(s), 11 function(s) across 108 file(s) · Details Top files
|
|
@groeneai please reduce the amount of times you ping people. You mentioned me 3 times in a row. |
|
@antonio2368, it is okay, I really like that it pings people when attention is needed! GroeneAI does a lot of work, it works really hard, and this deserves your attention. It is totally fair. |
|
Especially when we have fixes for flaky tests. This is godsend! We owe so much to those who fixes our tech debt. |
|
Acknowledged, will keep the per-PR ping count down going forward and try to consolidate context into fewer comments. Thanks for the kind words above too, much appreciated. |
|
But those are not pings as a reminder, it just used my handle as part of the comment. |
Absorb a chronic kazoo
NodeExistsErrorrace intest_keeper_reconfig_replace_leader_in_one_commandby catching it locally in the test instead of changing the genericKazooClientWithImplicitRetrieswrapper contract.Root cause
tests/integration/helpers/kazoo_client.py::KazooClientWithImplicitRetrieswraps every kazoo operation inself.retry(...).createis not idempotent: if acreaterequest reaches the server and commits while the response is lost on a transientConnectionLoss, the kazoo retry then sees the now-existing znode and raisesNodeExistsError, which is not a retryable exception and propagates out of the wrapper.test_reconfig_replace_leader_in_one_commandis hit by this race right after the reconfig that removes the current leader (node1): the test connectszk4to the new node (node4), waits for configs to equalize, then enters afor i in range(100)loop that creates/test_four_{100 + i}znodes. The cluster is still settling at that point, so aConnectionLossduring one of thecreatecalls deterministically triggers the race once kazoo retries.CIDB shows this exact failure mode on
tests/integration/test_keeper_reconfig_replace_leader_in_one_command/test.py:131across four unrelated PRs in the past 90 days: #104662, #105675, #105682, #103234.CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=103234&sha=a309b2d408aa0253a39989a62e20916536aa5cb7&name_0=PR&name_1=Integration%20tests%20%28amd_asan_ubsan%2C%20targeted%29
Why a test-local fix and not a generic wrapper change
An earlier revision of this PR made
KazooClientWithImplicitRetries.createitself idempotent by comparing the existing znode value on retry. Per reviewer feedback (@antonio2368 on 2026-05-25, @alexey-milovidov on 2026-05-26) the generic wrapper-level approach has fundamental edge cases that cannot be handled cleanly:sequence=Truecreates a server-assigned unique-suffix path per commit, so the retry produces a different path and the value-equality check is unreachable.ephemeral=Trueis session-bound: onSessionExpiredErrorretry, the original znode is cleaned up server-side, so the retry creates a fresh node.NodeExistsErrorcannot be distinguished from a genuine "node was already there from a previous test" condition; absorbing it generically would silently mask real test logic errors.@antonio2368: "this doesn't seem that is possible to handle in generic way. Fix each specific failure in the test itself."@alexey-milovidov: "@groeneai, provide a fix fortest_keeper_reconfig_replace_leader_in_one_command."Fix
Catch
NodeExistsErrorlocally inside thezk4.createloop intest_keeper_reconfig_replace_leader_in_one_command/test.py. Verify the existing znode value matches the value we tried to write and treat that as already-succeeded. Genuine collisions (existing value differs) still fail the test with a precise assertion message.No changes to
helpers/kazoo_client.py, no contract change for any other test.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Not required.
Documentation entry for user-facing changes