Repository navigation
Retry Kafka admin client construction on NodeNotReadyError too - #116700
alexey-milovidov merged 2 commits into
Conversation
get_admin_client retries a broker that is not up yet, but its except named only kafka.errors.NoBrokersAvailable. Constructing a KafkaAdminClient runs several readiness probes, and kafka-python chooses the exception class by whether the probe names a node: a cluster-wide probe raises NoBrokersAvailable, while the controller probe (admin/client.py:219 -> _refresh_controller_id -> :279, node id given) raises NodeNotReadyError. KafkaClient.check_version documents the split in its own docstring (client_async.py:887-891); the leaf swallows NodeNotReadyError and keeps looping only when node_id is None (:918-922), and the raise is conn.py:990-992, reached when the socket to the controller does not come up inside api_version_auto_timeout_ms, which defaults to 2000 ms. So the loop covered half the class it was written for. I added that loop in ClickHouse#107337 and narrowed it to one class there deliberately; that was wrong about the class. Surfaced as test_partition_affinity.py::test_partition_affinity_settings_validation erroring out of the autouse fixture in Integration tests (amd_asan_ubsan, db disk, old analyzer, 4/6): https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=115294&sha=47d8d03a62c562bfc1e9a4adb9c2091d2f4a02fd&name_0=PR&name_1=Integration%20tests%20%28amd_asan_ubsan%2C%20db%20disk%2C%20old%20analyzer%2C%204%2F6%29 CIDB over 365 days at this call, split at the instant ClickHouse#107337 merged: before it, 10 NoBrokersAvailable and 1 NodeNotReadyError; after it, 0 NoBrokersAvailable and 2 NodeNotReadyError, against 23.3M Kafka integration test rows after versus 22.8M before. The retry works, and the uncaught sibling class is all that is left. This also corrects the "0 master failures" claim in ClickHouse#107337's own message: one master row exists, 2026-06-02, on test_batch_slow_7.py. Seventeen places constructed a KafkaAdminClient directly and had no retry at all. Four of them, test_kafka_bad_messages/test.py:68,229,290 and test_1.py:29, are in modules with no autouse fixture, so there that construction is the module's first admin client. All seventeen now call the helper, following ClickHouse#108635, which converged this suite's delete_topics calls onto the retrying helper the same way. Exactly one KafkaAdminClient construction is left under tests/integration, inside get_admin_client. Deliberately not a bare except Exception: IncompatibleBrokerVersion and UnrecognizedBrokerVersion are both retriable=False and must keep failing fast instead of stalling for 15 seconds with a useless message. Validated by injecting each exception at the constructor seam, with the fix reverted as a negative control: NodeNotReadyError propagates on the first attempt without the fix and is retried with it, NoBrokersAvailable is retried in both, and both non-retriable classes propagate in both. Co-Authored-By: Claude Opus 5 <[email protected]>
`get_admin_client` retries the construction of a `KafkaAdminClient` so that a broker which is not up yet does not fail a test. Nothing in the tree failed if that `except` clause was narrowed back to a single class, so add tests/integration/test_kafka_bad_messages/test_admin_client_helper.py: two functions and four parametrized ids, driving the helper with a stub constructor and needing neither a Kafka broker nor a ClickHouse instance. Two ids cover the readiness class that has to be retried, `NoBrokersAvailable` when the constructor's probe is cluster-wide and `NodeNotReadyError` when it targets a specific node. Two cover the version faults that have to fail fast, `IncompatibleBrokerVersion` and `UnrecognizedBrokerVersion`. Both functions assert the number of attempts; without that an arm which succeeded on its first attempt would pass as well, so the ids would show only that nothing escaped and never that a retry happened. Three mutations of the `except` clause redden pairwise disjoint sets of those four ids, so no id is redundant and no mutation is a blanket break. Dropping `NodeNotReadyError` from the tuple reddens its id alone, dropping `NoBrokersAvailable` reddens its id alone, and a bare `except Exception` reddens only the two version ids, which then report the loop's exhaustion message instead of the version mismatch itself. The first of the three mutations is byte-identical to the line as it stood before the retry was widened, so it is also the negative control. The test passes `retries=3` explicitly. Each failed attempt sleeps one second, and three is the smallest budget that admits two failures followed by a success. Also wrap the two class names in the comment above the loop in inline code blocks, as .claude/CLAUDE.md asks for. CI report of the failure this covers: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=115294&sha=47d8d03a62c562bfc1e9a4adb9c2091d2f4a02fd&name_0=PR&name_1=Integration%20tests%20%28amd_asan_ubsan%2C%20db%20disk%2C%20old%20analyzer%2C%204%2F6%29 Related: ClickHouse#115294 Co-Authored-By: Claude Opus 5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex). Two rounds: a full pass on the
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-10:20260827-114900 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-40:20260827-112800 |
|
Workflow [PR], commit [7239e42] Summary: ✅ AI ReviewSummaryThis PR routes the touched Kafka integration tests through Final VerdictStatus: ✅ Approve |
|
cc @kssenii, could you review this? The Kafka integration-test helper already retried a broker that is not up yet but caught only |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Description
Related: #115294
Related: #107337
Related: #108635
test_storage_kafka/test_partition_affinity.py::test_partition_affinity_settings_validationerroredwith
kafka.errors.NodeNotReadyErrorout of theautousefixture, not the test body:Integration tests (amd_asan_ubsan, db disk, old analyzer, 4/6).
get_admin_clientalready retries a broker that is not up yet, but itsexceptnamed onlykafka.errors.NoBrokersAvailable. AKafkaAdminClientruns several readiness probes on construction,and kafka-python picks the exception class by whether the probe names a node: a cluster-wide probe
raises
NoBrokersAvailable, the controller probe raisesNodeNotReadyError, asKafkaClient.check_version's own docstring documents. So the loop covered half the class it waswritten for. I added it in #107337, so the single-class catch was mine.
CIDB over 365 days at this call, split at the instant #107337 merged: 10
NoBrokersAvailableand 1NodeNotReadyErrorbefore, 0 and 2 after, against a larger denominator. It reached master once, on2026-06-02, before the loop existed.
Separately, 17 places constructed a
KafkaAdminClientdirectly with no retry, four of them in moduleswith no
autousefixture, where that construction is the module's first admin client. All 17 now callthe helper, following #108635, which converged this suite's
delete_topicscalls the same way. The onedirect construction left, in the
casa_del_dolorfuzzer, is in no CI job.tests/integration/test_kafka_bad_messages/test_admin_client_helper.pycovers this with a stubconstructor and no broker: two ids for the classes to retry, two for
IncompatibleBrokerVersionandUnrecognizedBrokerVersion, which areretriable=Falseand must fail fast rather than stall for 15seconds. Three mutations of the
exceptclause redden pairwise disjoint subsets of the four ids, so noid is redundant; the first is byte-identical to the clause before this change, so it doubles as the
negative control.
Not fixed here: a failed attempt strands a partially constructed client, because kafka-python builds
its internal client before the probes that can raise.
Workflow [PR]
Sync PR [sync-upstream/pr/116700]
Version info
26.9.1.400(included in26.9and later)