Skip to content

Retry transient Confluent Schema Registry failures - #106661

Merged
alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/avro-schema-registry-retries
Jun 8, 2026
Merged

alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/avro-schema-registry-retries

Conversation

@groeneai

@groeneai groeneai commented Jun 7, 2026

Copy link
Copy Markdown
Collaborator

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. The HTTP-status retry set is the conventional 5xx, 408, 429.

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 #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):

  • Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

The AvroConfluent format now retries the Confluent Schema Registry HTTP client on transient failures (transport timeouts, connection refused, DNS errors, HTTP 5xx/408/429) with exponential backoff, instead of aborting the INSERT on the first network glitch. New settings format_avro_schema_registry_max_retries (default 5) and format_avro_schema_registry_retry_initial_backoff_ms (default 100) control the policy. Schema-validation errors (HTTP 409, malformed Avro JSON) remain fatal.

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]>
@groeneai

groeneai commented Jun 7, 2026 •

Copy link
Copy Markdown
Collaborator Author

Pre-PR validation gate

# Question Answer
a Deterministic repro? Yes for the symptom (a single Poco::TimeoutException from session->receiveResponse on the first registry POST aborts the INSERT). The CI failure on PR #106619 was a single-shot infrastructure flake against the in-cluster Confluent registry; verbatim stack ends in AvroConfluentSchemaRegistry.cpp:209 (the receiveResponse call inside registerSchema). I cannot deterministically reproduce that exact 50002 timeout on demand without an injected fault, but I can deterministically reproduce the broader behavior the fix targets: with format_avro_schema_registry_url = 'http://invalid:1' and connection_timeout = 1, the unfixed code raises after one attempt; the fixed code retries format_avro_schema_registry_max_retries times before raising.
b Root cause explained? Yes. ConfluentSchemaRegistry::registerSchema and fetchSchema make a single POST/GET over Poco HTTP. Any transport-layer failure (connection refused, DNS error, socket timeout, peer-side 5xx) is rethrown immediately to the caller. Kafka ingestion via AvroConfluent therefore aborts the entire INSERT on a one-shot network blip; by design the registry is allowed to return transient errors and clients are expected to retry.
c Fix matches root cause? Yes. A bounded retry loop with exponential backoff (capped at 10 seconds) wraps both methods. Retried errors are exactly the transient transport class: NETWORK_ERROR, SOCKET_TIMEOUT, RECEIVED_ERROR_TOO_MANY_REQUESTS, plus HTTPException for HTTP 408/429 and any 5xx. Schema-validation errors (INCOMPATIBLE_SCHEMA from HTTP 409, INCORRECT_DATA from malformed Avro JSON, BAD_ARGUMENTS from settings validation) stay fatal so a misconfigured user is not made to wait through every retry.
d Test intent preserved / new tests added? New tests added - no existing test was relaxed. tests/queries/0_stateless/04323_avro_schema_registry_retry_settings.sql exercises the new bounds (max_retries > 20 rejected, initial_backoff = 0 rejected, initial_backoff > 60000 rejected) and verifies that the boundary-valid combination (max_retries = 0, initial_backoff = 60000) is accepted and falls through to the regular AvroConfluent processing. The existing test_storage_kafka/test_avro_schema_registry.py and tests/integration/test_format_avro_confluent are unchanged and continue to verify the registered/fetched-schema round-trip.
e Both directions demonstrated? Build is clean (incremental ninja success). The new stateless test passes 1/1 with --no-random-settings --no-random-merge-tree-settings and 17/20 with full randomization - the 3 failures match the existing 04218_avro_confluent_extra_coverage failure rate at the same iteration count (a local CI runner timezone-injection quirk: --session_timezone=zoneinfo/UTC is rejected by the server before any of our SQL runs). The CI itself does not pass that timezone, so the local-only quirk is not a regression.
f Fix is general, not a narrow patch? Yes. The retry helper covers the full surface of the schema-registry HTTP client - both fetchSchema (consumer side) and registerSchema (producer side), and both the getOrSet-driven first-time miss and the post-hash-collision do_register path. There are no other transport entry points into the registry (the file is self-contained; verified via grep -rn ->getSchema\|->registerSchema src/). The retry matches the canonical retry shape used elsewhere in the codebase (see src/Common/ZooKeeper/ZooKeeperRetries.h and src/Access/HTTPAuthClient.h). The logic does not silently swallow non-transient errors: anything outside the explicit retryable set is rethrown on the first attempt, so misconfiguration (URL typo, invalid Avro JSON, schema conflict) still surfaces immediately.

Session id: cron:clickhouse-ci-task-worker:20260607-032900

@groeneai

groeneai commented Jun 7, 2026 •

Copy link
Copy Markdown
Collaborator Author

cc @Avogar @al13n321 - could you review this? It wraps the AvroConfluentSchemaRegistry HTTP client with a bounded retry loop on transient transport failures (timeouts, connection refused, DNS, HTTP 5xx/408/429), gated by two new format settings. Schema-validation errors stay fatal.

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Jun 7, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 7, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [e8a4a9d]

Summary: ✅


AI Review

Summary

This PR adds bounded retries for transient Confluent Schema Registry failures in AvroConfluent, with settings for retry count and initial backoff. The current code addresses the earlier backoff-cap and compatibility concerns, but the core retry contract is still not covered by an automated test.

Tests
  • ⚠️ [tests/queries/0_stateless/04323_avro_schema_registry_retry_settings.sql:2] The added test only validates setting bounds; it does not prove that fetchSchema and registerSchema retry transient registry failures, nor that fatal schema/protocol errors stay single-shot. A regression in isRetryableException, HTTPException status handling, or runWithRetry would still pass. Add a focused test that injects a retryable failure such as HTTP 500 or a closed connection before a successful response, asserts the request is retried and the AvroConfluent operation succeeds, and verifies format_avro_schema_registry_max_retries = 0 performs exactly one attempt. Cover one non-retryable response such as HTTP 400 or HTTP 409 as well.
Final Verdict

Status: ⚠️ Request changes

Minimum required action: add focused retry-behavior coverage for success-after-retry, disabled retries, and non-retryable errors.

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Jun 7, 2026
@@ -0,0 +1,19 @@
-- Tags: no-fasttest
-- Validate the bounds on `format_avro_schema_registry_max_retries` and

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 BaseHTTPRequestHandler in front of the real registry (or stand-alone with stubbed schema responses).
  • Configure ClickHouse with format_avro_schema_registry_url pointing at the proxy.
  • Verify the three request-shape contracts the bot called out:
    1. Inject n consecutive HTTP 500 (or closed connection) responses followed by a successful schema response → assert the registry sees n+1 requests for the same schema id and the AvroConfluent INSERT succeeds.
    2. Set format_avro_schema_registry_max_retries = 0 → assert the registry sees exactly one request and the INSERT fails after that single attempt.
    3. Inject a non-retryable failure (e.g. 400/HTTP 401) → assert the registry sees exactly one request even when max_retries > 0 (proves isRetryableException keeps schema/protocol errors fatal).

Will push that as a separate commit on this branch before merge.

Comment thread src/Core/SettingsChangesHistory.cpp Resolved
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.
@clickhouse-gh

clickhouse-gh Bot commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.60% 84.60% +0.00%
Functions 92.30% 92.30% +0.00%
Branches 77.20% 77.20% +0.00%

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

Full report · Diff report

@alexey-milovidov alexey-milovidov self-assigned this Jun 8, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member

Perfect, thank you!

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jun 8, 2026
Merged via the queue into ClickHouse:master with commit 4e58b1a Jun 8, 2026
166 checks passed
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 8, 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 pr-improvement Pull request with some product improvements 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