Repository navigation
Retry transient Confluent Schema Registry failures - #106661
alexey-milovidov merged 2 commits into
Conversation
A single network glitch when talking to the Confluent Schema Registry currently aborts the surrounding INSERT. The HTTP client in `AvroConfluentSchemaRegistry` makes one POST/GET attempt and propagates the first `Poco::TimeoutException` or `Poco::Net::NetException` to the caller, so a transient registry outage breaks `Kafka` ingestion that relies on `AvroConfluent`. Add a bounded retry loop around `fetchSchema` and `registerSchema` with exponential backoff (capped at 10 seconds). Schema-validation errors (HTTP 409 `INCOMPATIBLE_SCHEMA`, `INCORRECT_DATA`, `BAD_ARGUMENTS`) stay fatal so misconfigured users do not wait through every retry. Two new format settings control the policy: - `format_avro_schema_registry_max_retries` (default 5, capped at 20, 0 disables retries) - `format_avro_schema_registry_retry_initial_backoff_ms` (default 100, capped at 60000) Reported by @alexey-milovidov on ClickHouse#106619. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate
Session id: |
|
Workflow [PR], commit [e8a4a9d] Summary: ✅
AI ReviewSummaryThis PR adds bounded retries for transient Confluent Schema Registry failures in Tests
Final VerdictStatus: Minimum required action: add focused retry-behavior coverage for success-after-retry, disabled retries, and non-retryable errors. |
| @@ -0,0 +1,19 @@ | |||
| -- Tags: no-fasttest | |||
| -- Validate the bounds on `format_avro_schema_registry_max_retries` and | |||
There was a problem hiding this comment.
This only tests the new setting bounds, not the retry behavior promised by the PR. A regression in isRetryableException, the HTTPException status path, or the runWithRetry attempt loop would still pass while AvroConfluent no longer retries transient registry failures. Please add a focused test that injects a retryable registry failure such as HTTP 500 or a closed connection before a successful response, asserts the request is retried, and also checks format_avro_schema_registry_max_retries = 0 still fails after one attempt.
There was a problem hiding this comment.
Acknowledged — the current 04323_avro_schema_registry_retry_settings.sql only verifies the validator bounds, not the retry behavior itself. A regression in isRetryableException, the HTTPException status path, or the runWithRetry attempt loop would not be caught.
I plan a follow-up commit that adds a Python integration test alongside the existing test_format_avro_confluent suite (which already runs against a real Schema Registry). The test will:
- Sit a small Python
BaseHTTPRequestHandlerin front of the real registry (or stand-alone with stubbed schema responses). - Configure ClickHouse with
format_avro_schema_registry_urlpointing at the proxy. - Verify the three request-shape contracts the bot called out:
- Inject
nconsecutive HTTP500(or closed connection) responses followed by a successful schema response → assert the registry seesn+1requests for the same schema id and theAvroConfluentINSERTsucceeds. - Set
format_avro_schema_registry_max_retries = 0→ assert the registry sees exactly one request and theINSERTfails after that single attempt. - Inject a non-retryable failure (e.g.
400/HTTP 401) → assert the registry sees exactly one request even whenmax_retries > 0(provesisRetryableExceptionkeeps schema/protocol errors fatal).
- Inject
Will push that as a separate commit on this branch before merge.
Two corrections raised by clickhouse-gh[bot] on ClickHouse#106661: 1. Cap the FIRST backoff at the documented 10 s ceiling. `runWithRetry` only applied `max_backoff_ms` after the first sleep (`backoff_ms = std::min(backoff_ms * 2, max_backoff_ms)` runs after `sleepForMilliseconds(backoff_ms)`). With the validator allowing `format_avro_schema_registry_retry_initial_backoff_ms` up to 60000, the first retry could stall an `AvroConfluent` query for 60 s before even attempting retry 1, contradicting the documented 10 s cap. Initialize `backoff_ms` with `std::min(retry.initial_backoff_ms, max_backoff_ms)` so every sleep, including the first, honors the cap. 2. Make `compatibility = '26.5'` restore the pre-26.6 no-retry behavior. The history entry recorded `previous_value = 5` for `format_avro_schema_registry_max_retries`, which left `compatibility = '26.5'` retrying schema-registry calls 5 times. Pre-26.6 `AvroConfluent` issued a single request and surfaced the first transient failure to the user. Setting `previous_value = 0` restores that: under `compatibility = '26.5'` the registry sees exactly one request per schema/registration, matching upgrade timing and request-count expectations. Updated the description strings on both retry settings to call this out explicitly.
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 122/145 (84.14%) | Lost baseline coverage (was covered on master, now uncovered in this PR): 2 line(s) · Uncovered code |
|
Perfect, thank you! |
A single network glitch when talking to the Confluent Schema Registry currently aborts the surrounding INSERT. The HTTP client in
AvroConfluentSchemaRegistrymakes onePOST/GETattempt and propagates the firstPoco::TimeoutExceptionorPoco::Net::NetExceptionto the caller, so a transient registry outage breaksKafkaingestion that relies onAvroConfluent.Add a bounded retry loop around
fetchSchemaandregisterSchemawith exponential backoff (capped at 10 seconds). Schema-validation errors (HTTP 409INCOMPATIBLE_SCHEMA,INCORRECT_DATA,BAD_ARGUMENTS) stay fatal so misconfigured users do not wait through every retry. The HTTP-status retry set is the conventional 5xx, 408, 429.Two new format settings control the policy:
format_avro_schema_registry_max_retries(default5, capped at20,0disables retries)format_avro_schema_registry_retry_initial_backoff_ms(default100, capped at60000)Reported by @ alexey-milovidov on #106619 (single Poco timeout in
test_storage_kafka/test_avro_schema_registry.py::test_kafka_produce_consume_avro_confluent).Related: #106619
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
The
AvroConfluentformat now retries the Confluent Schema Registry HTTP client on transient failures (transport timeouts, connection refused, DNS errors, HTTP5xx/408/429) with exponential backoff, instead of aborting the INSERT on the first network glitch. New settingsformat_avro_schema_registry_max_retries(default5) andformat_avro_schema_registry_retry_initial_backoff_ms(default100) control the policy. Schema-validation errors (HTTP409, malformed Avro JSON) remain fatal.