Skip to content

Add AvroConfluent output format - #101935

Merged
antaljanosbenjamin merged 24 commits into
masterfrom
avro-confluent-output-format
May 13, 2026
Merged

antaljanosbenjamin merged 24 commits into
masterfrom
avro-confluent-output-format

Conversation

@antaljanosbenjamin

@antaljanosbenjamin antaljanosbenjamin commented Apr 7, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Improvement

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

You can now write data in AvroConfluent format, which was previously input-only. This enables producing Confluent Schema Registry-framed Avro messages directly from ClickHouse, for example when writing to Kafka. The schema is automatically registered with the registry. Use the new output_format_avro_confluent_subject setting to specify the subject name.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Version info

  • Merged into: 26.5.1.600

@clickhouse-gh

clickhouse-gh Bot commented Apr 7, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [e561c81]

Summary: ❌

job_name test_name status info comment
Stress test (arm_release) FAIL
Segmentation fault (STID: 2672-67ba) FAIL cidb, issue ISSUE CREATED

AI Review

Summary

This PR adds AvroConfluent output support (including schema registration), new related settings/timeouts, and SYSTEM DROP AVRO SCHEMA CACHE. The feature direction is good, but there are still correctness/operability issues in cache semantics and metrics wiring that should be fixed before merge.

PR Metadata
  • ⚠️ Changelog category = Improvement is acceptable for this user-visible capability addition.
  • ⚠️ Changelog entry is clear and user-facing.
  • ⚠️ Documentation checkbox is left unchecked even though docs were updated in this PR.
Findings

❌ Blockers

  • [src/Processors/Formats/Impl/AvroConfluentSchemaRegistry.cpp:49] register_cache is initialized with AvroSchemaCache* metrics instead of AvroSchemaRegistryCache*. This double-counts one metric family and leaves the registry-cache metrics incorrect, breaking observability and alerting.
    • Suggested fix: initialize register_cache with CurrentMetrics::AvroSchemaRegistryCacheBytes and CurrentMetrics::AvroSchemaRegistryCacheCells.
  • [src/Processors/Formats/Impl/AvroConfluentSchemaRegistry.cpp:301] clearConfluentSchemaRegistryCache only drops the global URL→instance cache, but does not clear caches in already-alive ConfluentSchemaRegistry instances.
    • Impact: SYSTEM DROP AVRO SCHEMA CACHE is not reliable for long-lived users of existing shared pointers (e.g. already-created format instances).
    • Suggested fix: clear per-instance caches too (or use generation-based invalidation visible to existing instances).

⚠️ Majors

  • [tests/integration/test_storage_kafka/test_avro_schema_registry.py:20] Entire new integration suite is skipped on ARM (if is_arm(): pytestmark = pytest.mark.skip), creating architecture-asymmetric coverage for the new feature.
    • Suggested fix: remove unconditional ARM skip; if needed, scope skip narrowly to a known ARM-specific issue.
  • [tests/integration/test_format_avro_confluent/test.py:490] Test asserts exact registry message substring "incompatible with an earlier schema", which is brittle across registry versions.
    • Suggested fix: assert stable signals (INCOMPATIBLE_SCHEMA, HTTP 409, subject, and distinctive field marker).

💡 Nits

  • [tests/integration/test_format_avro_confluent/test.py:281] The comment says the test “first register[s] ... using the official Python client”, but the test body does not do that registration.
    • Suggested fix: either add the Python registration step or adjust the comment to match actual behavior.
Tests
  • ⚠️ New Kafka/Schema-Registry integration coverage is intentionally disabled on ARM; this should be architecture-neutral unless there is a concrete ARM-only incompatibility.
ClickHouse Rules
Item Status Notes
Deletion logging ✅
Serialization versioning ➖
Core-area scrutiny ⚠️ SYSTEM DROP AVRO SCHEMA CACHE invalidation is incomplete for already-alive instances.
No test removal ✅
Experimental gate ➖
No magic constants ✅
Backward compatibility ✅
SettingsChangesHistory.cpp ✅
PR metadata quality ⚠️ Documentation checkbox is unchecked despite docs updates.
Safe rollout ⚠️ Cache-drop semantics are not fully effective in long-lived flows.
Compilation time ✅
No large/binary files ✅
Final Verdict

Status: ⚠️ Request changes

Minimum required actions:

  1. Fix register_cache metrics wiring.
  2. Make SYSTEM DROP AVRO SCHEMA CACHE invalidate caches for already-alive registry instances.
  3. Remove or narrowly scope the ARM skip in the new integration suite.

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Apr 7, 2026
@antaljanosbenjamin antaljanosbenjamin linked an issue Apr 7, 2026 that may be closed by this pull request
from helpers.cluster import ClickHouseCluster, is_arm
import helpers.kafka.common as k

if is_arm():

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 new integration suite is skipped on ARM via if is_arm(): pytestmark = pytest.mark.skip.

Given current CI capacity, ARM is expected to run these tests, so this introduces asymmetric coverage exactly for the new AvroConfluent producer path. Please drop the unconditional ARM skip and keep the tests architecture-neutral unless there is a proven ARM-specific incompatibility (in which case document the concrete issue and scope the skip narrowly).


#include <Formats/FormatSettings.h>
#include <Formats/FormatSchemaInfo.h>
#include <Processors/Formats/Impl/AvroConfluentSchemaRegistry.h>

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.

Same compile-time concern here: AvroRowInputFormat.h does not need the full definition of ConfluentSchemaRegistry in the header (only std::shared_ptr<ConfluentSchemaRegistry> is stored).

Please prefer a forward declaration in the header and move the include to the .cpp to avoid unnecessary transitive includes in dependent translation units.

@Avogar Avogar self-assigned this Apr 17, 2026
@antaljanosbenjamin

Copy link
Copy Markdown
Member Author

I doubt these errors are because of my changes (LLVM coverage cannot find binaries).

settings={
"async_insert": 1,
"wait_for_async_insert": 1,
"output_format_avro_confluent_subject": "test_subject_02187", #Subject name should be unique to avoid conflicts with other tests

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.

Nit: typo in the inline comment — please add a space after #.

#Subject name should be unique ... → # Subject name should be unique ...

@Avogar Avogar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

PR title says ArrowConfluent instead of AvtoConfluent

Poco::URI url(base_url, base_url.getPath() + "/schemas/ids/" + std::to_string(id));
LOG_TRACE(getLogger("ConfluentSchemaRegistry"), "Fetching schema id = {} from url {}", id, url.toString());

/// One second for connect/send/receive. Just in case.

@Avogar Avogar Apr 20, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

1 second might be a too small timeout for send/receive, no? Maybe make it al teast 5-10 seconds, or even configurable via settings? WDYT?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I can expose a setting yes. As we already used hardcodrd 1s for fetching, I thought it is okay to keep it as is, but it is easy to change. Will add a setting for all 3 to minimize complexity.

@antaljanosbenjamin antaljanosbenjamin changed the title Add ArrowConfluent output format Add AvroConfluent output format Apr 22, 2026
assert "HTTP 409 Conflict" in error
assert subject in error
# Message coming from Confluent Schema Registry itself, if flaky can be removed
assert "incompatible with an earlier schema" in error

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 assertion is brittle against Schema Registry version/message wording changes. The test already defines unique_field_name specifically to verify propagated server details, but it is never asserted.

Please assert on a stable signal from the returned error (for example the presence of unique_field_name and INCOMPATIBLE_SCHEMA) instead of the exact phrase "incompatible with an earlier schema".

@clickhouse-gh clickhouse-gh Bot left a comment

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.

Submitting pending review to unblock inline comment posting.

ConfluentSchemaRegistry::ConfluentSchemaRegistry(const std::string & base_url_, size_t schema_cache_max_size)
: base_url(base_url_)
, schema_cache(CurrentMetrics::AvroSchemaCacheBytes, CurrentMetrics::AvroSchemaCacheCells, schema_cache_max_size)
, register_cache(CurrentMetrics::AvroSchemaCacheBytes, CurrentMetrics::AvroSchemaCacheCells, schema_cache_max_size)

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.

register_cache is initialized with the same metrics as schema_cache:

, register_cache(CurrentMetrics::AvroSchemaCacheBytes, CurrentMetrics::AvroSchemaCacheCells, schema_cache_max_size)

This means AvroSchemaRegistryCacheBytes/Cells never get updated, while AvroSchemaCache* gets double-accounted across two independent caches. The result is misleading cache observability and broken per-cache monitoring.

Please initialize register_cache with CurrentMetrics::AvroSchemaRegistryCacheBytes and CurrentMetrics::AvroSchemaRegistryCacheCells.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

AvroSchemaRegistryCache* is for the cache that caches registries. AvroSchemaCache* is for the cache that holds schema related information (id -> schema for one and (subject + schema) -> id for the newly added functionality).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I could introduce new metrics, but I don't feel like it make sense.


void clearConfluentSchemaRegistryCache()
{
schema_registry_cache.clear();

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.

clearConfluentSchemaRegistryCache only clears the global URL→instance map, but it does not clear caches inside already-alive ConfluentSchemaRegistry objects.

That means long-lived format instances (for example Kafka tables that already hold shared_ptr<ConfluentSchemaRegistry>) keep using stale schema_cache / register_cache entries after SYSTEM DROP AVRO SCHEMA CACHE, so the command does not reliably clear the cache in practice.

Please clear per-instance caches as well (e.g. add ConfluentSchemaRegistry::clearCaches and iterate current instances before dropping references), or make cache invalidation generation-based so existing instances observe the drop immediately.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

They will only use the registry to finish the current poll round. I think that is fine, no single poll will last longer than a few seconds.


def test_output_subject_encoding(started_cluster):
# type: (ClickHouseCluster) -> None

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 test comment says we "first register ... using the official Python client (ground truth)", but the test body does not perform that registration. It only registers from ClickHouse and checks GET /subjects.

Could you either add the Python-side registration step or adjust the comment so it matches what the test actually verifies?

Comment on lines +282 to +286
# Subject names with reserved URI characters (/, ?, #) must be properly
# encoded when registering with the Schema Registry. First register a
# schema under such a subject using the official Python client (ground
# truth), then do the same from ClickHouse and compare the stored names.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Suggested change
# Subject names with reserved URI characters (/, ?, #) must be properly
# encoded when registering with the Schema Registry. First register a
# schema under such a subject using the official Python client (ground
# truth), then do the same from ClickHouse and compare the stored names.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I will remove this comment and add test to cover the missed lines in a separate PR.

@clickhouse-gh

clickhouse-gh Bot commented May 6, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.10% 84.00% -0.10%
Functions 91.10% 91.10% +0.00%
Branches 76.60% 76.60% +0.00%

Changed lines: 90.94% (261/287) | lost baseline coverage: 2 line(s) · Uncovered code

Full report · Diff report

@antaljanosbenjamin
antaljanosbenjamin added this pull request to the merge queue May 13, 2026
Merged via the queue into master with commit 273b271 May 13, 2026
482 of 487 checks passed
@antaljanosbenjamin
antaljanosbenjamin deleted the avro-confluent-output-format branch May 13, 2026 10:28
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label May 13, 2026
Algunenano pushed a commit that referenced this pull request Oct 15, 2026
…onflict

The only conflict is in `AvroConfluentRowInputFormat::getOrCreateDeserializer`.
On master the `getSchema` call takes the registry timeouts and retry settings
added by #101935 (AvroConfluent output format), which is not on 26.3.

Resolution: keep 26.3's one-argument `schema_registry->getSchema(schema_id)` and
take #125505's change as is: build the cached `AvroDeserializer` in place with
`try_emplace` instead of moving a stack-local one into the cache. The header and
the test are unchanged from the PR.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

add support AvroConfluent as Output format

3 participants