Repository navigation
Retry delete_topics RPC in kafka_delete_topic to fix flaky teardown - #108635
alexey-milovidov merged 2 commits into
Conversation
The Kafka integration test helper kafka_delete_topic() called admin_client.delete_topics([topic]) with no retry on the RPC itself, unlike its sibling kafka_create_topic() which retries create_topics() up to max_retries times. A transient broker/controller error during test teardown (delete_topics -> _send_request_to_controller raising) therefore failed an otherwise-passing test. The existing post-delete list_topics() verification loop only handled "delete accepted but not yet visible", not "delete RPC raised". Wrap the delete_topics() call in the same retry-on-exception loop used by kafka_create_topic(). Persistent failures still raise after exhausting max_retries; the happy path is unchanged (single call). Observed in CI on Integration tests teardown of test_kafka_bad_messages/test.py::test_bad_messages_parsing_stream (delete_topics -> _send_request_to_controller). Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-0:20260626-171800 |
|
cc @antaljanosbenjamin — could you review this? It adds a retry loop around |
|
Workflow [PR], commit [dc6b564] Summary: ✅ AI ReviewSummaryThe PR retries Kafka Final VerdictStatus: ✅ Approve |
The previous commit added a retry-on-exception loop only to the shared single-topic helper kafka_delete_topic. The same unprotected delete_topics RPC existed in two other teardown paths, so a transient broker/controller error during cleanup could still fail an otherwise-passing test: - test_produce_http_interface.py defined its own duplicate kafka_create_topic and kafka_delete_topic; the local kafka_delete_topic called delete_topics once with no retry. Dropped both duplicates and reused the shared helpers in helpers.kafka.common (single source of truth). - The shared bulk helper clean_test_database_and_topics issued an unprotected bulk delete_topics(topics). Wrapped it in the same retry loop. - Eleven test_storage_kafka tests inlined a byte-identical copy of that bulk teardown. Converged them onto the now-retry-protected clean_test_database_and_topics so every Kafka delete_topics RPC in the integration suite goes through a retry path. Removed imports left unused after the convergence. Net 30 insertions / 337 deletions. After the change the only delete_topics call sites in tests/integration are the two retry-protected helpers. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate (updated for the duplicate-coverage change)This update generalizes the original single-helper fix to every Kafka teardown Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-2:20260626-190800 |
LLVM Coverage Report
Changed lines: No C/C++ source files changed — skipping uncovered code analysis. Newly covered by added/modified tests: 311 line(s), 22 function(s) across 122 file(s) · Details Top files
|
CI finish ledger — dc6b564Every failure below has an owner. Only
All test/build/stress/integration jobs passed on this head (the generalized Session id: cron:our-pr-ci-monitor:20260626-233000 |
kafka_delete_topic, the shared single-topic teardown helper for the whole Kafka integration family, retried a *successful* delete as if it had failed and could never converge, so an otherwise fully passing test was reported FAILED from teardown. UnknownTopicOrPartitionError (error code 3) on a DeleteTopicsRequest means "that topic does not exist", which for a delete is exactly the requested end state. It landed in the helper's generic `except Exception: retry`, so the helper asked the broker 49 more times to delete something already gone, burned ~23 s, and then raised. Read off the failing job's kafka-python client log (2026-07-24, topic Native_stream_err_1784918653): attempt 1's request was sent at 18:44:18.560; at 18:44:48.570 the client gave up on the response after its 30 s request timeout (the shard runs three xdist workers under TSan); the reconnect's metadata refresh at 18:44:49.077 reported ClusterMetadata(brokers: 1, topics: 3, groups: 0), i.e. only the three internal topics, proving the delete had in fact landed broker-side and only its response was lost; every attempt from 18:44:49.078 on returned error_code 3, which kafka/admin/client.py:409 raises on. So this is a classification bug, not a missing retry. More retries provably cannot help: each error-3 response came back in 1-4 ms, and the condition is permanent. Rather than adding a guard, remove the incorrect classification, which makes the teardown operation idempotent - the correct property for a delete. UnknownTopicOrPartitionError is now caught ahead of the generic handler and treated as the absent-topic path. It is not a blind return: it falls through to the helper's existing post-verification loop, which independently confirms the topic is no longer listed and still raises otherwise. The generic retry is untouched, since it is load-bearing for the transient RequestTimedOutError. kafka.errors marks UnknownTopicOrPartitionError retriable, but that describes stale-client-metadata semantics on the produce/fetch paths, where a later metadata refresh can make the topic appear. On the delete path the same code means the opposite, so keying the retry on that flag would preserve the bug. Not a single-test flake: since the retry loop was added (ClickHouse#108635, 2026-06-27) the signature accounts for 4 CI hits across 4 unrelated PRs, 3 test modules and 3 sanitizer flavours, all through this one frame. It also makes a routine operation of tests/casa_del_dolor/catalogs/kafkatest.py, which deletes randomly chosen topic names, stop burning the full 50-attempt loop. The regression test drives the helper with a stub admin client replaying that exact RPC sequence. A broker cannot be made to drop exactly one DeleteTopicsResponse on demand, and the passing path is byte-identical to today's, so a broker-driven test of this interleaving could only be non-deterministic - which is the property this change removes. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=111572&sha=43ca40c8c0beb217e3edc66236a546332bb3c000&name_0=PR&name_1=Integration%20tests%20%28amd_tsan%2C%204%2F6%29 Related: ClickHouse#111572 Co-Authored-By: Claude Opus 4.8 <[email protected]>
kafka_delete_topic, the shared single-topic teardown helper for the whole Kafka integration family, retried a *successful* delete as if it had failed and could never converge, so an otherwise fully passing test was reported FAILED from teardown. UnknownTopicOrPartitionError (error code 3) on a DeleteTopicsRequest means "that topic does not exist", which for a delete is exactly the requested end state. It landed in the helper's generic `except Exception: retry`, so the helper asked the broker 49 more times to delete something already gone, burned ~23 s, and then raised. Read off the failing job's kafka-python client log (2026-07-24, topic Native_stream_err_1784918653): attempt 1's request was sent at 18:44:18.560; at 18:44:48.570 the client gave up on the response after its 30 s request timeout (the shard runs three xdist workers under TSan); the reconnect's metadata refresh at 18:44:49.077 reported ClusterMetadata(brokers: 1, topics: 3, groups: 0), i.e. only the three internal topics, proving the delete had in fact landed broker-side and only its response was lost; every attempt from 18:44:49.078 on returned error_code 3, which kafka/admin/client.py:409 raises on. So this is a classification bug, not a missing retry. More retries provably cannot help: each error-3 response came back in 1-4 ms, and the condition is permanent. Rather than adding a guard, remove the incorrect classification, which makes the teardown operation idempotent - the correct property for a delete. UnknownTopicOrPartitionError is now caught ahead of the generic handler and treated as the absent-topic path. It is not a blind return: it falls through to the helper's existing post-verification loop, which independently confirms the topic is no longer listed and still raises otherwise. The generic retry is untouched, since it is load-bearing for the transient RequestTimedOutError. kafka.errors marks UnknownTopicOrPartitionError retriable, but that describes stale-client-metadata semantics on the produce/fetch paths, where a later metadata refresh can make the topic appear. On the delete path the same code means the opposite, so keying the retry on that flag would preserve the bug. Not a single-test flake: since the retry loop was added (ClickHouse#108635, 2026-06-27) the signature accounts for 4 CI hits across 4 unrelated PRs, 3 test modules and 3 sanitizer flavours, all through this one frame. It also makes a routine operation of tests/casa_del_dolor/catalogs/kafkatest.py, which deletes randomly chosen topic names, stop burning the full 50-attempt loop. The regression test drives the helper with a stub admin client replaying that exact RPC sequence. A broker cannot be made to drop exactly one DeleteTopicsResponse on demand, and the passing path is byte-identical to today's, so a broker-driven test of this interleaving could only be non-deterministic - which is the property this change removes. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=111572&sha=43ca40c8c0beb217e3edc66236a546332bb3c000&name_0=PR&name_1=Integration%20tests%20%28amd_tsan%2C%204%2F6%29 Related: ClickHouse#111572 Co-Authored-By: Claude Opus 4.8 <[email protected]>
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]>
…lete-topic-teardown-retry Retry delete_topics RPC in kafka_delete_topic to fix flaky teardown
Related: #83683
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Description
The Kafka integration test helper
kafka_delete_topic()calledadmin_client.delete_topics([topic])with no retry on the RPC, unlike its siblingkafka_create_topic()which retriescreate_topics()up tomax_retriestimes. A transient broker/controller error during test teardown (delete_topics->_send_request_to_controllerraising) therefore failed an otherwise-passing test. This wraps thedelete_topics()call in the same retry-on-exception loop, mirroringkafka_create_topic(). Persistent failures still raise after exhaustingmax_retries; the happy path is unchanged.CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=108567&sha=2e30a6b9ae669015526971d597f7ea0b204183ed&name_0=PR&name_1=Integration%20tests%20%28arm_binary%2C%20distributed%20plan%2C%201%2F4%29
Failure stack (teardown):
Version info
26.7.1.145