Skip to content

sink: capture schema registry failure - #5712

Open
wk989898 wants to merge 2 commits into
pingcap:masterfrom
wk989898:registry-fix
Open

sink: capture schema registry failure#5712
wk989898 wants to merge 2 commits into
pingcap:masterfrom
wk989898:registry-fix

Conversation

@wk989898

@wk989898 wk989898 commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

What problem does this PR solve?

Issue Number: close #5653

What is changed and how it works?

Before this change, when Schema Registry returned 500, TiCDC could keep retrying inside the Avro schema registry helper and the changefeed could remain healthy-looking.

Now, when schema registration gets a 500, TiCDC returns the error immediately. The encoder error flows to the dispatcher manager, then to the maintainer/coordinator error path. The changefeed is reported as warning, with the registry error visible in last_warning.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
    With this pr, changefeed will be in warning status
img_v3_0213t_ca43cc89-661c-4d5a-9020-b82e0310dcdg

Questions

Will it cause performance regression or break compatibility?
Do you need to update user documentation, design documentation or monitoring documentation?

Release note

Please refer to [Release Notes Language Style Guide](https://pingcap.github.io/tidb-dev-guide/contribute-to-tidb/release-notes-style-guide.html) to write a quality release note.

If you don't think this PR needs a release note then fill it with `None`.

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of Schema Registry connection timeouts and interrupted retries.
    • Schema registration errors now include the HTTP status code, making failures clearer.
    • Prevented retries from continuing after an HTTP response is received.
  • Tests

    • Added coverage for server-side Schema Registry errors.
    • Added integration testing to verify affected changefeeds enter a warning state with relevant error details.

wk989898 added 2 commits July 22, 2026 10:53
Signed-off-by: wk989898 <nhsmwk@gmail.com>
Signed-off-by: wk989898 <nhsmwk@gmail.com>
@ti-chi-bot ti-chi-bot Bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. do-not-merge/needs-triage-completed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jul 23, 2026
@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Schema Registry requests now have bounded timeouts and improved retry termination. HTTP 500 responses include status details, unit tests cover registration failures, and an integration test verifies Avro changefeeds enter warning status when schema registration fails.

Changes

Schema Registry Error Handling

Layer / File(s) Summary
Bounded requests and retry handling
pkg/sink/codec/avro/confluent_schema_registry.go
Adds shared request timeouts, timeout-bound connectivity checks, HTTP status errors, response-aware retry termination, and cancellation-safe retry waits.
Unit failure simulation and assertions
pkg/sink/codec/avro/confluent_schema_registry.go, pkg/sink/codec/avro/confluent_schema_registry_test.go, pkg/sink/codec/avro/mock_schema_registry.go
Mocks HTTP 500 registration failures and verifies registration and retry results.
Changefeed warning integration coverage
tests/integration_tests/avro_schema_registry_error/run.sh, tests/integration_tests/run_light_it_in_ci.sh
Adds an integration test for Avro and Debezium Avro changefeeds and enables it in the Kafka light test group.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested labels: lgtm, approved

Poem

I’m a rabbit with retries tucked tight,
No endless hops through the server night.
Five hundred knocks now plainly ring,
Changefeeds warn when failures sting.
Timers pause, then safely flee—
A tidy burrow for CDC.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 7.69% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes add fail-fast schema-registry error handling and integration coverage for 500 errors, which matches issue #5653's objectives.
Out of Scope Changes check ✅ Passed The added timeout, error handling, mock behavior, and CI test wiring are all directly related to the schema registry failure fix.
Title check ✅ Passed The title is concise and accurately reflects the main change: handling schema registry failures.
Description check ✅ Passed The description is mostly complete with an issue link, change summary, and tests, though the questions and release note are left unfilled.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai 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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pkg/sink/codec/avro/confluent_schema_registry_test.go`:
- Around line 139-141: Update the test around manager.Register to assert that
the returned Avro schema API error includes the HTTP status detail “status 500”,
while preserving the existing ErrAvroSchemaAPIError and zero schema ID
assertions.

In `@tests/integration_tests/avro_schema_registry_error/run.sh`:
- Around line 130-131: Update the two check_changefeed_status assertions in the
avro schema registry error test to enforce a short explicit deadline for the
warning transition instead of allowing all MAX_RETRIES attempts. Keep validating
both avro_changefeed_id and debezium_changefeed_id reach the expected “register
schema failed with status 500” warning within that bounded interval.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: fdd785a6-9d62-4d74-8d9a-c40e0a5844ea

📥 Commits

Reviewing files that changed from the base of the PR and between be4c4b0 and 108c334.

📒 Files selected for processing (5)
  • pkg/sink/codec/avro/confluent_schema_registry.go
  • pkg/sink/codec/avro/confluent_schema_registry_test.go
  • pkg/sink/codec/avro/mock_schema_registry.go
  • tests/integration_tests/avro_schema_registry_error/run.sh
  • tests/integration_tests/run_light_it_in_ci.sh

Comment on lines +139 to +141
schemaID, err := manager.Register(ctx, "server-error", codec.Schema())
require.ErrorIs(t, err, errors.ErrAvroSchemaAPIError)
require.Zero(t, schemaID.confluentSchemaID)

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.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Assert the HTTP status detail.

This test passes with the old status-less error, so it does not protect the new clear-error contract. Assert that the returned error includes status 500.

Proposed test assertion
 schemaID, err := manager.Register(ctx, "server-error", codec.Schema())
 require.ErrorIs(t, err, errors.ErrAvroSchemaAPIError)
+require.ErrorContains(t, err, "status 500")
 require.Zero(t, schemaID.confluentSchemaID)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
schemaID, err := manager.Register(ctx, "server-error", codec.Schema())
require.ErrorIs(t, err, errors.ErrAvroSchemaAPIError)
require.Zero(t, schemaID.confluentSchemaID)
schemaID, err := manager.Register(ctx, "server-error", codec.Schema())
require.ErrorIs(t, err, errors.ErrAvroSchemaAPIError)
require.ErrorContains(t, err, "status 500")
require.Zero(t, schemaID.confluentSchemaID)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/sink/codec/avro/confluent_schema_registry_test.go` around lines 139 -
141, Update the test around manager.Register to assert that the returned Avro
schema API error includes the HTTP status detail “status 500”, while preserving
the existing ErrAvroSchemaAPIError and zero schema ID assertions.

Comment on lines +130 to +131
ensure "$MAX_RETRIES" "check_changefeed_status '127.0.0.1:8300' '$avro_changefeed_id' 'warning' 'last_warning' 'register schema failed with status 500'"
ensure "$MAX_RETRIES" "check_changefeed_status '127.0.0.1:8300' '$debezium_changefeed_id' 'warning' 'last_warning' 'register schema failed with status 500'"

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Assert a bounded health-transition time.

These ensure calls allow the warning to appear on any of 20 retries, so a regression that leaves a changefeed healthy for most of that window still passes. Add a short, explicit deadline consistent with the required immediate transition.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/integration_tests/avro_schema_registry_error/run.sh` around lines 130 -
131, Update the two check_changefeed_status assertions in the avro schema
registry error test to enforce a short explicit deadline for the warning
transition instead of allowing all MAX_RETRIES attempts. Keep validating both
avro_changefeed_id and debezium_changefeed_id reach the expected “register
schema failed with status 500” warning within that bounded interval.

@wk989898 wk989898 added the needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. label Jul 23, 2026
@wk989898

Copy link
Copy Markdown
Collaborator Author

/test all

@ti-chi-bot ti-chi-bot Bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Jul 27, 2026
@ti-chi-bot

ti-chi-bot Bot commented Jul 27, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: 3AceShowHand

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot

ti-chi-bot Bot commented Jul 27, 2026

Copy link
Copy Markdown

[LGTM Timeline notifier]

Timeline:

  • 2026-07-27 10:21:28.526300034 +0000 UTC m=+1832274.562395090: ☑️ agreed by 3AceShowHand.

@ti-chi-bot ti-chi-bot Bot added the approved label Jul 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved needs-1-more-lgtm Indicates a PR needs 1 more LGTM. needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Schema Registry 500 errors not reflected in Changefeed status

2 participants